-
Notifications
You must be signed in to change notification settings - Fork 1
Test Finish #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Test Finish #1
Changes from 5 commits
e54e76a
4867351
aaee968
73b5743
3a9b026
2a57190
b430839
fd715e0
cefad9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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") | ||
|
|
||
| 1. Create a new Bundle "InterviewBundle" within the namespace "Test" | ||
| OK (changement de l'index de l'appli avec la commande generate:bundle) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 !
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 !
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'ai séparé les deux tests et corriger celui de 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 | ||
|
|
||
|
|
@@ -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) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ;)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"> | ||
|
|
@@ -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> | ||
|
||
| <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> | ||
|
|
||
|
|
||
| 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} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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); | ||
| } | ||
| } |
| 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)); | ||
| } | ||
| } |
| 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>"); | ||
| } | ||
| } |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 :)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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