CookieCollectionTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. * Licensed under The MIT License
  6. * Redistributions of files must retain the above copyright notice.
  7. *
  8. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. * @link http://cakephp.org CakePHP(tm) Project
  10. * @since 3.5.0
  11. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  12. */
  13. namespace Cake\Test\TestCase\Http\Cookie;
  14. use Cake\Http\Cookie\Cookie;
  15. use Cake\Http\Cookie\CookieCollection;
  16. use Cake\TestSuite\TestCase;
  17. /**
  18. * Cookie collection test.
  19. */
  20. class CookieCollectionTest extends TestCase
  21. {
  22. /**
  23. * Test constructor
  24. *
  25. * @return void
  26. */
  27. public function testConstructorWithEmptyArray()
  28. {
  29. $collection = new CookieCollection([]);
  30. $this->assertCount(0, $collection);
  31. }
  32. /**
  33. * Test valid cookies
  34. *
  35. * @return void
  36. */
  37. public function testConstructorWithCookieArray()
  38. {
  39. $cookies = [
  40. new Cookie('one', 'one'),
  41. new Cookie('two', 'two')
  42. ];
  43. $collection = new CookieCollection($cookies);
  44. $this->assertCount(2, $collection);
  45. }
  46. /**
  47. * Test that the constructor takes only an array of objects implementing
  48. * the CookieInterface
  49. *
  50. * @expectedException \InvalidArgumentException
  51. * @expectedExceptionMessage Expected `Cake\Http\Cookie\CookieCollection[]` as $cookies but instead got `array` at index 1
  52. * @return void
  53. */
  54. public function testConstructorWithInvalidCookieObjects()
  55. {
  56. $array = [
  57. new Cookie('one', 'one'),
  58. []
  59. ];
  60. new CookieCollection($array);
  61. }
  62. }