ReplaceIteratorTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Collection\Iterator;
  16. use Cake\Collection\Iterator\ReplaceIterator;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * ReplaceIterator Test
  20. *
  21. */
  22. class ReplaceIteratorTest extends TestCase {
  23. /**
  24. * Tests that the iterator works correctly
  25. *
  26. * @return void
  27. */
  28. public function testReplace() {
  29. $items = new \ArrayIterator([1, 2, 3]);
  30. $callable = $this->getMock('stdClass', ['__invoke']);
  31. $callable->expects($this->at(0))
  32. ->method('__invoke')
  33. ->with(1, 0, $items)
  34. ->will($this->returnValue(1));
  35. $callable->expects($this->at(1))
  36. ->method('__invoke')
  37. ->with(2, 1, $items)
  38. ->will($this->returnValue(4));
  39. $callable->expects($this->at(2))
  40. ->method('__invoke')
  41. ->with(3, 2, $items)
  42. ->will($this->returnValue(9));
  43. $map = new ReplaceIterator($items, $callable);
  44. $this->assertEquals([1, 4, 9], iterator_to_array($map));
  45. }
  46. }