-
-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #1497 [make:*] add ability to generate tests
- Loading branch information
Showing
12 changed files
with
531 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony MakerBundle package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\MakerBundle\Maker\Common; | ||
|
||
use Symfony\Bundle\MakerBundle\ConsoleStyle; | ||
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* @author Jesse Rushlow <jr@rushlow.dev> | ||
* | ||
* @internal | ||
*/ | ||
trait CanGenerateTestsTrait | ||
{ | ||
private bool $generateTests = false; | ||
|
||
public function configureCommandWithTestsOption(Command $command): Command | ||
{ | ||
$testsHelp = file_get_contents(\dirname(__DIR__, 2).'/Resources/help/_WithTests.txt'); | ||
$help = $command->getHelp()."\n".$testsHelp; | ||
|
||
$command | ||
->addOption(name: 'with-tests', mode: InputOption::VALUE_NONE, description: 'Generate PHPUnit Tests') | ||
->setHelp($help) | ||
; | ||
|
||
return $command; | ||
} | ||
|
||
public function interactSetGenerateTests(InputInterface $input, ConsoleStyle $io): void | ||
{ | ||
// Sanity check for maker dev's - End user should never see this. | ||
if (!$input->hasOption('with-tests')) { | ||
throw new RuntimeCommandException('Whoops! "--with-tests" option does not exist. Call "addWithTestsOptions()" in the makers "configureCommand().'); | ||
} | ||
|
||
$this->generateTests = $input->getOption('with-tests'); | ||
|
||
if (!$this->generateTests) { | ||
$this->generateTests = $io->confirm('Do you want to generate PHPUnit tests? [Experimental]', false); | ||
} | ||
} | ||
|
||
public function shouldGenerateTests(): bool | ||
{ | ||
return $this->generateTests; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,6 @@ | ||
To generate tailored PHPUnit tests, simply call: | ||
|
||
<info>php %command.full_name% --with-tests</info> | ||
|
||
This will generate a unit test in <info>tests/</info> for you to review then use | ||
to test the new functionality of your app. |
Oops, something went wrong.