Skip to content

Commit 7ed6b8b

Browse files
committed
improved tests
1 parent 3787739 commit 7ed6b8b

File tree

5 files changed

+73
-21
lines changed

5 files changed

+73
-21
lines changed

src/GeneratorHelper.php

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Bundle\MakerBundle;
1313

14+
/**
15+
* @author Sadicov Vladimir <[email protected]>
16+
*/
1417
class GeneratorHelper
1518
{
1619
public function getEntityFieldPrintCode($entity, $field): string

src/Maker/MakeCrud.php

+19-16
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

14+
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1415
use Doctrine\Common\Inflector\Inflector;
15-
use Doctrine\ORM\EntityManager;
16+
use Doctrine\ORM\Mapping\Column;
1617
use Psr\Container\ContainerInterface;
1718
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
1819
use Symfony\Bundle\MakerBundle\ConsoleStyle;
@@ -111,7 +112,7 @@ public function getFiles(array $params): array
111112
{
112113
return [
113114
__DIR__.'/../Resources/skeleton/crud/controller/Controller.tpl.php' => 'src/Controller/'.$params['controller_class_name'].'.php',
114-
// __DIR__.'/../Resources/skeleton/crud/form/Type.tpl.php' => 'src/Form/'.$params['form_class_name'].'.php',
115+
__DIR__.'/../Resources/skeleton/crud/form/Type.tpl.php' => 'src/Form/'.$params['form_class_name'].'.php',
115116
__DIR__.'/../Resources/skeleton/crud/templates/_delete_form.tpl.php' => 'templates/'.$params['route_name'].'/_delete_form.html.twig',
116117
__DIR__.'/../Resources/skeleton/crud/templates/_form.tpl.php' => 'templates/'.$params['route_name'].'/_form.html.twig',
117118
__DIR__.'/../Resources/skeleton/crud/templates/index.tpl.php' => 'templates/'.$params['route_name'].'/index.html.twig',
@@ -138,27 +139,29 @@ public function configureDependencies(DependencyBuilder $dependencies)
138139
'annotations'
139140
);
140141

141-
// $dependencies->addClassDependency(
142-
// AbstractType::class,
143-
// // technically only form is needed, but the user will *probably* also want validation
144-
// 'form'
145-
// );
146-
//
147-
// $dependencies->addClassDependency(
148-
// Validation::class,
149-
// 'validator',
150-
// // add as an optional dependency: the user *probably* wants validation
151-
// false
152-
// );
142+
$dependencies->addClassDependency(
143+
AbstractType::class,
144+
'form'
145+
);
146+
147+
$dependencies->addClassDependency(
148+
Validation::class,
149+
'validator'
150+
);
153151

154152
$dependencies->addClassDependency(
155153
TwigBundle::class,
156154
'twig-bundle'
157155
);
158156

159157
$dependencies->addClassDependency(
160-
EntityManager::class,
161-
'orm-pack'
158+
DoctrineBundle::class,
159+
'orm'
160+
);
161+
162+
$dependencies->addClassDependency(
163+
Column::class,
164+
'orm'
162165
);
163166
}
164167

tests/Maker/FunctionalTest.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public function getCommandTests()
254254
$this->assertNotContains('Success', $output);
255255

256256
$this->assertContains('No database changes were detected', $output);
257-
}),
257+
})
258258
];
259259

260260
yield 'crud' => [MakerTestDetails::createTest(
@@ -264,15 +264,17 @@ public function getCommandTests()
264264
'SweetFood',
265265
])
266266
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeCrud')
267+
->addReplacement(
268+
'phpunit.xml.dist',
269+
'mysql://db_user:[email protected]:3306/db_name',
270+
'sqlite:///%kernel.project_dir%/var/app.db'
271+
)
267272
->addReplacement(
268273
'.env',
269274
'mysql://db_user:[email protected]:3306/db_name',
270275
'sqlite:///%kernel.project_dir%/var/app.db'
271276
)
272-
->addExtraDependencies('symfony/orm-pack')
273-
->assert(function (string $output, string $directory) {
274-
$this->assertContains('Success', $output);
275-
}),
277+
->addPreMakeCommand('./bin/console doctrine:schema:create --env=test')
276278
];
277279
}
278280

tests/fixtures/MakeCrud/src/Entity/SweetFood.php

+16
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,20 @@ class SweetFood
2020
* @ORM\Column(name="title", type="string", length=255)
2121
*/
2222
private $title;
23+
24+
/**
25+
* @return mixed
26+
*/
27+
public function getTitle()
28+
{
29+
return $this->title;
30+
}
31+
32+
/**
33+
* @param mixed $title
34+
*/
35+
public function setTitle($title)
36+
{
37+
$this->title = $title;
38+
}
2339
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Tests;
4+
5+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6+
7+
class GeneratedCrudControllerTest extends WebTestCase
8+
{
9+
public function testIndexAction()
10+
{
11+
$client = self::createClient();
12+
$client->request('GET', '/sweet/food/');
13+
14+
$this->assertEquals(200, $client->getResponse()->getStatusCode());
15+
$this->assertContains('<!DOCTYPE html>', $client->getResponse()->getContent());
16+
$this->assertContains('SweetFood index', $client->getResponse()->getContent());
17+
}
18+
19+
public function testNewAction()
20+
{
21+
$client = self::createClient();
22+
$client->request('GET', '/sweet/food/new');
23+
24+
$this->assertEquals(200, $client->getResponse()->getStatusCode());
25+
$this->assertContains('<!DOCTYPE html>', $client->getResponse()->getContent());
26+
$this->assertContains('New SweetFood', $client->getResponse()->getContent());
27+
}
28+
}

0 commit comments

Comments
 (0)