MockMongoConnection.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. class MockMongoConnection {
  11. public $queries = array();
  12. public $results = array();
  13. protected $_collection = null;
  14. public $gridFsPrefix = null;
  15. public function connect() {
  16. return false;
  17. }
  18. public function &__get($property) {
  19. $this->_collection = $property;
  20. return $this;
  21. }
  22. public function listDBs() {
  23. return array();
  24. }
  25. public function insert(array &$data, array $options = array()) {
  26. $data['_id'] = new MongoId();
  27. return $this->_record(__FUNCTION__, compact('data', 'options'));
  28. }
  29. protected function _record($type, array $data = array()) {
  30. $collection = $this->_collection;
  31. $this->queries[] = compact('type', 'collection') + $data;
  32. return array_pop($this->results);
  33. }
  34. public function update($conditions, $update, $options) {
  35. return $this->_record(__FUNCTION__, compact('conditions', 'update', 'options'));
  36. }
  37. public function remove($conditions, $options) {
  38. return $this->_record(__FUNCTION__, compact('conditions', 'options'));
  39. }
  40. public function find($conditions, $fields) {
  41. return $this->_record(__FUNCTION__, compact('conditions', 'fields'));
  42. }
  43. public function listCollections() {
  44. return $this->_record(__FUNCTION__);
  45. }
  46. public function getGridFS($prefix = "fs") {
  47. $this->gridFsPrefix = $prefix;
  48. return $this;
  49. }
  50. public function storeBytes($bytes = null, array $extra = array(), array $options = array()) {
  51. return;
  52. }
  53. }
  54. ?>