MockMongoSource.php 933 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\mocks\data\source;
  9. use MongoId;
  10. use lithium\tests\mocks\data\source\mongo_db\MockResult;
  11. class MockMongoSource extends \lithium\core\Object {
  12. public $resultSets = array();
  13. public $queries = array();
  14. public function __get($name) {
  15. return $this;
  16. }
  17. public function insert(&$data, $options) {
  18. $this->queries[] = compact('data', 'options');
  19. $result = current($this->resultSets);
  20. next($this->resultSets);
  21. $data['_id'] = new MongoId();
  22. return $result;
  23. }
  24. public function find($conditions, $fields) {
  25. $this->queries[] = compact('conditions', 'fields');
  26. $result = new MockResult(array('data' => current($this->resultSets)));
  27. next($this->resultSets);
  28. return $result;
  29. }
  30. }
  31. ?>