IdentityMarshallerTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller;
  13. /**
  14. * @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
  15. */
  16. class IdentityMarshallerTest extends Testcase
  17. {
  18. public function testMarshall()
  19. {
  20. $marshaller = new IdentityMarshaller();
  21. $values = ['data' => 'string_data'];
  22. $failed = [];
  23. $this->assertSame($values, $marshaller->marshall($values, $failed));
  24. }
  25. /**
  26. * @dataProvider invalidMarshallDataProvider
  27. */
  28. public function testMarshallInvalidData($values)
  29. {
  30. $marshaller = new IdentityMarshaller();
  31. $failed = [];
  32. $this->expectException(\LogicException::class);
  33. $this->expectExceptionMessage('Symfony\Component\HttpFoundation\Session\Storage\Handler\IdentityMarshaller::marshall accepts only string as data');
  34. $marshaller->marshall($values, $failed);
  35. }
  36. public function testUnmarshall()
  37. {
  38. $marshaller = new IdentityMarshaller();
  39. $this->assertEquals('data', $marshaller->unmarshall('data'));
  40. }
  41. public static function invalidMarshallDataProvider(): iterable
  42. {
  43. return [
  44. [['object' => new \stdClass()]],
  45. [['foo' => ['bar']]],
  46. ];
  47. }
  48. }