From 6e3dfb8f681e2ca2146d140fb35a55e77972db88 Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Mon, 11 Nov 2013 16:14:27 +0200 Subject: [PATCH] "Sphinx" unit tests for "update" and "delete" added. --- extensions/sphinx/Schema.php | 17 +++++++++++++++++ tests/unit/extensions/sphinx/CommandTest.php | 27 +++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/extensions/sphinx/Schema.php b/extensions/sphinx/Schema.php index ca05e38..5afb445 100644 --- a/extensions/sphinx/Schema.php +++ b/extensions/sphinx/Schema.php @@ -19,6 +19,23 @@ use yii\db\TableSchema; 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. * This method may be overridden by child classes to create a DBMS-specific query builder. * @return QueryBuilder query builder instance diff --git a/tests/unit/extensions/sphinx/CommandTest.php b/tests/unit/extensions/sphinx/CommandTest.php index 47fb5b9..639dea2 100644 --- a/tests/unit/extensions/sphinx/CommandTest.php +++ b/tests/unit/extensions/sphinx/CommandTest.php @@ -3,6 +3,7 @@ namespace yiiunit\extensions\sphinx; use yii\db\DataReader; +use yii\db\Expression; /** * @group sphinx @@ -128,12 +129,34 @@ class CommandTest extends SphinxTestCase $command = $db->createCommand()->update( 'yii2_test_rt_index', [ - 'title' => 'Test title', - 'content' => 'Test content', 'type_id' => $newTypeId, ], 'id = 1' ); $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!'); } } \ No newline at end of file