Пример #1
0
 public function testFindQueryWithMultipleWheres()
 {
     $connection = m::mock('juicyORM\\Database\\DbConnection');
     $connection->shouldReceive('query')->with('SELECT * FROM "monster" WHERE "species" = ? AND "origin" = ?', array('Jormungandr', 'Norse'))->once()->andReturn(array($this->fake_monster_table[2]));
     $db = juicyORM\Database\DB::Instance($this->dbConfig, $connection, true);
     $user_response = Monster::where("species", "=", "Jormungandr")->where("origin", "=", "Norse")->find();
     $this->assertEquals(gettype($user_response), 'array');
     $this->assertEquals(gettype($user_response[0]), 'object');
     $this->assertEquals(get_class($user_response[0]), 'juicyORM\\Database\\ModelRow');
     $this->assertEquals($user_response[0]->species, 'Jormungandr');
     $this->assertEquals($db->runtime_info(), array(array('sql' => 'SELECT * FROM "monster" WHERE "species" = ? AND "origin" = ?', 'bindings' => array('Jormungandr', 'Norse'))));
 }
Пример #2
0
 public function testDetachAll()
 {
     $connection = m::mock('juicyORM\\Database\\DbConnection');
     $connection->shouldReceive('query')->with('SELECT * FROM "tree" WHERE "tree_id" = ?', array(1))->once()->andReturn(array($this->fake_tree_table[0]));
     $connection->shouldReceive('query')->with('DELETE FROM "leaf_tree" WHERE "tree_id" = ?', array(1), false)->once()->andReturn(true);
     $db = juicyORM\Database\DB::Instance($this->dbConfig, $connection, true);
     $tree = new Tree($db);
     $user_response = $tree->find(1)->leaves->detach_all();
     $this->assertEquals(gettype($user_response), 'boolean');
     $this->assertEquals($user_response, true);
     $this->assertEquals($db->runtime_info(), array(array('sql' => 'SELECT * FROM "tree" WHERE "tree_id" = ?', 'bindings' => array(1)), array('sql' => 'DELETE FROM "leaf_tree" WHERE "tree_id" = ?', 'bindings' => array(1))));
 }
Пример #3
0
 public function testDestroyViaModelRow()
 {
     $connection = m::mock('juicyORM\\Database\\DbConnection');
     $connection->shouldReceive('query')->with('SELECT * FROM "user" WHERE "user_id" = ?', array('1'))->once()->andReturn(array($this->fake_user_table[0]));
     $connection->shouldReceive('query')->with('DELETE FROM "user" WHERE "user_id" = ?', array('1'), false)->once()->andReturn(true);
     $db = juicyORM\Database\DB::Instance($this->dbConfig, $connection, true);
     $user = new User($db);
     $user_response = $user->find(1)->destroy();
     $this->assertEquals(gettype($user_response), 'NULL');
     $this->assertEquals($db->runtime_info(), array(array('sql' => 'SELECT * FROM "user" WHERE "user_id" = ?', 'bindings' => array('1')), array('sql' => 'DELETE FROM "user" WHERE "user_id" = ?', 'bindings' => array('1'))));
 }