PHP Classes

File: tests/ParserTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   iaso PHP JSON Parser Library   tests/ParserTest.php   Download  
File: tests/ParserTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: iaso PHP JSON Parser Library
Parse JSON strings immune to hash-DoS attacks
Author: By
Last change:
Date: 2 years ago
Size: 1,943 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

use
PHPUnit\Framework\TestCase;

/**
 * Class ParserTest
 */
class ParserTest extends TestCase
{
   
/**
     * @covers \ParagonIE\Iaso\Parser::parse()
     */
   
public function testParseBasic()
    {
       
$parser = new ParagonIE\Iaso\Parser();
       
$blank = new ParagonIE\Iaso\Contract\Blank();

       
$result = $parser->parse(
           
'{"apple":123,"boy":[1,2,3],"cat":{"a":1,"b":2,"c":3}}',
           
$blank
       
);
       
$this->assertSame(
            [
'apple' => 123, 'boy' => [1, 2, 3], 'cat' => ['a' => 1, 'b' => 2, 'c' => 3]],
           
$result->asArray(true),
           
'Failing with no whitespace'
       
);

       
$result = $parser->parse(
           
'{"apple":123,"boy":[1, 2, 3 ],"cat":{"a":1,"b":2,"c":3}}',
           
$blank
       
);
       
$this->assertSame(
            [
'apple' => 123, 'boy' => [1, 2, 3], 'cat' => ['a' => 1, 'b' => 2, 'c' => 3]],
           
$result->asArray(true),
           
'Failing with some whitespace'
       
);

       
$result = $parser->parse(
           
'{
                      "apple": 123,
                      "boy": [
                          1,
                          2,
                          3
                      ],
                      "cat": {
                          "a": 1,
                          "b": 2,
                          "c": 3.14
                      },
                      "dhole": true,
                      "dog": false,
                      "echo": null
                  }'
,
           
$blank
       
);
       
$this->assertSame(
            [
               
'apple' => 123,
               
'boy' => [1, 2, 3],
               
'cat' => ['a' => 1, 'b' => 2, 'c' => 3.14],
               
'dhole' => true,
               
'dog' => false,
               
'echo' => null
           
],
           
$result->asArray(true),
           
'Failing while prettified'
       
);
    }
}