public function testExecute() { $session = $this->buildSession(); $application = new Application(); $application->add($this->newTestedInstance()->setSession($session)); $command = $application->find('pomm:generate:model'); $command_args = ['command' => $command->getName(), 'config-name' => 'pomm_test', 'schema' => 'pomm_test', 'relation' => 'beta', '--prefix-ns' => 'Model', '--prefix-dir' => 'tmp']; $tester = new CommandTester($command); $options = ['decorated' => false]; $tester->execute($command_args, $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Creating file 'tmp/Model/PommTest/PommTestSchema/BetaModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/BetaModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/BetaModel.php'))->exception(function () use($tester, $command, $command_args) { $tester->execute($command_args); })->isInstanceOf('\\PommProject\\ModelManager\\Exception\\GeneratorException')->message->contains('--force'); $tester->execute(array_merge($command_args, ['--force' => null]), $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Overwriting file 'tmp/Model/PommTest/PommTestSchema/BetaModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/BetaModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/BetaModel.php')); $tester->execute(array_merge($command_args, ['relation' => 'dingo']), $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Creating file 'tmp/Model/PommTest/PommTestSchema/DingoModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/DingoModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/DingoModel.php')); $inspector = new Inspector(); $inspector->initialize($session); if (version_compare($inspector->getVersion(), '9.3', '>=') === true) { $tester->execute(array_merge($command_args, ['relation' => 'pluto']), $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Creating file 'tmp/Model/PommTest/PommTestSchema/PlutoModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/PlutoModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/PlutoModel.php')); } $command_args['--prefix-dir'] = "tmp/Model"; $tester->execute(array_merge($command_args, ['--psr4' => null, '--force' => null]), $options); $this->string($tester->getDisplay())->isEqualTo(" ✓ Overwriting file 'tmp/Model/PommTest/PommTestSchema/BetaModel.php'." . PHP_EOL)->string(file_get_contents('tmp/Model/PommTest/PommTestSchema/BetaModel.php'))->isEqualTo(file_get_contents('sources/tests/Fixture/BetaModel.php')); }
public function initialize(Session $session) { parent::initialize($session); $sql = ['begin', 'create schema pomm_test', 'create type pomm_test.complex_type as (one int4, two varchar)', 'create table pomm_test.alpha(alpha_one serial primary key, alpha_two varchar not null, alpha_three timestamp not null default now())', 'create table pomm_test.beta(beta_one serial, beta_two int4, beta_three pomm_test.complex_type[] not null, primary key(beta_one, beta_two), unique(beta_one))', 'create table pomm_test.charly(charly_one char(2) unique, charly_two point)', 'create view pomm_test.dingo as select * from pomm_test.charly', 'comment on schema pomm_test is $c$This is a test schema.$c$', 'comment on table pomm_test.beta is $c$This is the beta comment.$c$', 'comment on column pomm_test.beta.beta_one is $c$This is the beta.one comment.$c$', 'commit']; $this->executeSql(join(';', $sql)); $inspector = new Inspector(); $inspector->initialize($session); if (version_compare($inspector->getVersion(), '9.3', '>=') === true) { $sql = 'create materialized view pomm_test.pluto as select * from pomm_test.charly;'; $this->executeSql($sql); } }
public function testExecute() { $session = $this->buildSession(); $application = new Application(); $application->add($this->newTestedInstance()->setSession($session)); $command = $application->find('pomm:inspect:schema'); $tester = new CommandTester($command); $tester->execute(['command' => $command->getName(), 'config-name' => 'pomm_test', 'schema' => 'pomm_test'], ['decorated' => false]); $display = $tester->getDisplay(); $this->string($display)->contains("| alpha | table")->contains("| beta | table")->contains("This is the beta comment.")->contains("| dingo | view"); $inspector = new Inspector(); $inspector->initialize($session); if (version_compare($inspector->getVersion(), '9.3', '>=') === true) { $this->string($display)->contains("| pluto | materialized view |"); } $this->exception(function () use($tester, $command) { $tester->execute(['command' => $command->getName(), 'config-name' => 'pomm_test', 'schema' => 'whatever']); })->isInstanceOf('\\PommProject\\Cli\\Exception\\CliException'); }