-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load connection fixtures command (#7)
* Introduce Elasticsearch Fixtures * Update tests and readme * Add final keyword * Update composer * Provide to ElasticSearchExecutor & update tests * Update readme * Define data-fixtures package dependency version * Address code review * Apply Code Standards * Format config * Update parameters.yml * Added LoadDatabaseFixturesCommand * Added append option and confirm to LoadDatabaseFixturesCommand * Refactor in DoctrineCompilerPass; added tests for LoadDatabaseFixturesCommand; added LoadDatabaseFixturesCommand to readme; refactor in LoadDatabaseFixturesCommand * Improvements in README.md * Code Review addressed
- Loading branch information
1 parent
12f9ac6
commit 598d114
Showing
14 changed files
with
627 additions
and
91 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
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,55 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Kununu\TestingBundle\Command; | ||
|
||
use Kununu\TestingBundle\Service\Orchestrator; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class LoadDatabaseFixturesCommand extends Command | ||
{ | ||
private $connectionName; | ||
private $orchestrator; | ||
private $fixturesClassNames; | ||
|
||
public function __construct(string $connectionName, Orchestrator $orchestrator, array $fixturesClassNames) | ||
{ | ||
parent::__construct(sprintf('kununu_testing:load_fixtures:connections:%s', $connectionName)); | ||
|
||
$this->connectionName = $connectionName; | ||
$this->orchestrator = $orchestrator; | ||
$this->fixturesClassNames = $fixturesClassNames; | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
parent::configure(); | ||
|
||
$this | ||
->setDescription('Load Database Fixtures') | ||
->addOption('append', null, InputOption::VALUE_NONE, 'Append the data fixtures instead of deleting all data from the database first.'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): void | ||
{ | ||
$appendOption = $input->getOption('append'); | ||
|
||
$ui = new SymfonyStyle($input, $output); | ||
|
||
if (!$appendOption && | ||
!$ui->confirm( | ||
sprintf('Careful, database "%s" will be purged. Do you want to continue?', $this->connectionName), | ||
!$input->isInteractive() | ||
) | ||
) { | ||
return; | ||
} | ||
|
||
$this->orchestrator->execute($this->fixturesClassNames, $appendOption); | ||
|
||
$output->writeln(sprintf('Fixtures loaded with success for connection "%s"', $this->connectionName)); | ||
} | ||
} |
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,15 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Kununu\TestingBundle\Tests\App\Fixtures\Connection; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Kununu\DataFixtures\Adapter\ConnectionFixtureInterface; | ||
|
||
final class ConnectionFixture3 implements ConnectionFixtureInterface | ||
{ | ||
public function load(Connection $connection): void | ||
{ | ||
$connection->exec('INSERT INTO `table_1` (`name`, `description`) VALUES (\'name3\', \'description3\');'); | ||
$connection->exec('INSERT INTO `table_2` (`name`, `description`) VALUES (\'name3\', \'description3\');'); | ||
} | ||
} |
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,15 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Kununu\TestingBundle\Tests\App\Fixtures\Connection; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Kununu\DataFixtures\Adapter\ConnectionFixtureInterface; | ||
|
||
final class ConnectionFixture4 implements ConnectionFixtureInterface | ||
{ | ||
public function load(Connection $connection): void | ||
{ | ||
$connection->exec('INSERT INTO `table_1` (`name`, `description`) VALUES (\'name4\', \'description4\');'); | ||
$connection->exec('INSERT INTO `table_2` (`name`, `description`) VALUES (\'name4\', \'description4\');'); | ||
} | ||
} |
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,41 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use Kununu\TestingBundle\Tests\App\Kernel; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Input\ArgvInput; | ||
use Symfony\Component\Debug\Debug; | ||
|
||
set_time_limit(0); | ||
|
||
require dirname(__DIR__).'/../../vendor/autoload.php'; | ||
|
||
if (!class_exists(Application::class)) { | ||
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.'); | ||
} | ||
|
||
require dirname(__DIR__).'/config/bootstrap.php'; | ||
|
||
$input = new ArgvInput(); | ||
|
||
if (null !== $env = $input->getParameterOption(['--env', '-e'], $_ENV['APP_ENV'], true)) { | ||
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); | ||
} | ||
|
||
if ($input->hasParameterOption('--no-debug', true) || | ||
$_ENV['APP_ENV'] === 'prod' | ||
) { | ||
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); | ||
} | ||
|
||
if ($_SERVER['APP_DEBUG']) { | ||
umask(0000); | ||
|
||
if (class_exists(Debug::class)) { | ||
Debug::enable(); | ||
} | ||
} | ||
|
||
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); | ||
$application = new Application($kernel); | ||
$application->run($input); |
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
Oops, something went wrong.