JsonValidatorTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Serialize\Test\Unit;
  7. use Magento\Framework\Serialize\JsonValidator;
  8. class JsonValidatorTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var JsonValidator
  12. */
  13. private $jsonValidator;
  14. protected function setUp()
  15. {
  16. $this->jsonValidator = new JsonValidator();
  17. }
  18. /**
  19. * @param string $value
  20. * @param bool $expected
  21. * @dataProvider isValidDataProvider
  22. */
  23. public function testIsValid($value, $expected)
  24. {
  25. $this->assertEquals(
  26. $expected,
  27. $this->jsonValidator->isValid($value)
  28. );
  29. }
  30. /**
  31. * @return array
  32. */
  33. public function isValidDataProvider()
  34. {
  35. return [
  36. ['""', true],
  37. ['"string"', true],
  38. ['null', true],
  39. ['false', true],
  40. ['{"a":"b","d":123}', true],
  41. ['123', true],
  42. ['10.56', true],
  43. [123, true],
  44. [10.56, true],
  45. ['{}', true],
  46. ['"', false],
  47. ['"string', false],
  48. [null, false],
  49. [false, false],
  50. ['{"a', false],
  51. ['{', false],
  52. ['', false]
  53. ];
  54. }
  55. }