-
-
Notifications
You must be signed in to change notification settings - Fork 438
[make:crud][experimental] Add generated tests to make:crud #307
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b6aab44
Add generated tests to make:crud
ckrack a748362
Comment out to pass tests
ckrack 67ff18e
Pass only used variables to template
ckrack 523af32
Optimize generated test
ckrack 3033732
Fix indenting & TODO
ckrack b08b425
Tabs to Spaces
ckrack 351dc63
Crud: Make tests optional & fix renamed browser-kit class
ckrack b9f2036
Crud: Isolate & improve generated tests
ckrack a2ded0a
Crud: Add test for test-generation
ckrack ac588d3
refactor test
jrushlow a061aed
refactor index test
jrushlow 3c5ac73
annotation / attribute tests
jrushlow 036b9c5
handel entity manager && custom repo tests
jrushlow 9592d08
lets not do this yet
jrushlow b87f148
cleanup
jrushlow 88b5f41
conditionally use typed properties
jrushlow 6a1dfe9
type hints for php 7.4 <
jrushlow 9b1990f
warn user if testpack is not installed after we generate the test
jrushlow 4cb0d14
fix method call
jrushlow 3d9adfb
check for WebTestCase
jrushlow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| <?= "<?php\n" ?> | ||
| <?php use Symfony\Bundle\MakerBundle\Str; ?> | ||
|
|
||
| namespace <?= $namespace ?>; | ||
|
|
||
| <?= $use_statements; ?> | ||
|
|
||
| class <?= $class_name ?> extends WebTestCase<?= "\n" ?> | ||
| { | ||
| <?= $use_typed_properties ? null : " /** @var KernelBrowser */\n" ?> | ||
| private <?= $use_typed_properties ? 'KernelBrowser ' : null ?>$client; | ||
| <?= $use_typed_properties ? null : " /** @var EntityManagerInterface */\n" ?> | ||
| private <?= $use_typed_properties ? 'EntityManagerInterface ' : null ?>$manager; | ||
| <?= $use_typed_properties ? null : " /** @var EntityRepository */\n" ?> | ||
| private <?= $use_typed_properties ? 'EntityRepository ' : null ?>$repository; | ||
| private <?= $use_typed_properties ? 'string ' : null ?>$path = '<?= $route_path; ?>/'; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| $this->client = static::createClient(); | ||
| $this->manager = (static::getContainer()->get('doctrine'))->getManager(); | ||
| $this->repository = $this->manager->getRepository(<?= $entity_class_name; ?>::class); | ||
|
|
||
| foreach ($this->repository->findAll() as $object) { | ||
| $this->manager->remove($object); | ||
| } | ||
|
|
||
| $this->manager->flush(); | ||
| } | ||
|
|
||
| public function testIndex(): void | ||
| { | ||
| $crawler = $this->client->request('GET', $this->path); | ||
|
|
||
| self::assertResponseStatusCodeSame(200); | ||
| self::assertPageTitleContains('<?= ucfirst($entity_var_singular); ?> index'); | ||
|
|
||
| // Use the $crawler to perform additional assertions e.g. | ||
| // self::assertSame('Some text on the page', $crawler->filter('.p')->first()); | ||
| } | ||
|
|
||
| public function testNew(): void | ||
| { | ||
| $this->markTestIncomplete(); | ||
| $this->client->request('GET', sprintf('%snew', $this->path)); | ||
|
|
||
| self::assertResponseStatusCodeSame(200); | ||
|
|
||
| $this->client->submitForm('Save', [ | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| '<?= $form_field_prefix; ?>[<?= $form_field; ?>]' => 'Testing', | ||
| <?php endforeach; ?> | ||
| ]); | ||
|
|
||
| self::assertResponseRedirects('/sweet/food/'); | ||
|
|
||
| self::assertSame(1, $this->manager->getRepository()->count([])); | ||
jrushlow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public function testShow(): void | ||
| { | ||
| $this->markTestIncomplete(); | ||
| $fixture = new <?= $entity_class_name; ?>(); | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| $fixture->set<?= ucfirst($form_field); ?>('My Title'); | ||
| <?php endforeach; ?> | ||
|
|
||
| $this->repository->add($fixture, true); | ||
|
|
||
| $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); | ||
|
|
||
| self::assertResponseStatusCodeSame(200); | ||
| self::assertPageTitleContains('<?= ucfirst($entity_var_singular); ?>'); | ||
|
|
||
| // Use assertions to check that the properties are properly displayed. | ||
| } | ||
|
|
||
| public function testEdit(): void | ||
| { | ||
| $this->markTestIncomplete(); | ||
| $fixture = new <?= $entity_class_name; ?>(); | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| $fixture->set<?= ucfirst($form_field); ?>('Value'); | ||
| <?php endforeach; ?> | ||
|
|
||
| $this->manager->persist($fixture); | ||
| $this->manager->flush(); | ||
|
|
||
| $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId())); | ||
|
|
||
| $this->client->submitForm('Update', [ | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| '<?= $form_field_prefix; ?>[<?= $form_field; ?>]' => 'Something New', | ||
| <?php endforeach; ?> | ||
| ]); | ||
|
|
||
| self::assertResponseRedirects('<?= $route_path; ?>/'); | ||
|
|
||
| $fixture = $this->repository->findAll(); | ||
|
|
||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| self::assertSame('Something New', $fixture[0]->get<?= ucfirst($form_field); ?>()); | ||
| <?php endforeach; ?> | ||
| } | ||
|
|
||
| public function testRemove(): void | ||
| { | ||
| $this->markTestIncomplete(); | ||
| $fixture = new <?= $entity_class_name; ?>(); | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| $fixture->set<?= ucfirst($form_field); ?>('Value'); | ||
| <?php endforeach; ?> | ||
|
|
||
| $$this->manager->remove($fixture); | ||
| $this->manager->flush(); | ||
|
|
||
| $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); | ||
| $this->client->submitForm('Delete'); | ||
|
|
||
| self::assertResponseRedirects('<?= $route_path; ?>/'); | ||
| self::assertSame(0, $this->repository->count([])); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| <?= "<?php\n" ?> | ||
| <?php use Symfony\Bundle\MakerBundle\Str; ?> | ||
|
|
||
| namespace <?= $namespace ?>; | ||
|
|
||
| <?= $use_statements; ?> | ||
|
|
||
| class <?= $class_name ?> extends WebTestCase<?= "\n" ?> | ||
| { | ||
| <?= $use_typed_properties ? null : " /** @var KernelBrowser */\n" ?> | ||
| private <?= $use_typed_properties ? 'KernelBrowser ' : null ?>$client; | ||
| <?= $use_typed_properties ? null : " /** @var $repository_class_name */\n" ?> | ||
| private <?= $use_typed_properties ? "$repository_class_name " : null ?>$repository; | ||
| private <?= $use_typed_properties ? 'string ' : null ?>$path = '<?= $route_path; ?>/'; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| $this->client = static::createClient(); | ||
| $this->repository = (static::getContainer()->get('doctrine'))->getRepository(<?= $entity_class_name; ?>::class); | ||
|
|
||
| foreach ($this->repository->findAll() as $object) { | ||
| $this->repository->remove($object, true); | ||
| } | ||
| } | ||
|
|
||
| public function testIndex(): void | ||
| { | ||
| $crawler = $this->client->request('GET', $this->path); | ||
|
|
||
| self::assertResponseStatusCodeSame(200); | ||
| self::assertPageTitleContains('<?= ucfirst($entity_var_singular); ?> index'); | ||
|
|
||
| // Use the $crawler to perform additional assertions e.g. | ||
| // self::assertSame('Some text on the page', $crawler->filter('.p')->first()); | ||
| } | ||
|
|
||
| public function testNew(): void | ||
| { | ||
| $this->markTestIncomplete(); | ||
| $this->client->request('GET', sprintf('%snew', $this->path)); | ||
|
|
||
| self::assertResponseStatusCodeSame(200); | ||
|
|
||
| $this->client->submitForm('Save', [ | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| '<?= $form_field_prefix; ?>[<?= $form_field; ?>]' => 'Testing', | ||
| <?php endforeach; ?> | ||
| ]); | ||
|
|
||
| self::assertResponseRedirects('/sweet/food/'); | ||
|
|
||
| self::assertSame(1, $this->repository->count([])); | ||
| } | ||
|
|
||
| public function testShow(): void | ||
| { | ||
| $this->markTestIncomplete(); | ||
| $fixture = new <?= $entity_class_name; ?>(); | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| $fixture->set<?= ucfirst($form_field); ?>('My Title'); | ||
| <?php endforeach; ?> | ||
|
|
||
| $this->repository->add($fixture, true); | ||
|
|
||
| $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); | ||
|
|
||
| self::assertResponseStatusCodeSame(200); | ||
| self::assertPageTitleContains('<?= ucfirst($entity_var_singular); ?>'); | ||
|
|
||
| // Use assertions to check that the properties are properly displayed. | ||
| } | ||
|
|
||
| public function testEdit(): void | ||
| { | ||
| $this->markTestIncomplete(); | ||
| $fixture = new <?= $entity_class_name; ?>(); | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| $fixture->set<?= ucfirst($form_field); ?>('My Title'); | ||
| <?php endforeach; ?> | ||
|
|
||
| $this->repository->add($fixture, true); | ||
|
|
||
| $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId())); | ||
|
|
||
| $this->client->submitForm('Update', [ | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| '<?= $form_field_prefix; ?>[<?= $form_field; ?>]' => 'Something New', | ||
| <?php endforeach; ?> | ||
| ]); | ||
|
|
||
| self::assertResponseRedirects('<?= $route_path; ?>/'); | ||
|
|
||
| $fixture = $this->repository->findAll(); | ||
|
|
||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| self::assertSame('Something New', $fixture[0]->get<?= ucfirst($form_field); ?>()); | ||
| <?php endforeach; ?> | ||
| } | ||
|
|
||
| public function testRemove(): void | ||
| { | ||
| $this->markTestIncomplete(); | ||
| $fixture = new <?= $entity_class_name; ?>(); | ||
| <?php foreach ($form_fields as $form_field => $typeOptions): ?> | ||
| $fixture->set<?= ucfirst($form_field); ?>('My Title'); | ||
| <?php endforeach; ?> | ||
|
|
||
| $this->repository->add($fixture, true); | ||
|
|
||
| $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); | ||
| $this->client->submitForm('Delete'); | ||
|
|
||
| self::assertResponseRedirects('<?= $route_path; ?>/'); | ||
| self::assertSame(0, $this->repository->count([])); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What would happen if we didn't check for the class? And just always asked the question? If they ran the tests, obviously they wouldn't work, but would it be obvious that they just need to install some stuff? I'm trying to limit the number of conditionals and paths we have.
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.
Welp nothing - good catch!