public function testArrayAttributeRelationLazy() { $order = Order::findOne(1); $items = $order->itemsByArrayValue; $this->assertEquals(2, count($items)); $this->assertTrue(isset($items[1])); $this->assertTrue(isset($items[2])); $this->assertTrue($items[1] instanceof Item); $this->assertTrue($items[2] instanceof Item); $order = Order::findOne(2); $items = $order->itemsByArrayValue; $this->assertEquals(3, count($items)); $this->assertTrue(isset($items[3])); $this->assertTrue(isset($items[4])); $this->assertTrue(isset($items[5])); $this->assertTrue($items[3] instanceof Item); $this->assertTrue($items[4] instanceof Item); $this->assertTrue($items[5] instanceof Item); }
public function testUpdatePk() { $pkName = 'id'; $orderItem = Order::findOne([$pkName => 2]); $this->assertEquals(2, $orderItem->primaryKey); $this->assertEquals(2, $orderItem->oldPrimaryKey); $this->assertEquals(2, $orderItem->{$pkName}); // $this->setExpectedException('yii\base\InvalidCallException'); $orderItem->{$pkName} = 13; $this->assertEquals(13, $orderItem->primaryKey); $this->assertEquals(2, $orderItem->oldPrimaryKey); $this->assertEquals(13, $orderItem->{$pkName}); $orderItem->save(); $this->afterSave(); $this->assertEquals(13, $orderItem->primaryKey); $this->assertEquals(13, $orderItem->oldPrimaryKey); $this->assertEquals(13, $orderItem->{$pkName}); $this->assertNull(Order::findOne([$pkName => 2])); $this->assertNotNull(Order::findOne([$pkName => 13])); }