1
|
|
|
<?php declare(strict_types = 1); |
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\Serialize; |
10
|
|
|
|
11
|
|
|
use KleijnWeb\SwaggerBundle\Document\Specification\Operation; |
12
|
|
|
use KleijnWeb\SwaggerBundle\Serialize\SerializationTypeResolver; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author John Kleijn <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class SerializationTypeResolverTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var SerializationTypeResolver |
21
|
|
|
*/ |
22
|
|
|
private $resolver; |
23
|
|
|
|
24
|
|
|
protected function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->resolver = new SerializationTypeResolver([ |
27
|
|
|
'KleijnWeb\SwaggerBundle\Tests\Serialize\Stubs\Namespace2', |
28
|
|
|
'KleijnWeb\SwaggerBundle\Tests\Serialize\Stubs\Namespace1' |
29
|
|
|
]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @test |
34
|
|
|
* @expectedException \InvalidArgumentException |
35
|
|
|
*/ |
36
|
|
|
public function unresolvableTypeResultsInException() |
37
|
|
|
{ |
38
|
|
|
$this->resolver->resolveUsingTypeName('Nope'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @test |
44
|
|
|
* @expectedException \InvalidArgumentException |
45
|
|
|
*/ |
46
|
|
|
public function willThrowExceptionWhenBaseTypeNameCannotBeDeterminedFromSchema() |
47
|
|
|
{ |
48
|
|
|
$this->resolver->resolveUsingSchema(new \stdClass()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @test |
53
|
|
|
*/ |
54
|
|
|
public function canResolveTypesInOrderUsingMultipleNamespaces() |
55
|
|
|
{ |
56
|
|
|
$this->assertSame(Stubs\Namespace2\Foo::class, $this->resolver->resolveUsingTypeName('Foo')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @test |
61
|
|
|
*/ |
62
|
|
|
public function canResolveSameTypeTwice() |
63
|
|
|
{ |
64
|
|
|
$this->assertSame(Stubs\Namespace2\Foo::class, $this->resolver->resolveUsingTypeName('Foo')); |
65
|
|
|
$this->assertSame(Stubs\Namespace2\Foo::class, $this->resolver->resolveUsingTypeName('Foo')); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @test |
70
|
|
|
*/ |
71
|
|
|
public function canReverseLookupPreviouslyResolvedType() |
72
|
|
|
{ |
73
|
|
|
$this->resolver->resolveUsingTypeName('Foo'); |
74
|
|
|
$this->assertSame('Foo', $this->resolver->reverseLookup(Stubs\Namespace2\Foo::class)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @test |
79
|
|
|
* @expectedException \InvalidArgumentException |
80
|
|
|
*/ |
81
|
|
|
public function reverseLookupWillFailIfNotPreviouslyResolved() |
82
|
|
|
{ |
83
|
|
|
$this->resolver->reverseLookup(Stubs\Namespace2\Foo::class); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @test |
88
|
|
|
* @expectedException \InvalidArgumentException |
89
|
|
|
*/ |
90
|
|
|
public function resolveOperationBodyTypeWillFailWhenOperationHasNoParameters() |
91
|
|
|
{ |
92
|
|
|
/** @var Operation $operation */ |
93
|
|
|
$operation = $this->getMockBuilder(Operation::class)->disableOriginalConstructor()->getMock(); |
94
|
|
|
|
95
|
|
|
$this->resolver->resolveOperationBodyType($operation); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|