Skip to content

Commit

Permalink
reduces execute function lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Antoine FOURNEL committed Jan 5, 2016
1 parent c5b109a commit 2946b39
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions Command/FunctionalTestGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ protected function execute(InputInterface $input, OutputInterface $output)


}

if ( !empty( $controllers ) )
{
$this->generate($targetBundle, $controllers, $input, $output);
}

public function generate( $targetBundle, $controllers, $input, $output ){
if ( !empty( $controllers ) ){
$output->writeln( "Writing controller test");
foreach ( $controllers as $name => $routes )
{
foreach ( $controllers as $name => $routes ){
$addTest = $this->createControllerTestFile($targetBundle, $name);
$questionHelper = $this->getHelper('question');

Expand All @@ -71,43 +72,42 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<error>Command aborted</error>');
return ;
}
foreach ( $routes as $route )
{
foreach ( $routes as $route ){
$match = $this->namespace . $targetBundle;
$ctrl = explode (":", str_ireplace( $match, "", $route->getDefault('_controller') ) );
$actionName = end( $ctrl );
$skip = 0;
$output->writeln("\r\n<info>Generation test for route $actionName ...</info>");
if ( $skip == 0)
{
if ( $skip == 0){
$dir = dirname($this->getContainer()->getParameter('kernel.root_dir')).'/src/'.$this->namespace."/".$targetBundle;
if ( !is_dir ( $dir."/Tests" ) ){
$output->writeln( "\r\n Generating directory..." );
mkdir($dir."/Tests", 0755, true);
}
if ( !is_dir( $dir."/Tests/Controller")){
$output->writeln( "\r\n Generating tests controller directory..." );
mkdir($dir."/Tests/Controller", 0755, true);
}

if ( !file_exists($dir."/Tests/SetUpFunctionalTest.php")){
$this->generateDir($dir, $output);
if ( !file_exists($dir."/Tests/SetUpFunctionalTest.php")){
$output->writeln( "\r\n Generating SetUpFunctionalTest in {$targetBundle}.php ..." );
file_put_contents($dir."/Tests/SetUpFunctionalTest.php", $this->generateSetupFunctionTest($targetBundle));
}

$addTest .= $this->addTestAction($actionName, $route);
}
}

$addTest .= "
}
";
}";
file_put_contents($dir."/Tests/Controller/" . $name . "Test.php", $addTest);
}
}
}
}

public function generateDir( $dir, $output )
{
if ( !is_dir ( $dir."/Tests" ) ){
$output->writeln( "\r\n Generating directory..." );
mkdir($dir."/Tests", 0755, true);
}
if ( !is_dir( $dir."/Tests/Controller")){
$output->writeln( "\r\n Generating tests controller directory..." );
mkdir($dir."/Tests/Controller", 0755, true);
}
}

public function createControllerTestFile( $targetBundle, $name )
{
return "
Expand Down

0 comments on commit 2946b39

Please sign in to comment.