예제 #1
0
 /**
  * @depends testSetterGetter
  * @depends testSetMultiple
  */
 public function testGetAndHasId()
 {
     // normal id
     $a = Test_Basic::create();
     $this->assertFalse($a->hasId());
     $a->set('id', 768);
     $this->assertTrue($a->hasId());
     $this->assertEquals(768, $a->getId());
     // custom id
     $a = DifferentIdField::create();
     $this->assertFalse($a->hasId());
     $a->set('custom_id', 98765);
     $this->assertTrue($a->hasId());
     $this->assertEquals(98765, $a->getId());
     // compound keys
     $compoundModel = Test\Compound::create();
     $this->assertFalse($compoundModel->hasId());
     $compoundModel->setData(array('foo_id' => 1, 'bar_id' => 77, 'name' => 'Foo Bar'));
     $this->assertTrue($compoundModel->hasId());
     $this->assertEquals(array('foo_id' => 1, 'bar_id' => 77), $compoundModel->getId());
 }
예제 #2
0
 /**
  * @depends testBasic
  * @depends testNullIfNotFound
  */
 public function testCompound()
 {
     // check if empty
     $result = Test\Compound::findAll();
     $this->assertInternalType('array', $result);
     $this->assertEmpty($result);
     // create
     $model1 = Test\Compound::create();
     $model1->foo_id = 5;
     $model1->bar_id = 10;
     $model1->name = '5 to 10';
     $this->assertTrue($model1->save());
     // create
     $model2 = Test\Compound::create();
     $model2->foo_id = 7;
     $model2->bar_id = 10;
     $model2->name = '7 to 10';
     $this->assertTrue($model2->save());
     // create
     $model3 = Compound::create();
     $model3->foo_id = 11;
     $model3->bar_id = 1;
     $model3->name = '11 to 1';
     $this->assertTrue($model3->save());
     // create and delete
     $model4 = Test\Compound::create();
     $model4->foo_id = 11;
     $model4->bar_id = 8;
     $model4->name = '11 to 8';
     $this->assertTrue($model4->save());
     $this->assertTrue($model4->delete());
     // query one
     $model = Test\Compound::find(5, 10);
     $this->assertInstanceOf('\\RormTest\\Test\\Compound', $model);
     $this->assertEquals(5, $model->foo_id);
     $this->assertEquals(10, $model->bar_id);
     // query many
     $query = Test\Compound::query();
     $query->whereGt('foo_id', 6);
     $query->orderByAsc('foo_id');
     $result = $query->findMany();
     $this->assertInstanceOf('\\Rorm\\QueryIterator', $result);
     foreach ($result as $model) {
         /** @var Compound $model */
         // check if correct model
         $this->assertInstanceOf('\\RormTest\\Test\\Compound', $model);
         // check if not filtered item
         $this->assertNotEquals($model1->foo_id, $model->foo_id);
     }
     // query buffered
     $result = Test\Compound::findAll();
     $this->assertInternalType('array', $result);
     $this->assertNotEmpty($result);
     $this->assertContainsOnlyInstancesOf('\\RormTest\\Test\\Compound', $result);
     $this->assertEquals(3, count($result));
 }