1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the KleijnWeb\SwaggerBundle package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace KleijnWeb\SwaggerBundle\Tests\Document; |
10
|
|
|
|
11
|
|
|
use KleijnWeb\SwaggerBundle\Document\YamlParser; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author John Kleijn <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class YamlParserTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Check Symfony\Yaml bug |
20
|
|
|
* |
21
|
|
|
* @see https://github.com/symfony/symfony/issues/17709 |
22
|
|
|
* |
23
|
|
|
* @test |
24
|
|
|
*/ |
25
|
|
|
public function canParseNumericMap() |
26
|
|
|
{ |
27
|
|
|
$yaml = <<<YAML |
28
|
|
|
map: |
29
|
|
|
1: one |
30
|
|
|
2: two |
31
|
|
|
YAML; |
32
|
|
|
$parser = new YamlParser(); |
33
|
|
|
$actual = $parser->parse($yaml); |
34
|
|
|
$this->assertInternalType('object', $actual); |
35
|
|
|
$this->assertInternalType('object', $actual->map); |
36
|
|
|
$this->assertTrue(property_exists($actual->map, '1')); |
37
|
|
|
$this->assertTrue(property_exists($actual->map, '2')); |
38
|
|
|
$this->assertSame('one', $actual->map->{'1'}); |
39
|
|
|
$this->assertSame('two', $actual->map->{'2'}); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Check Symfony\Yaml bug |
44
|
|
|
* |
45
|
|
|
* @see https://github.com/symfony/symfony/pull/17711 |
46
|
|
|
* |
47
|
|
|
* @test |
48
|
|
|
*/ |
49
|
|
|
public function willParseArrayAsArrayAndObjectAsObject() |
50
|
|
|
{ |
51
|
|
|
$yaml = <<<YAML |
52
|
|
|
array: |
53
|
|
|
- key: one |
54
|
|
|
- key: two |
55
|
|
|
YAML; |
56
|
|
|
|
57
|
|
|
$parser = new YamlParser(); |
58
|
|
|
$actual = $parser->parse($yaml); |
59
|
|
|
$this->assertInternalType('object', $actual); |
60
|
|
|
|
61
|
|
|
$this->assertInternalType('array', $actual->array); |
62
|
|
|
$this->assertInternalType('object', $actual->array[0]); |
63
|
|
|
$this->assertInternalType('object', $actual->array[1]); |
64
|
|
|
$this->assertSame('one', $actual->array[0]->key); |
65
|
|
|
$this->assertSame('two', $actual->array[1]->key); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|