1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2017 Gerrit Addiks. |
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
7
|
|
|
* @license GPL-3.0 |
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Addiks\RDMBundle\Tests\Exception; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Addiks\RDMBundle\Exception\FailedRDMAssertionException; |
15
|
|
|
use ReflectionClass; |
16
|
|
|
use Addiks\RDMBundle\Tests\Hydration\EntityExample; |
17
|
|
|
use Addiks\RDMBundle\Tests\Hydration\ServiceExample; |
18
|
|
|
use Addiks\RDMBundle\Tests\ValueObjectExample; |
19
|
|
|
|
20
|
|
|
final class FailedRDMAssertionExceptionTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var FailedRDMAssertionException |
25
|
|
|
*/ |
26
|
|
|
private $exception; |
27
|
|
|
|
28
|
|
|
public function setUp(): void |
29
|
|
|
{ |
30
|
|
|
$this->exception = new FailedRDMAssertionException("Some Message!", "some_type", [ |
31
|
|
|
'lorem' => 'ipsum', |
32
|
|
|
'dolor' => 'sit' |
33
|
|
|
]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @test |
38
|
|
|
*/ |
39
|
|
|
public function shouldStoreType() |
40
|
|
|
{ |
41
|
|
|
$this->assertEquals("some_type", $this->exception->getType()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
*/ |
47
|
|
|
public function shouldStoreParameters() |
48
|
|
|
{ |
49
|
|
|
$this->assertEquals([ |
50
|
|
|
'lorem' => 'ipsum', |
51
|
|
|
'dolor' => 'sit' |
52
|
|
|
], $this->exception->getParameters()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @test |
57
|
|
|
*/ |
58
|
|
|
public function shouldCreateExpectedDifferentServiceException() |
59
|
|
|
{ |
60
|
|
|
$reflectionClass = new ReflectionClass(EntityExample::class); |
61
|
|
|
|
62
|
|
|
$serviceA = new ServiceExample("lorem", 123); |
63
|
|
|
$serviceB = new ServiceExample("ipsum", 456); |
64
|
|
|
|
65
|
|
|
/** @var FailedRDMAssertionException $actualException */ |
66
|
|
|
$actualException = FailedRDMAssertionException::expectedDifferentService( |
67
|
|
|
"some_service", |
68
|
|
|
$reflectionClass, |
69
|
|
|
$serviceA, |
70
|
|
|
$serviceB |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$this->assertEquals( |
74
|
|
|
sprintf( |
75
|
|
|
"Expected service 'some_service' (%s#%s) on entity %s, was %s#%s instead!", |
76
|
|
|
ServiceExample::class, |
77
|
|
|
spl_object_hash($serviceA), |
78
|
|
|
EntityExample::class, |
79
|
|
|
ServiceExample::class, |
80
|
|
|
spl_object_hash($serviceB) |
81
|
|
|
), |
82
|
|
|
$actualException->getMessage() |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @test |
88
|
|
|
*/ |
89
|
|
|
public function shouldCreateExpectedInstanceOfException() |
90
|
|
|
{ |
91
|
|
|
/** @var FailedRDMAssertionException $actualException */ |
92
|
|
|
$actualException = FailedRDMAssertionException::expectedInstanceOf( |
93
|
|
|
ValueObjectExample::class, |
94
|
|
|
EntityExample::class, |
95
|
|
|
"some origin" |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$this->assertEquals( |
99
|
|
|
sprintf( |
100
|
|
|
"Expected instance of %s instead of %s as specified in some origin!", |
101
|
|
|
ValueObjectExample::class, |
102
|
|
|
EntityExample::class |
103
|
|
|
), |
104
|
|
|
$actualException->getMessage() |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @test |
110
|
|
|
*/ |
111
|
|
|
public function shouldCreateExpectedArrayException() |
112
|
|
|
{ |
113
|
|
|
/** @var FailedRDMAssertionException $actualException */ |
114
|
|
|
$actualException = FailedRDMAssertionException::expectedArray( |
115
|
|
|
ValueObjectExample::class, |
116
|
|
|
"some origin" |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$this->assertEquals( |
120
|
|
|
sprintf( |
121
|
|
|
"Expected array, got string as specified in some origin!", |
122
|
|
|
ValueObjectExample::class |
123
|
|
|
), |
124
|
|
|
$actualException->getMessage() |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
|