Browse Source

"Sphinx" unit tests for "update" and "delete" added.

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
6e3dfb8f68
  1. 17
      extensions/sphinx/Schema.php
  2. 27
      tests/unit/extensions/sphinx/CommandTest.php

17
extensions/sphinx/Schema.php

@ -19,6 +19,23 @@ use yii\db\TableSchema;
class Schema extends \yii\db\mysql\Schema class Schema extends \yii\db\mysql\Schema
{ {
/** /**
* @var array mapping from physical column types (keys) to abstract column types (values)
*/
public $typeMap = [
'field' => self::TYPE_STRING,
'string' => self::TYPE_STRING,
'ordinal' => self::TYPE_STRING,
'integer' => self::TYPE_INTEGER,
'int' => self::TYPE_INTEGER,
'uint' => self::TYPE_INTEGER,
'bigint' => self::TYPE_BIGINT,
'timestamp' => self::TYPE_TIMESTAMP,
'bool' => self::TYPE_BOOLEAN,
'float' => self::TYPE_FLOAT,
'mva' => self::TYPE_STRING,
];
/**
* Creates a query builder for the database. * Creates a query builder for the database.
* This method may be overridden by child classes to create a DBMS-specific query builder. * This method may be overridden by child classes to create a DBMS-specific query builder.
* @return QueryBuilder query builder instance * @return QueryBuilder query builder instance

27
tests/unit/extensions/sphinx/CommandTest.php

@ -3,6 +3,7 @@
namespace yiiunit\extensions\sphinx; namespace yiiunit\extensions\sphinx;
use yii\db\DataReader; use yii\db\DataReader;
use yii\db\Expression;
/** /**
* @group sphinx * @group sphinx
@ -128,12 +129,34 @@ class CommandTest extends SphinxTestCase
$command = $db->createCommand()->update( $command = $db->createCommand()->update(
'yii2_test_rt_index', 'yii2_test_rt_index',
[ [
'title' => 'Test title',
'content' => 'Test content',
'type_id' => $newTypeId, 'type_id' => $newTypeId,
], ],
'id = 1' 'id = 1'
); );
$this->assertEquals(1, $command->execute(), 'Unable to execute update!'); $this->assertEquals(1, $command->execute(), 'Unable to execute update!');
list($row) = $db->createCommand('SELECT * FROM yii2_test_rt_index')->queryAll();
$this->assertEquals($newTypeId, $row['type_id'], 'Unable to update attribute value!');
}
/**
* @depends testInsert
*/
public function testDelete()
{
$db = $this->getConnection();
$db->createCommand()->insert('yii2_test_rt_index', [
'title' => 'Test title',
'content' => 'Test content',
'type_id' => 2,
'id' => 1,
])->execute();
$command = $db->createCommand()->delete('yii2_test_rt_index', 'id = 1');
$this->assertEquals(1, $command->execute(), 'Unable to execute delete!');
$rows = $db->createCommand('SELECT * FROM yii2_test_rt_index')->queryAll();
$this->assertEquals(0, count($rows), 'Unable to delete record!');
} }
} }
Loading…
Cancel
Save