Exemplo n.º 1
0
 /**
  * @expectedException              \InvalidArgumentException
  * @expectedExceptionMessageRegExp /The file "(.*)" already exists/
  */
 public function testThrowsExceptionWhenConfigFilePresent()
 {
     touch(sys_get_temp_dir() . '/phinx.yml');
     $application = new PhinxApplication('testing');
     $application->add(new Init());
     $command = $application->find('init');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), 'path' => sys_get_temp_dir()), array('decorated' => false));
 }
Exemplo n.º 2
0
 /**
  * @expectedException              \InvalidArgumentException
  * @expectedExceptionMessageRegExp /The file "(.*)" already exists/
  */
 public function testThrowsExceptionWhenConfigFilePresent()
 {
     touch(sys_get_temp_dir() . '/phinx.yml');
     $application = new PhinxApplication('testing');
     $application->add(new Init());
     // setup dependencies
     $output = new StreamOutput(fopen('php://memory', 'a', false));
     $command = $application->find('init');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), 'path' => sys_get_temp_dir()), array('decorated' => false));
 }
Exemplo n.º 3
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The seed class name "badseedname" is invalid. Please use CamelCase format
  */
 public function testExecuteWithInvalidClassName()
 {
     $application = new PhinxApplication('testing');
     $application->add(new SeedCreate());
     /** @var SeedCreate $command */
     $command = $application->find('seed:create');
     // mock the manager class
     /** @var Manager|PHPUnit_Framework_MockObject_MockObject $managerStub */
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $this->input, $this->output));
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), 'name' => 'badseedname'), array('decorated' => false));
 }
Exemplo n.º 4
0
 public function testDatabaseNameSpecified()
 {
     $application = new PhinxApplication('testing');
     $application->add(new Rollback());
     /** @var Rollback $command */
     $command = $application->find('rollback');
     // mock the manager class
     /** @var Manager|PHPUnit_Framework_MockObject_MockObject $managerStub */
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $this->input, $this->output));
     $managerStub->expects($this->once())->method('rollback');
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
     $this->assertRegExp('/using database development/', $commandTester->getDisplay());
 }
Exemplo n.º 5
0
 public function testFormatSpecified()
 {
     $application = new PhinxApplication('testing');
     $application->add(new Status());
     /** @var Status $command */
     $command = $application->find('status');
     // mock the manager class
     /** @var Manager|PHPUnit_Framework_MockObject_MockObject $managerStub */
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $this->input, $this->output));
     $managerStub->expects($this->once())->method('printStatus')->will($this->returnValue(0));
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $return = $commandTester->execute(array('command' => $command->getName(), '--format' => 'json'), array('decorated' => false));
     $this->assertEquals(0, $return);
     $this->assertRegExp('/using format json/', $commandTester->getDisplay());
 }
Exemplo n.º 6
0
 public function testExecuteMultipleSeeders()
 {
     $application = new PhinxApplication('testing');
     $application->add(new SeedRun());
     /** @var SeedRun $command */
     $command = $application->find('seed:run');
     // mock the manager class
     /** @var Manager|PHPUnit_Framework_MockObject_MockObject $managerStub */
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $this->input, $this->output));
     $managerStub->expects($this->exactly(3))->method('seed')->withConsecutive(array($this->identicalTo('development'), $this->identicalTo('One')), array($this->identicalTo('development'), $this->identicalTo('Two')), array($this->identicalTo('development'), $this->identicalTo('Three')));
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), '--seed' => ['One', 'Two', 'Three']), array('decorated' => false));
     $this->assertRegExp('/no environment specified/', $commandTester->getDisplay());
 }
Exemplo n.º 7
0
 /**
  * @param array $config
  * @param array $commandLine
  * @dataProvider provideSimpleTemplateGenerator
  */
 public function testSimpleTemplateGeneratorsIsCorrectlyPopulated(array $config, array $commandLine)
 {
     $application = new PhinxApplication('testing');
     $application->add(new Create());
     /** @var Create $command $command */
     $command = $application->find('create');
     /** @var Manager $managerStub mock the manager class */
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $this->input, $this->output));
     foreach ($config as $key => $value) {
         $this->config[$key] = $value;
     }
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandLine = array_merge(array('command' => $command->getName()), $commandLine);
     $commandTester->execute($commandLine, array('decorated' => false));
     // Get output.
     preg_match('`created (?P<MigrationFilename>.+(?P<Version>\\d{14}).*?)\\s`', $commandTester->getDisplay(), $match);
     // Was migration created?
     $this->assertFileExists($match['MigrationFilename'], 'Failed to create migration file from template generator');
     // Get migration.
     $actualMigration = file_get_contents($match['MigrationFilename']);
     // Does the migration match our expectation?
     $expectedMigration = "useClassName Phinx\\Migration\\AbstractMigration / className {$commandLine['name']} / version {$match['Version']} / baseClassName AbstractMigration";
     $this->assertSame($expectedMigration, $actualMigration, 'Failed to create migration file from template generator correctly.');
 }
Exemplo n.º 8
0
 /**
  * @param array $config
  * @param array $commandLine
  * @dataProvider provideSimpleTemplateGenerator
  */
 public function testSimpleTemplateGeneratorsIsCorrectlyPopulated(array $config, array $commandLine)
 {
     $application = new PhinxApplication('testing');
     $application->add(new Create());
     // setup dependencies
     $input = new ArrayInput([]);
     $output = new StreamOutput(fopen('php://memory', 'a', false));
     /** @var Create $command $command */
     $command = $application->find('create');
     /** @var Manager $managerStub mock the manager class */
     $managerStub = $this->getMock('\\Phinx\\Migration\\Manager', array(), array($this->config, $input, $output));
     foreach ($config as $key => $value) {
         $this->config[$key] = $value;
     }
     $command->setConfig($this->config);
     $command->setManager($managerStub);
     $commandTester = new CommandTester($command);
     $commandLine = array_merge(array('command' => $command->getName()), $commandLine);
     $commandTester->execute($commandLine, array('decorated' => false));
     // Get output.
     preg_match('`^using migration path (.*?)\\s+using migration base class (.*?)\\s+using template creation class (.*?)\\s+created (\\1.(\\d++)(.*?))\\s+`', $commandTester->getDisplay(), $match);
     // Was migration created?
     $this->assertFileExists($match[4], 'Failed to create migration file from template generator');
     // Get migration.
     $actualMigration = file_get_contents($match[4]);
     // Does the migration match our expectation?
     $expectedMigration = "useClassName Phinx\\Migration\\AbstractMigration / className {$commandLine['name']} / version {$match[5]} / baseClassName AbstractMigration";
     $this->assertSame($expectedMigration, $actualMigration, 'Failed to create migration file from template generator correctly.');
 }