Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,65 +42,92 @@ Access the project with your favourite browser. You should see similar welcome s


## Test tasks:
/!\ Précision: je suis sous Windows ("/" "\")

1. Change the text on symfony homepage from "Welcome to Symfony 2.8.8" to "This is a test"
OK

1. Run the PhpUnit test. Check if there are any errors, if so fix them.
OK (en mettant en commentaires "swiftmailer" dans config_test.yml et modifier le test)
(commande à la racine : "phpunit -c app/ src/AppBundle/Tests/Controller/DefaultControllerTest.php")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne comprend pas pourquoi tu as du désactiver le swiftmailer ? Qu'est-ce qui se passait ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK j'ai vu en voulant faire le test, essaies de résoudre le problème sans virer ça du config_test :)

Copy link
Author

@ThomasPetithory ThomasPetithory Jan 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok j'ai rajouter un require pour le swiftmailer bundle et fais un composer install, et là c'est ok, je l'ai pas configuré par contre


1. Create a new Bundle "InterviewBundle" within the namespace "Test"
OK (changement de l'index de l'appli avec la commande generate:bundle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

(commande à la racine: "php app/console generate:bundle --namespace=Test/InterviewBundle --bundle-name=TestInterviewBundle")

1. Create a method helloAction under AppBundle\Controller\DefaultController
* for route `/hello`
* with a proper json return `{"hello":"world!"}`
Ok (return JsonResponse)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


1. Create a "Bios" collection and load the example data into your MongoDB server
* copy the json string from mongodb website ([link](https://docs.mongodb.com/manual/reference/bios-example-collection/))
* or download and load the archive dump ([link](https://raw.githubusercontent.com/OskHa/php_interview_test/master/symfony_mongodb_example.archive))
OK mais il faut que vous fassiez la manip:
* mettre la collection en copier/coller dans une database "test" ou changer dans app/config/parameters.yml
* utiliser le dump symfony_mongodb_example.archive à la racine

1. Define ODM "Bios" document under namespace Test/InterviewBundle/Documents
Ok sauf qu'on ne doit pas utiliser "Documents" mais "Document" pour que le mapping fonctionne (pas trouvé d'autres solutions)
(commande à la racine pour les setters/getters: "php app/console doctrine:mongodb:generate:documents TestInterviewBundle")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


1. Define ODM "Bios" repository under namespace Test/InterviewBundle/Repositories
Ok sauf qu'on doit utiliser "Repository" et non "Repositories"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectivement la bonne pratique est Repository mais ça aurait pu fonctionner aussi avec Repositories ;)

(commande à la racine; "php app/console doctrine:mongodb:generate:repositories TestInterviewBundle")

/!\A partir de ce point, j'ai créé une methode (avec la route \testdb) pour tester les methodes demandées
De plus, les nouvelles routes sont définies dans le routing du Bundle pour la portabilité
1. Implement following repository methods
* findByFirstName($firstName)
* findByContribution($contributionName)
* findByDeadBefore($year)
OK (on peut voir les résultats sur /testdb, on peut changer les paramètres des recherches dans le controller
src/Test/InterviewBundle/Controller/DefaultController.php)
/!\ les ids de la db sont parfois 'bizarre' (expl: 51df07b094c6acd67e492f41 (oui oui c'est bien un id))

1. Define and create a service "BiosService" under namespace Test/InterviewBundle/Services and implement following methods
* getAllAwards()
* Use the logger to log operations (error, warning, debug)
Ok, inscrit dans les services du Bundle (pour la portabilité)
Cependant, j'ai utilisé ma classe test pour tester le service, mais je ne me suis pas servi du logger

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca serait bien d'implémenter le logger stp :).

Sur les retours, un service ne doit pas renvoyer de Response (une Response c'est essentiellement un objet qui HTTP pour renvoeyr des données au navigateur et donc, envoyé que par le controller). Est-ce que tu peux modifier un peu le code pour que ça soit plus propre là dessus ?

De même, ton renvoi "false" depuis tes Repository me semble un peu brouillon car je pense qu'il y'a moyen d'éviter ça derrière, mais je termine la revue pour te le confirmer !

Sinon le reste me semble bien !

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai injecter le logger dans le BiosService

1. Create ContributionsController under namespace Test/InterviewBundle/Controller
OK

1. Add a contributionsAction method to your ContributionsController
* for route `/contributions`
* make a use of your BiosService
* avoid logic under controller
* method should list all contributions
* with a proper json return `["contrib", ...]`
OK

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bon, ça va venir contredire mon post précédent de "un service ne doit pas renvoyer de Response" car dans ce cas précis, je comprend pourquoi tu l'as fait.

Je pense que je n'aurai pas géré ça comme ça (genre je pense que j'aurai assigné le résultat du service dans une variable et renvoyé la response depuis le controller pour des questions de réutilisation du code). Mais ce que tu as fait fonctionne et on est sur de l'affinage donc pas de souci !

1. Add a biosByContributionAction method to your ContributionsController
* for route `/contributions/{contributionName}`
* make a use of your BiosService
* avoid logic under controller
* method should list all bios documents with provided contribution
* with a proper json return `[{...}]`
Ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

1. make a unit test for the controller
* check if route `/hello` has response code 200
* check if route `/hello` response is a json
* check if route `/contributions` has response code 200
* check if route `/contributions/fake` has response code 404
* check if route `/contributions/OOP` has response code 200

Ok j'ai mis les tests dans Test/InterviewBundle/Tests/Controller/DefaultControllerTest.php
(commande à la racine: "phpunit -c app/ src/Test/InterviewBundle//Tests/Controller/DefaultControllerTest.php")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

1. make a unit test for the BiosService
* at least 1 method of your choice
Ok j'ai mis un test de 'getAllContributions' avec retour Json à la suite des tests précédents

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alors, si tu test le service, il faut créer une nouvelle class (et pas mettre ton test dans la classe de test du controller).

Le test est pas mal sinon !

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai séparé les deux tests et corriger celui de service :
en fait, il vérifiait la réponse de $client->request('GET', '/contributions/OOP'); (qui rend un json) situé au dessus et non le retour du service!

1. write a command called `test:command` that should accept 1 argument called id under namespace Test/InterviewBundle/Command
* The command should check if a Bios document with an id of the argument exists
* if document exists, return info "document exists"
* if document doesnt exist, return error "document doesnt exist"

Ok (par contre Mongo a un petit soucis pour find un objet avec un id, pas moyen de le faire proprement en 'requête' alors j'ai du le faire en php)

## Bonus tasks

Expand All @@ -109,14 +136,17 @@ Access the project with your favourite browser. You should see similar welcome s
test:
ping: pong
```
Ok

1. Check the symfony application for errors and fix them if any.
Ok, j'ai du modifier "test:" en "test_interview:" qui est le namespace du bundle
et ajouter du code dans le DependencyInjection/Configuration pour ajouter le paramètre ping de valeur pong (valeur par défaut obligatoire)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

1. write a prompt for the command `test:command`
* Prompt text is "This is a test. Do you want to continue (y/N) ?"
* If you decline, return error "Nothing done. Exiting..."
* If you accept, run the command

OK, j'ai du modifier le code demandé en 15 forcément

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca marche, avec un check sur le paramètre qui devrait être obligatoire serait encore mieux ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done, mais c'est juste une vérification d'existence, un message et un exit

# That's it!
## Thank you for your participation! Good luck submitting your results!
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function registerBundles()
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new Test\InterviewBundle\TestInterviewBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
Expand Down
12 changes: 11 additions & 1 deletion app/Resources/views/default/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<div id="wrapper">
<div id="container">
<div id="welcome">
<h1><span>Welcome to</span> Symfony {{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}</h1>
<!-- Demande 1 -->
<h1>This is a test</h1>
<!--<h1><span>Welcome to</span> Symfony {{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}</h1>-->
</div>

<div id="status">
Expand Down Expand Up @@ -39,6 +41,14 @@
<a href="http://symfony.com/doc/{{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION')[:3] }}/book/page_creation.html">
How to create your first page in Symfony
</a>
<br/>
<!-- petit rajout pour avoir les liens directement sur l'acceuil -->
<ul>
<li><a href={{ path('test_interview_homepage') }}>Index du bundle Test</a></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention à tes liens :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi? Est-ce que je dois rajouter une vérification que la route existe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non, il manque des guillemets tout simplement dans ton href ;)

Copy link
Author

@ThomasPetithory ThomasPetithory Jan 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oupsss.... Corrigé en même temps que swiftmailer

<li><a href={{ path('hello') }}>Action Hello du controleur default du bundle App</a></li>
<li><a href={{ path('testdb') }}>Page perso de Test pour les différents méthodes et service demandés</a></li>
<li><a href={{ path('contributions') }}>Page des contributions</a></li>
</ul>
</p>
</div>

Expand Down
7 changes: 6 additions & 1 deletion app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ doctrine_mongodb:
default_database: "%mongodb.default_database%"
document_managers:
default:
auto_mapping: true
auto_mapping: true

# Bonus Task 1
#test: <-- non fonctionnel
test_interview:
ping: pong
4 changes: 3 additions & 1 deletion app/config/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ monolog:
# type: chromephp
# level: info

# Demande 2, on ne sert pas (pour le moment) de mailer donc on peut désactiver la configuration
# pour que le test PhpUnit passe
#swiftmailer:
# delivery_address: me@example.com
# delivery_address: me@example.com
4 changes: 2 additions & 2 deletions app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ web_profiler:
toolbar: false
intercept_redirects: false

swiftmailer:
disable_delivery: true
#swiftmailer:
# disable_delivery: true
8 changes: 8 additions & 0 deletions app/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
test_interview:
resource: "@TestInterviewBundle/Resources/config/routing.yml"
prefix: /

app:
resource: "@AppBundle/Controller/"
type: annotation

hello:
path: /hello
defaults: {_controller: AppBundle:Default:hello}
11 changes: 6 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/AppBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;

class DefaultController extends Controller
{
Expand All @@ -18,4 +19,13 @@ public function indexAction(Request $request)
'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..'),
));
}

// Demande 4
/**
* @Route("/hello", name="hello")
*/
public function helloAction()
{
return new JsonResponse(array('hello' => 'world'));
}
}
4 changes: 3 additions & 1 deletion src/AppBundle/Tests/Controller/DefaultControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public function testIndex()
$crawler = $client->request('GET', '/');

$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertContains('Welcome to Symfony', $crawler->filter('#container h1')->text());
// Demande 2
//$this->assertContains('Welcome to Symfony', $crawler->filter('#container h1')->text());
$this->assertContains('This is a test', $crawler->filter('#container h1')->text());
}
}
45 changes: 45 additions & 0 deletions src/Test/InterviewBundle/Command/TestCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
// Demande 15 et Bonus 2
namespace Test\InterviewBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

class TestCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('test:command')
->setDescription('Demande 15')
->addArgument(
'id'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
// Demande Bonus 2
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('This is a test. Do you want to continue (y/N)?', false);

if (!$helper->ask($input, $output, $question)) {
$output->writeln("Nothing done. Exiting...");
return;
}
// Fin Demande Bonus 2
$id= $input->getArgument('id');

$container = $this->getContainer();

$service = $container->get('testinterview.biosservice');
$result = $service->getById($id);

$text = $result->getContent() === 'true' ?'document exists' : 'document doesnt exist';

$output->writeln($text);
}
}
20 changes: 20 additions & 0 deletions src/Test/InterviewBundle/Controller/ContributionsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
// Demande 10
namespace Test\InterviewBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class ContributionsController extends Controller
{
// Demande 11
public function contributionsAction ()
{
return $this->forward('testinterview.biosservice:getAllContributions');
}

// Demande 12
public function biosByContributionAction ($contributionName)
{
return $this->forward('testinterview.biosservice:getBiosByContributionName',array("contributionName" => $contributionName));
}
}
66 changes: 66 additions & 0 deletions src/Test/InterviewBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Test\InterviewBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

class DefaultController extends Controller
{
// fonction de test permettant de vérifier les query et les résultats
public function testdbAction() {
// Initialisation (captain obvious)
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$repository = $dm->getRepository('TestInterviewBundle:Bios');

// Test de findByFirstName(name) avec un retour JSON listant les Ids des entités trouvées
/*------ Paramètre(s) utilisé(s) ------*/
// param de findByFirstName
$test_first_name = 'John';
// param de findByContribution
$test_contribution_name = 'OOP';
// param de findByDeadBefore
$test_date_dead_before = 2012;
/*------ Fin ------*/

// Test findByFirstName((string) name)
// return array of bios id
$result = $repository->findByFirstName($test_first_name);
$ids_bios_by_first_name = array();
if ($result != false)
foreach ($result as $bios) {
$ids_bios_by_first_name[] = $bios->getId();
}

// Test de findByContribution((string) name)
// return array of bios id
$result = $repository->findByContribution($test_contribution_name);
$ids_bios_by_contribution_name = array();
if ($result != false)
foreach ($result as $bios) {
$ids_bios_by_contribution_name[] = $bios->getId();
}

// Test de findByDeadBefore((integer) year)
// return array of bios id
$result = $repository->findByDeadBefore($test_date_dead_before);
$ids_bios_by_dead_before = array();
if ($result != false)
foreach ($result as $bios) {
$ids_bios_by_dead_before[] = $bios->getId();
}

// Test du Service et GetAllAwards
$service = $this->forward('testinterview.biosservice:getAllAwards');

// la réponse Html n'utilise pas de template Twig donc pas très jolie, c'est juste pour vérifier les données retournées par les fonctions
// (si vide, un résultat ou plusieurs)
return new Response("<html><body>"
."Test findByFirstName : Ids des Bios pour le first name $test_first_name : ".implode(",", $ids_bios_by_first_name)."<br/>"
."Test findByContribution : Ids des Bios pour le contribution name $test_contribution_name : ".implode(",", $ids_bios_by_contribution_name)."<br/>"
."Test findByDeadBefore : Ids des Bios pour les morts avant le 1er Janvier $test_date_dead_before 00:00:00 : ".implode(",", $ids_bios_by_dead_before)."<br/>"
."Test BiosService GetAllAwards (Format Json) : ".$service->getContent()."<br/>"
."</body></html>");
}
}
Loading