4
4
5
5
use PHPUnit \Framework \Constraint \Constraint ;
6
6
use PHPUnit \Framework \Constraint \IsEqual ;
7
+ use SebastianBergmann \Exporter \Exporter ;
7
8
use Symfony \Component \DependencyInjection \Definition ;
8
9
use Symfony \Component \DependencyInjection \Exception \OutOfBoundsException ;
9
10
@@ -12,9 +13,10 @@ final class DefinitionHasArgumentConstraint extends Constraint
12
13
/**
13
14
* @var int|string
14
15
*/
15
- private $ argumentIndex ;
16
- private $ expectedValue ;
17
- private $ checkExpectedValue ;
16
+ private string |int $ argumentIndex ;
17
+ private mixed $ expectedValue ;
18
+ private bool $ checkExpectedValue ;
19
+ private Exporter $ exporter ;
18
20
19
21
public function __construct ($ argumentIndex , $ expectedValue , bool $ checkExpectedValue = true )
20
22
{
@@ -37,6 +39,7 @@ public function __construct($argumentIndex, $expectedValue, bool $checkExpectedV
37
39
$ this ->argumentIndex = $ argumentIndex ;
38
40
$ this ->expectedValue = $ expectedValue ;
39
41
$ this ->checkExpectedValue = $ checkExpectedValue ;
42
+ $ this ->exporter = new Exporter ();
40
43
}
41
44
42
45
public function toString (): string
@@ -98,6 +101,18 @@ private function evaluateArgumentValue(Definition $definition, bool $returnResul
98
101
{
99
102
$ actualValue = $ definition ->getArgument ($ this ->argumentIndex );
100
103
104
+ if (gettype ($ actualValue ) !== gettype ($ this ->expectedValue )) {
105
+ $ this ->fail (
106
+ $ definition ,
107
+ sprintf (
108
+ 'The value of argument named "%s" (%s) is not equal to the expected value (%s) ' ,
109
+ $ this ->argumentIndex ,
110
+ $ this ->exporter ->export ($ actualValue ),
111
+ $ this ->exporter ->export ($ this ->expectedValue )
112
+ )
113
+ );
114
+ }
115
+
101
116
$ constraint = new IsEqual ($ this ->expectedValue );
102
117
103
118
if (!$ constraint ->evaluate ($ actualValue , '' , true )) {
@@ -109,15 +124,15 @@ private function evaluateArgumentValue(Definition $definition, bool $returnResul
109
124
$ message = sprintf (
110
125
'The value of argument named "%s" (%s) is not equal to the expected value (%s) ' ,
111
126
$ this ->argumentIndex ,
112
- $ this ->exporter () ->export ($ actualValue ),
113
- $ this ->exporter () ->export ($ this ->expectedValue )
127
+ $ this ->exporter ->export ($ actualValue ),
128
+ $ this ->exporter ->export ($ this ->expectedValue )
114
129
);
115
130
} else {
116
131
$ message = sprintf (
117
132
'The value of argument with index %d (%s) is not equal to the expected value (%s) ' ,
118
133
$ this ->argumentIndex ,
119
- $ this ->exporter () ->export ($ actualValue ),
120
- $ this ->exporter () ->export ($ this ->expectedValue )
134
+ $ this ->exporter ->export ($ actualValue ),
135
+ $ this ->exporter ->export ($ this ->expectedValue )
121
136
);
122
137
}
123
138
0 commit comments