예제 #1
0
 /**
  * testRun method
  *
  * @return void
  */
 function testRun()
 {
     $back = $this->Version;
     $options = array('connection' => 'test_suite');
     $Version =& new TestMigrationVersionMockMigrationVersion($options);
     $this->Version = $Version;
     $this->Version->setReturnValue('getMigration', new CakeMigration($options));
     $this->Version->Version =& ClassRegistry::init(array('class' => 'schema_migrations', 'ds' => 'test_suite'));
     // Variable used on setReturValueAt method
     $mappingCount = 0;
     // direction => up
     $Version->setReturnValueAt($mappingCount++, 'getMapping', $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
     $Version->setReturnValueAt($mappingCount++, 'getMapping', $this->__mapping(1, 1));
     $this->assertEqual($Version->getVersion('mocks'), 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
     $Version->setReturnValueAt($mappingCount++, 'getMapping', $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
     $Version->setReturnValueAt($mappingCount++, 'getMapping', $this->__mapping(1, 4));
     $this->assertEqual($Version->getVersion('mocks'), 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
     $Version->setReturnValueAt($mappingCount++, 'getMapping', $this->__mapping(1, 3));
     $this->assertEqual($Version->getVersion('mocks'), 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
     $Version->setReturnValueAt($mappingCount++, 'getMapping', $this->__mapping(1, 7));
     $this->assertEqual($Version->getVersion('mocks'), 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)
     $Version->setReturnValueAt($mappingCount++, 'getMapping', $this->__mapping(1, 3));
     $this->assertEqual($Version->getVersion('mocks'), 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->assertEqual($Version->getVersion('mocks'), 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);
 }