MockComment.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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;
  9. use lithium\data\model\Query;
  10. use lithium\data\entity\Record;
  11. use lithium\data\collection\RecordSet;
  12. class MockComment extends \lithium\tests\mocks\data\MockBase {
  13. public $belongsTo = array('MockPost');
  14. public static $connection = null;
  15. protected $_meta = array('connection' => false, 'key' => 'comment_id');
  16. public static function find($type, array $options = array()) {
  17. $defaults = array(
  18. 'conditions' => null, 'fields' => null, 'order' => null, 'limit' => null, 'page' => 1
  19. );
  20. $options += $defaults;
  21. $params = compact('type', 'options');
  22. $self = static::_object();
  23. $filter = function($self, $params) {
  24. extract($params);
  25. $query = new Query(array('type' => 'read') + $options);
  26. return new RecordSet(array(
  27. 'query' => $query,
  28. 'data' => array_map(
  29. function($data) {
  30. return new Record(compact('data') + array('model' => __CLASS__));
  31. },
  32. array(
  33. array('comment_id' => 1, 'author_id' => 123, 'text' => 'First comment'),
  34. array('comment_id' => 2, 'author_id' => 241, 'text' => 'Second comment'),
  35. array('comment_id' => 3, 'author_id' => 451, 'text' => 'Third comment')
  36. )
  37. )
  38. ));
  39. };
  40. $finder = isset($self->_finders[$type]) ? array($self->_finders[$type]) : array();
  41. return static::_filter(__METHOD__, $params, $filter, $finder);
  42. }
  43. }
  44. ?>