예제 #1
0
 public function test_execute_should_handle_bindings()
 {
     $db = new AkDbAdapter(array());
     // no conection details, we're using a Mock
     Mock::generate('ADOConnection');
     $connection = new MockADOConnection();
     $connection->setReturnValue('Execute', true);
     $connection->expectAt(0, 'Execute', array('SELECT * FROM articles WHERE id=1'));
     $connection->expectAt(1, 'Execute', array('SELECT * FROM articles WHERE id=?', array(1)));
     $db->connection =& $connection;
     $db->execute('SELECT * FROM articles WHERE id=1');
     $db->execute(array('SELECT * FROM articles WHERE id=?', 1));
 }
예제 #2
0
 public function setUp()
 {
     $this->db = new AkDbAdapter(array());
     // no conection details, we're using a Mock
     Mock::generate('ADOConnection');
     $connection = new MockADOConnection();
     Mock::generate('ADORecordSet');
     $RecordSet = new MockADORecordSet();
     $RecordSet->setReturnValue('FetchRow', false);
     $RecordSet->setReturnValueAt(0, 'FetchRow', array('id' => 1, 'name' => 'One'));
     $RecordSet->setReturnValueAt(1, 'FetchRow', array('id' => 2, 'name' => 'Two'));
     $RecordSet->setReturnValueAt(2, 'FetchRow', array('id' => 3, 'name' => 'Three'));
     $RecordSet->setReturnValueAt(3, 'FetchRow', array('id' => 4, 'name' => 'Four'));
     $connection->setReturnValue('Execute', $RecordSet);
     $this->db->connection =& $connection;
 }
예제 #3
0
 public function test_find_on_association_with_conditions_array_sql()
 {
     $this->installAndIncludeModels(array('Friend' => 'id,name'));
     $Mary =& $this->Friend->create(array('name' => 'Mary'));
     $Mary->friend->add($this->Friend->create(array('name' => 'James')));
     //$db = new AkDbAdapter(array());  // no conection details, we're using a Mock
     Mock::generate('ADOConnection');
     $connection = new MockADOConnection();
     $result = new ADORecordSet_array(-1);
     $result->InitArray(array(array('id' => 1, 'name' => 'James')), array('id' => 'I', 'name' => 'C'));
     $connection->setReturnValue('Execute', $result);
     if ($Mary->_db->type() == 'sqlite') {
         $connection->expectAt(0, 'Execute', array('SELECT friends.* FROM friends LEFT OUTER JOIN friends_friends AS _FriendFriend ON _FriendFriend.related_id = friends.id LEFT OUTER JOIN friends AS _Friend ON _FriendFriend.friend_id = _Friend.id WHERE (friends.name = ?) AND (_FriendFriend.friend_id  LIKE  1) AND 1', array('James')));
     } else {
         $connection->expectAt(0, 'Execute', array('SELECT friends.* FROM friends LEFT OUTER JOIN friends_friends AS _FriendFriend ON _FriendFriend.related_id = friends.id LEFT OUTER JOIN friends AS _Friend ON _FriendFriend.friend_id = _Friend.id WHERE (friends.name = ?) AND (_FriendFriend.friend_id  =  1)', array('James')));
     }
     $oldConnection = $Mary->_db->connection;
     $Mary->_db->connection =& $connection;
     //$Mary->_db = $db;
     $Mary->friend->find(array('conditions' => array('name = ?', 'James')));
     $Mary->_db->connection = $oldConnection;
 }