|
|
|
@ -241,32 +241,32 @@ class ActiveRecordTest extends ElasticSearchTestCase
|
|
|
|
|
|
|
|
|
|
public function testFindComplexCondition() |
|
|
|
|
{ |
|
|
|
|
$this->assertEquals(2, Customer::find()->where(array('OR', array('id' => 1), array('id' => 2)))->count()); |
|
|
|
|
$this->assertEquals(2, count(Customer::find()->where(array('OR', array('id' => 1), array('id' => 2)))->all())); |
|
|
|
|
$this->assertEquals(2, Customer::find()->where(array('OR', array('name' => 'user1'), array('name' => 'user2')))->count()); |
|
|
|
|
$this->assertEquals(2, count(Customer::find()->where(array('OR', array('name' => 'user1'), array('name' => 'user2')))->all())); |
|
|
|
|
|
|
|
|
|
$this->assertEquals(2, Customer::find()->where(array('id' => array(1,2)))->count()); |
|
|
|
|
$this->assertEquals(2, count(Customer::find()->where(array('id' => array(1,2)))->all())); |
|
|
|
|
$this->assertEquals(2, Customer::find()->where(array('name' => array('user1','user2')))->count()); |
|
|
|
|
$this->assertEquals(2, count(Customer::find()->where(array('name' => array('user1','user2')))->all())); |
|
|
|
|
|
|
|
|
|
$this->assertEquals(1, Customer::find()->where(array('AND', array('id' => array(2,3)), array('BETWEEN', 'status', 2, 4)))->count()); |
|
|
|
|
$this->assertEquals(1, count(Customer::find()->where(array('AND', array('id' => array(2,3)), array('BETWEEN', 'status', 2, 4)))->all())); |
|
|
|
|
$this->assertEquals(1, Customer::find()->where(array('AND', array('name' => array('user2','user3')), array('BETWEEN', 'status', 2, 4)))->count()); |
|
|
|
|
$this->assertEquals(1, count(Customer::find()->where(array('AND', array('name' => array('user2','user3')), array('BETWEEN', 'status', 2, 4)))->all())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testSum() |
|
|
|
|
{ |
|
|
|
|
$this->assertEquals(6, OrderItem::find()->count()); |
|
|
|
|
$this->assertEquals(7, OrderItem::find()->sum('quantity')); |
|
|
|
|
} |
|
|
|
|
// public function testSum() |
|
|
|
|
// { |
|
|
|
|
// $this->assertEquals(6, OrderItem::find()->count()); |
|
|
|
|
// $this->assertEquals(7, OrderItem::find()->sum('quantity')); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
public function testFindColumn() |
|
|
|
|
{ |
|
|
|
|
$this->assertEquals(array('user1', 'user2', 'user3'), Customer::find()->column('name')); |
|
|
|
|
// TODO $this->assertEquals(array('user3', 'user2', 'user1'), Customer::find()->orderBy(array('name' => Query::SORT_DESC))->column('name')); |
|
|
|
|
} |
|
|
|
|
// public function testFindColumn() |
|
|
|
|
// { |
|
|
|
|
// $this->assertEquals(array('user1', 'user2', 'user3'), Customer::find()->column('name')); |
|
|
|
|
//// TODO $this->assertEquals(array('user3', 'user2', 'user1'), Customer::find()->orderBy(array('name' => Query::SORT_DESC))->column('name')); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
public function testExists() |
|
|
|
|
{ |
|
|
|
|
$this->assertTrue(Customer::find()->where(array('id' => 2))->exists()); |
|
|
|
|
$this->assertFalse(Customer::find()->where(array('id' => 5))->exists()); |
|
|
|
|
$this->assertTrue(Customer::find()->where(array('name' => 'user1'))->exists()); |
|
|
|
|
$this->assertFalse(Customer::find()->where(array('name' => 'user5'))->exists()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// public function testFindLazy() |
|
|
|
@ -393,19 +393,19 @@ class ActiveRecordTest extends ElasticSearchTestCase
|
|
|
|
|
$customer->name = 'user4'; |
|
|
|
|
$customer->address = 'address4'; |
|
|
|
|
|
|
|
|
|
$this->assertNull($customer->id); |
|
|
|
|
$this->assertNull($customer->primaryKey); |
|
|
|
|
$this->assertTrue($customer->isNewRecord); |
|
|
|
|
|
|
|
|
|
$customer->save(); |
|
|
|
|
|
|
|
|
|
$this->assertNotNull($customer->id); |
|
|
|
|
$this->assertNotNull($customer->primaryKey); |
|
|
|
|
$this->assertFalse($customer->isNewRecord); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testInsertPk() |
|
|
|
|
{ |
|
|
|
|
$customer = new Customer; |
|
|
|
|
$customer->id = 5; |
|
|
|
|
$customer->primaryKey = 5; |
|
|
|
|
$customer->email = 'user5@example.com'; |
|
|
|
|
$customer->name = 'user5'; |
|
|
|
|
$customer->address = 'address5'; |
|
|
|
@ -414,7 +414,7 @@ class ActiveRecordTest extends ElasticSearchTestCase
|
|
|
|
|
|
|
|
|
|
$customer->save(); |
|
|
|
|
|
|
|
|
|
$this->assertEquals(5, $customer->id); |
|
|
|
|
$this->assertEquals(5, $customer->primaryKey); |
|
|
|
|
$this->assertFalse($customer->isNewRecord); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -447,15 +447,12 @@ class ActiveRecordTest extends ElasticSearchTestCase
|
|
|
|
|
{ |
|
|
|
|
$this->setExpectedException('yii\base\NotSupportedException'); |
|
|
|
|
|
|
|
|
|
$pk = array('id' => 2); |
|
|
|
|
$pk = array('primaryKey' => 2); |
|
|
|
|
$orderItem = Order::find($pk); |
|
|
|
|
$this->assertEquals(2, $orderItem->id); |
|
|
|
|
$this->assertEquals(2, $orderItem->primaryKey); |
|
|
|
|
|
|
|
|
|
$orderItem->id = 13; |
|
|
|
|
$orderItem->primaryKey = 13; |
|
|
|
|
$orderItem->save(); |
|
|
|
|
|
|
|
|
|
$this->assertNull(OrderItem::find($pk)); |
|
|
|
|
$this->assertNotNull(OrderItem::find(array('id' => 13))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testDelete() |
|
|
|
@ -468,10 +465,12 @@ class ActiveRecordTest extends ElasticSearchTestCase
|
|
|
|
|
$customer = Customer::find(2); |
|
|
|
|
$this->assertNull($customer); |
|
|
|
|
|
|
|
|
|
Customer::getDb()->createCommand()->flushIndex('customers'); |
|
|
|
|
|
|
|
|
|
// deleteAll |
|
|
|
|
$customers = Customer::find()->all(); |
|
|
|
|
$this->assertEquals(2, count($customers)); |
|
|
|
|
$ret = Customer::deleteAll(); |
|
|
|
|
$ret = Customer::deleteAll([1,2,3]); |
|
|
|
|
$this->assertEquals(2, $ret); |
|
|
|
|
$customers = Customer::find()->all(); |
|
|
|
|
$this->assertEquals(0, count($customers)); |
|
|
|
|