Exemple #1
0
 function testFindOne()
 {
     $this->fillPages(10);
     $m = $this->getManager();
     $c = new Repository($m);
     $c->setTable('pages');
     $p = $c->findOne(2);
     $this->assertInstanceOf('SQRT\\DB\\Item', $p, 'Объект Item');
     $this->assertEquals(2, $p->get('id'), 'ID = 2');
     $p = $c->findOne('id < 10', 'id DESC');
     $this->assertEquals(9, $p->get('id'), 'ID = 9');
 }
Exemple #2
0
 function testDelete()
 {
     $m = $this->getManager();
     $c = new Repository($m);
     $c->setTable('pages');
     $p = $c->make();
     $p->setPrimaryKey('id');
     $p->set('name', 'Hello');
     $p->save();
     $p1 = $c->findOne(1);
     $p1->setPrimaryKey(false);
     try {
         $p1->delete();
         $this->fail('Ожидаемое исключение');
     } catch (\SQRT\DB\Exception $e) {
         $this->assertEquals(\SQRT\DB\Exception::PK_NOT_SET, $e->getCode(), 'Первичный ключ не задан');
     }
     $p->delete();
     $this->assertEquals(0, $c->count(), 'Записей в таблице нет');
 }