Пример #1
0
 public function testDescribeTable()
 {
     $this->loadFixtures(['Users', 'Stats']);
     $user = new User();
     $this->assertEquals(['id' => ['field' => 'id', 'type' => 'int', 'length' => '11', 'null' => false, 'primary' => true, 'ai' => true], 'country_id' => ['field' => 'country_id', 'type' => 'int', 'length' => '11', 'null' => true, 'index' => true], 'username' => ['field' => 'username', 'type' => 'varchar', 'length' => '255', 'null' => false, 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci', 'unique' => true], 'password' => ['field' => 'password', 'type' => 'varchar', 'length' => '255', 'null' => true, 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci'], 'email' => ['field' => 'email', 'type' => 'varchar', 'length' => '255', 'null' => true, 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci'], 'firstName' => ['field' => 'firstName', 'type' => 'varchar', 'length' => '255', 'null' => true, 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci'], 'lastName' => ['field' => 'lastName', 'type' => 'varchar', 'length' => '255', 'null' => true, 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci'], 'age' => ['field' => 'age', 'type' => 'smallint', 'length' => '6', 'null' => true], 'created' => ['field' => 'created', 'type' => 'datetime', 'length' => '', 'null' => true, 'default' => null], 'modified' => ['field' => 'modified', 'type' => 'datetime', 'length' => '', 'null' => true, 'default' => null]], $user->getDriver()->describeTable($user->getTable()));
     $stat = new Stat();
     $this->assertEquals(['id' => ['field' => 'id', 'type' => 'int', 'length' => '11', 'null' => false, 'primary' => true, 'ai' => true], 'name' => ['field' => 'name', 'type' => 'varchar', 'length' => '255', 'null' => true, 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci'], 'health' => ['field' => 'health', 'type' => 'int', 'length' => '11', 'null' => true], 'energy' => ['field' => 'energy', 'type' => 'smallint', 'length' => '6', 'null' => true], 'damage' => ['field' => 'damage', 'type' => 'float', 'length' => '', 'null' => true], 'defense' => ['field' => 'defense', 'type' => 'double', 'length' => '', 'null' => true], 'range' => ['field' => 'range', 'type' => 'decimal', 'length' => '8,2', 'null' => true], 'isMelee' => ['field' => 'isMelee', 'type' => 'tinyint', 'length' => '1', 'null' => true], 'data' => ['field' => 'data', 'type' => 'blob', 'length' => '', 'null' => true]], $user->getDriver()->describeTable($stat->getTable()));
 }
Пример #2
0
 public function testBuildUpdateJoins()
 {
     $user = new User();
     $query = $user->query(Query::UPDATE)->data(['username' => 'foo']);
     $query->rightJoin(['profiles', 'Profile'], [], ['User.id' => 'Profile.user_id']);
     $this->assertRegExp('/UPDATE\\s+(`|\\")?users(`|\\")? AS (`|\\")?User(`|\\")? RIGHT JOIN (`|\\")?profiles(`|\\")? AS (`|\\")?Profile(`|\\")? ON (`|\\")?User(`|\\")?\\.(`|\\")?id(`|\\")? = (`|\\")?Profile(`|\\")?\\.(`|\\")?user_id(`|\\")?\\s+SET (`|\\")?User(`|\\")?\\.(`|\\")?username(`|\\")? = \\?;/', $this->object->buildUpdate($query));
     // With fields
     $query = $user->query(Query::UPDATE)->data(['username' => 'foo']);
     $query->rightJoin(['profiles', 'Profile'], ['avatar' => 'image.jpg'], ['User.id' => 'Profile.user_id']);
     $this->assertRegExp('/UPDATE\\s+(`|\\")?users(`|\\")? AS (`|\\")?User(`|\\")? RIGHT JOIN (`|\\")?profiles(`|\\")? AS (`|\\")?Profile(`|\\")? ON (`|\\")?User(`|\\")?\\.(`|\\")?id(`|\\")? = (`|\\")?Profile(`|\\")?\\.(`|\\")?user_id(`|\\")?\\s+SET (`|\\")?User(`|\\")?\\.(`|\\")?username(`|\\")? = \\?, (`|\\")?Profile(`|\\")?\\.(`|\\")?avatar(`|\\")? = \\?;/', $this->object->buildUpdate($query));
 }