Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions templates/crud/test/Test.EntityManager.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ 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');
$fixture->set<?= Str::asCamelCase($form_field); ?>('My Title');
<?php endforeach; ?>

$this->manager->persist($fixture);
Expand All @@ -80,7 +80,7 @@ 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');
$fixture->set<?= Str::asCamelCase($form_field); ?>('Value');
<?php endforeach; ?>

$this->manager->persist($fixture);
Expand All @@ -99,7 +99,7 @@ public function testEdit(): void
$fixture = $this-><?= lcfirst($entity_var_singular); ?>Repository->findAll();

<?php foreach ($form_fields as $form_field => $typeOptions): ?>
self::assertSame('Something New', $fixture[0]->get<?= ucfirst($form_field); ?>());
self::assertSame('Something New', $fixture[0]->get<?= Str::asCamelCase($form_field); ?>());
<?php endforeach; ?>
}

Expand All @@ -108,7 +108,7 @@ 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');
$fixture->set<?= Str::asCamelCase($form_field); ?>('Value');
<?php endforeach; ?>

$this->manager->persist($fixture);
Expand Down
22 changes: 22 additions & 0 deletions tests/Maker/MakeCrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ public function getTestDetails(): \Generator
}),
];

yield 'it_generates_correct_class_methods' => [$this->createMakerTest()
->addExtraDependencies('symfony/test-pack')
->run(function (MakerTestRunner $runner) {
$runner->copy(
'make-crud/Foo.php',
'src/Entity/Foo.php'
);

$output = $runner->runMaker([
'Foo', // Entity Class Name
'', // Default Controller,
'y', // Generate Tests
]);

$this->assertStringContainsString('src/Controller/FooController.php', $output);
$this->assertStringContainsString('src/Form/FooType.php', $output);
$this->assertStringContainsString('tests/Controller/FooControllerTest.php', $output);

$this->runCrudTest($runner, 'it_generates_correct_class_methods.php');
}),
];

yield 'it_generates_crud_custom_repository_with_test' => [$this->createMakerTest()
->addExtraDependencies('symfony/test-pack')
->run(function (MakerTestRunner $runner) {
Expand Down
49 changes: 49 additions & 0 deletions tests/fixtures/make-crud/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class Foo
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column()]
private ?int $id = null;

#[ORM\Column(length: 255)]
private ?string $foo = null;

#[ORM\Column(length: 255)]
private ?string $foo_bar = null;

public function getId()
{
return $this->id;
}

public function getFoo(): string
{
return $this->foo;
}

public function setFoo(string $foo): self
{
$this->foo = $foo;

return $this;
}

public function getFooBar(): string
{
return $this->foo_bar;
}

public function setFooBar(string $foo_bar): self
{
$this->foo_bar = $foo_bar;

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php


namespace App\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class GeneratedCrudControllerTest extends WebTestCase
{
/**
* Refers to the source folder where all generated files will be placed.
* Facilitates access to src/, templates/ and tests/ folders.
* @var string
*/
private string $rootFolder = __DIR__ . "/..";

public function testGeneratedTestsHasCorrectGettersAndSetters()
{
$testFileContent = file_get_contents($this->rootFolder . '/tests/Controller/FooControllerTest.php');

$this->assertStringContainsString("getFooBar()", $testFileContent);
$this->assertMatchesRegularExpression("/setFooBar(.*)/", $testFileContent);
$this->assertStringNotContainsString("getFoo_bar()", $testFileContent);
}
}