BufferedResultSetTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * PHP Version 5.4
  4. *
  5. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice.
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://cakephp.org CakePHP(tm) Project
  14. * @since CakePHP(tm) v 3.0.0
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. namespace Cake\Test\TestCase\ORM;
  18. use Cake\Core\Configure;
  19. use Cake\Database\ConnectionManager;
  20. use Cake\ORM\BufferedResultSet;
  21. use Cake\ORM\Query;
  22. use Cake\ORM\Table;
  23. use Cake\TestSuite\TestCase;
  24. /**
  25. * BufferedResultSet test case.
  26. */
  27. class BufferedResultSetTest extends TestCase {
  28. public $fixtures = ['core.article'];
  29. public function setUp() {
  30. parent::setUp();
  31. $this->connection = ConnectionManager::get('test');
  32. $this->table = new Table(['table' => 'articles', 'connection' => $this->connection]);
  33. }
  34. /**
  35. * Test that result sets can be rewound and re-used.
  36. *
  37. * @return void
  38. */
  39. public function testRewind() {
  40. $query = $this->table->find('all');
  41. $results = $query->bufferResults()->execute();
  42. $first = $second = [];
  43. foreach ($results as $result) {
  44. $first[] = $result;
  45. }
  46. foreach ($results as $result) {
  47. $second[] = $result;
  48. }
  49. $this->assertEquals($first, $second);
  50. }
  51. }