CookiesCollectionTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of Chrome PHP.
  4. *
  5. * (c) Soufiane Ghzal <sghzal@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace HeadlessChromium\Test;
  11. use HeadlessChromium\Cookies\Cookie;
  12. use HeadlessChromium\Cookies\CookiesCollection;
  13. use PHPUnit\Framework\TestCase;
  14. /**
  15. * @covers \HeadlessChromium\Cookies\Cookie
  16. * @covers \HeadlessChromium\Cookies\CookiesCollection
  17. */
  18. class CookiesCollectionTest extends TestCase
  19. {
  20. public function testFilterBy(): void
  21. {
  22. $cookies = new CookiesCollection([
  23. Cookie::create('foo', 'bar'),
  24. Cookie::create('foo', 'baz'),
  25. Cookie::create('qux', 'quux'),
  26. ]);
  27. $newCookies = $cookies->filterBy('name', 'foo');
  28. $this->assertCount(2, $newCookies);
  29. $this->assertEquals('bar', $newCookies->getAt(0)->getValue());
  30. $this->assertEquals('baz', $newCookies->getAt(1)->getValue());
  31. }
  32. public function testFindOneBy(): void
  33. {
  34. $cookies = new CookiesCollection([
  35. Cookie::create('foo', 'bar'),
  36. Cookie::create('foo', 'baz'),
  37. Cookie::create('qux', 'quux'),
  38. ]);
  39. $cookieFoo = $cookies->findOneBy('name', 'foo');
  40. $cookieQux = $cookies->findOneBy('name', 'qux');
  41. $this->assertEquals('bar', $cookieFoo->getValue());
  42. $this->assertEquals('quux', $cookieQux->getValue());
  43. }
  44. }