| +----------------------------------------------------------------------+ */ namespace App\Tests\Command; use App\Command\GenerateFixturesCommand; use App\Config; use App\Database; use App\Database\Adapter; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use PHPUnit\Framework\TestCase; class GenerateFixturesCommandTest extends TestCase { private $database; private $generateFixturesCommand; public function setUp() { $adapter = new Adapter(); $adapter->setDsn('sqlite::memory:'); $this->database = new Database($adapter->getInstance()); $this->generateFixturesCommand = new GenerateFixturesCommand(); $this->generateFixturesCommand->setDatabase($this->database); } public function testExecute() { $config = new Config(['env' => 'dev']); $this->generateFixturesCommand->setConfig($config); $application = new Application(); $application->add($this->generateFixturesCommand); $command = $application->find('app:generate-fixtures'); $commandTester = new CommandTester($command); $commandTester->setInputs(['n']); $exitCode = $commandTester->execute(['command' => $command->getName()]); $this->assertRegExp('/.../', $commandTester->getDisplay()); $this->assertSame(0, $exitCode); } public function testExecuteInProdEnv() { $config = new Config(['env' => 'prod']); $this->generateFixturesCommand->setConfig($config); $application = new Application(); $application->add($this->generateFixturesCommand); $command = $application->find('app:generate-fixtures'); $commandTester = new CommandTester($command); $commandTester->setInputs(['n']); $exitCode = $commandTester->execute(['command' => $command->getName()]); $this->assertRegExp('/This command can be executed only in dev/', $commandTester->getDisplay()); $this->assertSame(0, $exitCode); } }