|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2018 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\Exception; |
|
12
|
|
|
|
|
13
|
|
|
use ErrorException; |
|
14
|
|
|
use ReflectionClass; |
|
15
|
|
|
use Addiks\RDMBundle\Exception\FailedRDMAssertionExceptionInterface; |
|
16
|
|
|
|
|
17
|
|
|
final class FailedRDMAssertionException extends ErrorException implements FailedRDMAssertionExceptionInterface |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $type; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var array<mixed> |
|
27
|
|
|
*/ |
|
28
|
|
|
private $parameters; |
|
29
|
|
|
|
|
30
|
2 |
|
public function __construct(string $message, string $type, array $parameters) |
|
31
|
|
|
{ |
|
32
|
2 |
|
parent::__construct($message); |
|
33
|
|
|
|
|
34
|
2 |
|
$this->type = $type; |
|
35
|
2 |
|
$this->parameters = $parameters; |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getType(): string |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->type; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getParameters(): array |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->parameters; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param mixed $expectedService |
|
50
|
|
|
* @param mixed $actualService |
|
51
|
|
|
*/ |
|
52
|
2 |
|
public static function expectedDifferentService( |
|
53
|
|
|
string $serviceId, |
|
54
|
|
|
ReflectionClass $classReflection, |
|
55
|
|
|
$expectedService, |
|
56
|
|
|
$actualService |
|
57
|
|
|
): FailedRDMAssertionException { |
|
58
|
|
|
/** @var string $actualDescription */ |
|
59
|
2 |
|
$actualDescription = null; |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
2 |
View Code Duplication |
if (is_object($actualService)) { |
|
|
|
|
|
|
62
|
1 |
|
$actualDescription = get_class($actualService) . '#' . spl_object_hash($actualService); |
|
63
|
|
|
|
|
64
|
|
|
} else { |
|
65
|
1 |
|
$actualDescription = gettype($actualService); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** @var string $expectedDescription */ |
|
69
|
2 |
|
$expectedDescription = null; |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
2 |
View Code Duplication |
if (is_object($expectedService)) { |
|
|
|
|
|
|
72
|
2 |
|
$expectedDescription = get_class($expectedService) . '#' . spl_object_hash($expectedService); |
|
73
|
|
|
|
|
74
|
|
|
} else { |
|
75
|
|
|
$expectedDescription = gettype($expectedService); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
2 |
|
return new self( |
|
79
|
2 |
|
sprintf( |
|
80
|
2 |
|
"Expected service %s (%s) on entity %s, was %s instead!", |
|
81
|
2 |
|
$serviceId, |
|
82
|
2 |
|
$expectedDescription, |
|
83
|
2 |
|
$classReflection->getName(), |
|
|
|
|
|
|
84
|
2 |
|
$actualDescription |
|
85
|
|
|
), |
|
86
|
2 |
|
"EXPECTED_DIFFERENT_SERVICE", |
|
87
|
2 |
|
[$serviceId, $expectedService, $actualService] |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|