Beispiel #1
2
 /**
  * Runs the drop and create commands on the fixtures if necessary.
  *
  * @param \Cake\TestSuite\Fixture\TestFixture $fixture the fixture object to create
  * @param Connection $db the datasource instance to use
  * @param array $sources The existing tables in the datasource.
  * @param bool $drop whether drop the fixture if it is already created or not
  * @return void
  */
 protected function _setupTable(TestFixture $fixture, Connection $db, array $sources, $drop = true)
 {
     if (!empty($fixture->created) && in_array($db->configName(), $fixture->created)) {
         return;
     }
     $table = $fixture->table;
     $exists = in_array($table, $sources);
     if ($drop && $exists) {
         $fixture->drop($db);
         $fixture->create($db);
     } elseif (!$exists) {
         $fixture->create($db);
     } else {
         $fixture->created[] = $db->configName();
         $fixture->truncate($db);
     }
 }
 /**
  * Add check constraints.
  *
  * @param ConnectionInterface $db
  * @return boolean
  */
 public function create(ConnectionInterface $db)
 {
     $result = parent::create($db);
     $sql = ['ALTER TABLE "comments" ADD CONSTRAINT "comments_status_in_list" CHECK(cakephp_validate_in_list("status", ARRAY[\'awaiting\', \'ham\', \'spam\']));', 'ALTER TABLE "comments" ADD CONSTRAINT "comments_name_min_length" CHECK(cakephp_validate_min_length("name", 4));', 'ALTER TABLE "comments" ADD CONSTRAINT "comments_name_alpha_numeric" CHECK(cakephp_validate_alpha_numeric("name"));'];
     foreach ($sql as $stmt) {
         $db->query($stmt);
     }
     return $result;
 }
 /**
  * Runs the drop and create commands on the fixtures if necessary.
  *
  * @param \Cake\TestSuite\Fixture\TestFixture $fixture the fixture object to create
  * @param Connection $db the datasource instance to use
  * @param bool $drop whether drop the fixture if it is already created or not
  * @return void
  */
 protected function _setupTable(TestFixture $fixture, Connection $db = null, $drop = true)
 {
     if (!$db) {
         if (!empty($fixture->connection)) {
             $db = ConnectionManager::get($fixture->connection, false);
         }
         if (!$db) {
             $db = ConnectionManager::get('test', false);
         }
     }
     if (!empty($fixture->created) && in_array($db->configName(), $fixture->created)) {
         return;
     }
     $schemaCollection = $db->schemaCollection();
     $sources = (array) $schemaCollection->listTables();
     $table = $fixture->table;
     $exists = in_array($table, $sources);
     if ($drop && $exists) {
         $fixture->drop($db);
         $fixture->create($db);
     } elseif (!$exists) {
         $fixture->create($db);
     } else {
         $fixture->created[] = $db->configName();
     }
 }