/** * testSetGetVersion method * * @return void */ public function testSetGetVersion() { $this->Version = $this->getMock('MigrationVersion', array('getMapping'), array(array('connection' => 'test'))); // Checking current $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping())); $result = $this->Version->getVersion('inexistent_plugin'); $expected = 0; $this->assertEqual($result, $expected); // Setting as 1 $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping())); $this->Version->expects($this->at(1))->method('getMapping')->will($this->returnValue($this->__mapping(1, 1))); $setResult = $this->Version->setVersion(1, 'inexistent_plugin'); $this->assertTrue(!empty($setResult)); $result = $this->Version->getVersion('inexistent_plugin'); $expected = 1; $this->assertEqual($result, $expected); // Setting as 2 $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 1))); $this->Version->expects($this->at(1))->method('getMapping')->will($this->returnValue($this->__mapping(1, 2))); $setResult = $this->Version->setVersion(2, 'inexistent_plugin'); $this->assertTrue(!empty($setResult)); $result = $this->Version->getVersion('inexistent_plugin'); $expected = 2; $this->assertEqual($result, $expected); // Setting as 1 $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 2))); $this->Version->expects($this->at(1))->method('getMapping')->will($this->returnValue($this->__mapping(1, 1))); $setResult = $this->Version->setVersion(2, 'inexistent_plugin', false); $this->assertTrue(!empty($setResult)); $result = $this->Version->getVersion('inexistent_plugin'); $expected = 1; $this->assertEqual($result, $expected); }
/** * testRun method * * @return void */ public function testRun() { $back = $this->Version; $options = array('connection' => 'test'); $Version = $this->getMock('MigrationVersion', array('getMapping', 'getMigration'), array($options), 'TestMigrationVersionMockMigrationVersion', false); $this->Version = $Version; $this->Version->expects($this->any())->method('getMigration')->will($this->returnValue(new CakeMigration($options))); $this->Version->Version = ClassRegistry::init(array('class' => 'schema_migrations', 'ds' => 'test')); // direction => up $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping())); $this->assertEqual($Version->getVersion('mocks'), 0); $this->assertTrue($Version->run(array('direction' => 'up', 'type' => 'mocks'))); $this->assertEqual($this->__migrated(), array(1)); $this->assertEqual($Version->getVersion('mocks'), 1); // direction => down $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 1))); $this->assertTrue($Version->run(array('direction' => 'down', 'type' => 'mocks'))); $this->assertEqual($this->__migrated(), array()); $this->assertEqual($Version->getVersion('mocks'), 0); // Set 1, 2, 3 versions applied $this->Version->setVersion(1, 'mocks'); $this->Version->setVersion(2, 'mocks'); $this->Version->setVersion(3, 'mocks'); // direction => up $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 3))); $this->assertEqual($Version->getVersion('mocks'), 3); $this->assertTrue($Version->run(array('direction' => 'up', 'type' => 'mocks'))); $this->assertEqual($this->__migrated(), range(1, 4)); $this->assertEqual($Version->getVersion('mocks'), 4); // direction => down $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 4))); $this->assertTrue($Version->run(array('direction' => 'down', 'type' => 'mocks'))); $this->assertEqual($this->__migrated(), range(1, 3)); $this->assertEqual($Version->getVersion('mocks'), 3); // version => 7 $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 3))); $this->assertTrue($Version->run(array('version' => 7, 'type' => 'mocks'))); $this->assertEqual($this->__migrated(), range(1, 7)); $this->assertEqual($Version->getVersion('mocks'), 7); // version => 3 $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 7))); $this->assertTrue($Version->run(array('version' => 3, 'type' => 'mocks'))); $this->assertEqual($this->__migrated(), range(1, 3)); $this->assertEqual($Version->getVersion('mocks'), 3); // version => 10 (top version) $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 3))); $this->assertTrue($Version->run(array('version' => 10, 'type' => 'mocks'))); $this->assertEqual($this->__migrated(), range(1, 10)); $this->assertEqual($Version->getVersion('mocks'), 10); // version => 0 (run down all migrations) //$Version->setReturnValueAt($mappingCount++, 'getMapping', $this->__mapping(1, 10)); $this->Version->expects($this->at(0))->method('getMapping')->will($this->returnValue($this->__mapping(1, 10))); $this->assertTrue($Version->run(array('version' => 0, 'type' => 'mocks'))); $this->assertEqual($this->__migrated(), array()); $this->assertEqual($Version->getVersion('mocks'), 0); // Changing values back $this->Version = $back; unset($back); }