TransposeIteratorTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.3.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\Collection;
  17. use Cake\TestSuite\TestCase;
  18. class TransposeIteratorTest extends TestCase
  19. {
  20. public function testTranspose()
  21. {
  22. $collection = new Collection([
  23. ['Products', '2012', '2013', '2014'],
  24. ['Product A', '200', '100', '50'],
  25. ['Product B', '300', '200', '100'],
  26. ['Product C', '400', '300', '200'],
  27. ]);
  28. $transposed = $collection->transpose();
  29. $expected = [
  30. ['Products', 'Product A', 'Product B', 'Product C'],
  31. ['2012', '200', '300', '400'],
  32. ['2013', '100', '200', '300'],
  33. ['2014', '50', '100', '200'],
  34. ];
  35. $this->assertEquals($expected, $transposed->toList());
  36. }
  37. /**
  38. * Tests that provided arrays do not have even length
  39. *
  40. * @expectedException \LogicException
  41. * @return void
  42. */
  43. public function testTransposeUnEvenLengthShouldThrowException()
  44. {
  45. $collection = new Collection([
  46. ['Products', '2012', '2013', '2014'],
  47. ['Product A', '200', '100', '50'],
  48. ['Product B', '300'],
  49. ['Product C', '400', '300'],
  50. ]);
  51. $collection->transpose();
  52. }
  53. }