mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-16 14:29:30 +08:00
* Test against the current hhvm version This provides the current HHVM version (3.15.2 as of this PR) and will track with each release (i.e. will be 3.16 when 3.16 is released. If testing against HHVM LST versions is desired follow this guide. https://docs.travis-ci.com/user/languages/php#HHVM-versions Should be able to change to container based Trusty after Q1-17 https://blog.travis-ci.com/2016-11-08-trusty-container-public-beta/ * Try to create travis user for trusty hhvm and grant permissions remove conditionals for apc and memcache * more tweaks to grant privileges * try 127.0.0.1 rather than localhost * grant after db create * try a different create user grant privileges form * try to specify postgresql: "9.3" for hhvm * need to look more into specifying postgresql: "9.3" hhvm issues * addon with no dash postgresql: "9.3" * requested change && not || * redis-server isn't needed here * Apply @cebe's patch for pgsql test failure * Update .travis.yml * Update CommandTest.php * Update CommandTest.php * Update CommandTest.php try to fix hhvm tests * Update CommandTest.php
98 lines
3.3 KiB
PHP
98 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace yii\tests\unit\framework\db\pgsql;
|
|
|
|
/**
|
|
* @group db
|
|
* @group pgsql
|
|
*/
|
|
class CommandTest extends \yiiunit\framework\db\CommandTest
|
|
{
|
|
public $driverName = 'pgsql';
|
|
|
|
public function testAutoQuoting()
|
|
{
|
|
$db = $this->getConnection(false);
|
|
|
|
$sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t';
|
|
$command = $db->createCommand($sql);
|
|
$this->assertEquals('SELECT "id", "t"."name" FROM "customer" t', $command->sql);
|
|
}
|
|
|
|
public function testBooleanValuesInsert()
|
|
{
|
|
$db = $this->getConnection();
|
|
$command = $db->createCommand();
|
|
$command->insert('bool_values', ['bool_col' => true]);
|
|
$this->assertEquals(1, $command->execute());
|
|
|
|
$command = $db->createCommand();
|
|
$command->insert('bool_values', ['bool_col' => false]);
|
|
$this->assertEquals(1, $command->execute());
|
|
|
|
$command = $db->createCommand('SELECT COUNT(*) FROM "bool_values" WHERE bool_col = TRUE;');
|
|
$this->assertEquals(1, $command->queryScalar());
|
|
$command = $db->createCommand('SELECT COUNT(*) FROM "bool_values" WHERE bool_col = FALSE;');
|
|
$this->assertEquals(1, $command->queryScalar());
|
|
}
|
|
|
|
public function testBooleanValuesBatchInsert()
|
|
{
|
|
$db = $this->getConnection();
|
|
$command = $db->createCommand();
|
|
$command->batchInsert('bool_values',
|
|
['bool_col'], [
|
|
[true],
|
|
[false],
|
|
]
|
|
);
|
|
$this->assertEquals(2, $command->execute());
|
|
|
|
$command = $db->createCommand('SELECT COUNT(*) FROM "bool_values" WHERE bool_col = TRUE;');
|
|
$this->assertEquals(1, $command->queryScalar());
|
|
$command = $db->createCommand('SELECT COUNT(*) FROM "bool_values" WHERE bool_col = FALSE;');
|
|
$this->assertEquals(1, $command->queryScalar());
|
|
}
|
|
|
|
public function testLastInsertId()
|
|
{
|
|
$db = $this->getConnection();
|
|
|
|
$sql = 'INSERT INTO {{profile}}([[description]]) VALUES (\'non duplicate\')';
|
|
$command = $db->createCommand($sql);
|
|
$command->execute();
|
|
$this->assertEquals(3, $db->getSchema()->getLastInsertID('public.profile_id_seq'));
|
|
|
|
$sql = 'INSERT INTO {{schema1.profile}}([[description]]) VALUES (\'non duplicate\')';
|
|
$command = $db->createCommand($sql);
|
|
$command->execute();
|
|
$this->assertEquals(3, $db->getSchema()->getLastInsertID('schema1.profile_id_seq'));
|
|
}
|
|
|
|
/**
|
|
* @see https://github.com/yiisoft/yii2/issues/11498
|
|
*/
|
|
public function testSaveSerializedObject()
|
|
{
|
|
if (defined('HHVM_VERSION')) {
|
|
$this->markTestSkipped('HHVMs PgSQL implementation does not seem to support blob colums in the way they are used here.');
|
|
}
|
|
|
|
$db = $this->getConnection();
|
|
|
|
$command = $db->createCommand()->insert('type', [
|
|
'int_col' => 1,
|
|
'char_col' => 'serialize',
|
|
'float_col' => 5.6,
|
|
'bool_col' => true,
|
|
'blob_col' => serialize($db),
|
|
]);
|
|
$this->assertEquals(1, $command->execute());
|
|
|
|
$command = $db->createCommand()->update('type', [
|
|
'blob_col' => serialize($db),
|
|
], ['char_col' => 'serialize']);
|
|
$this->assertEquals(1, $command->execute());
|
|
}
|
|
}
|