Skip to content

Commit

Permalink
minor #70 Simplification and minor fixes to functional test (yceruto)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

Simplification and minor fixes to functional test

Commits
-------

83bbaee Improving functional test
  • Loading branch information
javiereguiluz committed Nov 30, 2017
2 parents 57c8372 + 83bbaee commit cf62a28
Showing 1 changed file with 24 additions and 36 deletions.
60 changes: 24 additions & 36 deletions tests/Command/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\MakerBundle\Command\MakerCommand;
use Symfony\Bundle\MakerBundle\EventRegistry;
use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\Maker\MakeAuthenticator;
use Symfony\Bundle\MakerBundle\Maker\MakeCommand;
use Symfony\Bundle\MakerBundle\Maker\MakeController;
Expand All @@ -19,9 +22,6 @@
use Symfony\Bundle\MakerBundle\Maker\MakeUnitTest;
use Symfony\Bundle\MakerBundle\Maker\MakeValidator;
use Symfony\Bundle\MakerBundle\Maker\MakeVoter;
use Symfony\Bundle\MakerBundle\EventRegistry;
use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\MakerBundle;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Component\Config\Loader\LoaderInterface;
Expand All @@ -38,20 +38,19 @@

class FunctionalTest extends TestCase
{
private $fs;
private $targetDir;

public function setUp()
{
$tmpDir = sys_get_temp_dir().'/sf'.random_int(111111, 999999);
@mkdir($tmpDir, 0777, true);

$this->targetDir = $tmpDir;
$this->targetDir = sys_get_temp_dir().'/'.uniqid('sf_maker_', true);
$this->fs = new Filesystem();
$this->fs->mkdir($this->targetDir);
}

public function tearDown()
{
$fs = new Filesystem();
$fs->remove($this->targetDir);
$this->fs->remove($this->targetDir);
}

/**
Expand All @@ -60,7 +59,6 @@ public function tearDown()
public function testCommands(MakerInterface $maker, array $inputs)
{
$command = new MakerCommand($maker, $this->createGenerator());

$command->setCheckDependencies(false);

$tester = new CommandTester($command);
Expand All @@ -81,9 +79,7 @@ public function testCommands(MakerInterface $maker, array $inputs)

public function getCommandTests()
{
$makers = array();

$makers['command'] = array(
yield 'command' => array(
new MakeCommand(),
array(
// command name
Expand All @@ -95,31 +91,31 @@ public function getCommandTests()
$router->expects($this->once())
->method('getRouteCollection')
->willReturn(new RouteCollection());
$makers['controller'] = array(
yield 'controller' => array(
new MakeController($router),
array(
// controller class name
'FooBar',
),
);

$makers['entity'] = array(
yield 'entity' => array(
new MakeEntity(),
array(
// entity class name
'FooBar',
),
);

$makers['form'] = array(
yield 'form' => array(
new MakeForm(),
array(
// form name
'FooBar',
),
);

$makers['functional'] = array(
yield 'functional' => array(
new MakeFunctionalTest(),
array(
// functional test class
Expand All @@ -135,7 +131,7 @@ public function getCommandTests()
->method('getEventClassName')
->with('kernel.request')
->willReturn(GetResponseEvent::class);
$makers['subscriber'] = array(
yield 'subscriber' => array(
new MakeSubscriber($eventRegistry),
array(
// subscriber name
Expand All @@ -152,7 +148,7 @@ public function getCommandTests()
$eventRegistry2->expects($this->once())
->method('getEventClassName')
->willReturn(null);
$makers['subscriber_unknown_event_class'] = array(
yield 'subscriber_unknown_event_class' => array(
new MakeSubscriber($eventRegistry2),
array(
// subscriber name
Expand All @@ -162,7 +158,7 @@ public function getCommandTests()
),
);

$makers['serializer_encoder'] = array(
yield 'serializer_encoder' => array(
new MakeSerializerEncoder(),
array(
// encoder class name
Expand All @@ -172,47 +168,45 @@ public function getCommandTests()
),
);

$makers['twig_extension'] = array(
yield 'twig_extension' => array(
new MakeTwigExtension(),
array(
// extension class name
'FooBar',
),
);

$makers['unit_test'] = array(
yield 'unit_test' => array(
new MakeUnitTest(),
array(
// class name
'FooBar',
),
);

$makers['validator'] = array(
yield 'validator' => array(
new MakeValidator(),
array(
// validator name
'FooBar',
),
);

$makers['voter'] = array(
yield 'voter' => array(
new MakeVoter(),
array(
// voter class name
'FooBar',
),
);

$makers['auth_empty'] = array(
yield 'auth_empty' => array(
new MakeAuthenticator(),
array(
// class name
'AppCustomAuthenticator',
),
);

return $makers;
}

/**
Expand All @@ -228,7 +222,7 @@ public function testWiring()

$application = new Application($kernel);
foreach ($finder as $file) {
$class = 'Symfony\Bundle\MakerBundle\Maker\\'.substr($file->getFilename(), 0, strlen($file->getFilename()) - 4);
$class = 'Symfony\Bundle\MakerBundle\Maker\\'.$file->getBasename('.php');

$commandName = $class::getCommandName();
// if the command does not exist, this will explode
Expand Down Expand Up @@ -263,8 +257,6 @@ class FunctionalTestKernel extends Kernel
{
use MicroKernelTrait;

private $cacheDir;

public function registerBundles()
{
return array(
Expand All @@ -282,12 +274,8 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
$c->setParameter('kernel.secret', 123);
}

public function getCacheDir()
public function getRootDir()
{
if (null === $this->cacheDir) {
$this->cacheDir = sys_get_temp_dir().'/'.rand(100, 999);
}

return $this->cacheDir;
return sys_get_temp_dir().'/'.uniqid('sf_maker_', true);
}
}

0 comments on commit cf62a28

Please sign in to comment.