44
55use  PHPUnit \Framework \Constraint \Constraint ;
66use  PHPUnit \Framework \Constraint \IsEqual ;
7+ use  SebastianBergmann \Exporter \Exporter ;
78use  Symfony \Component \DependencyInjection \Definition ;
89use  Symfony \Component \DependencyInjection \Exception \OutOfBoundsException ;
910
@@ -12,9 +13,10 @@ final class DefinitionHasArgumentConstraint extends Constraint
1213    /** 
1314     * @var int|string 
1415     */ 
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 ;
1820
1921    public  function  __construct ($ argumentIndex , $ expectedValue , bool  $ checkExpectedValue  = true )
2022    {
@@ -37,6 +39,7 @@ public function __construct($argumentIndex, $expectedValue, bool $checkExpectedV
3739        $ this  ->argumentIndex  = $ argumentIndex ;
3840        $ this  ->expectedValue  = $ expectedValue ;
3941        $ this  ->checkExpectedValue  = $ checkExpectedValue ;
42+         $ this  ->exporter  = new  Exporter ();
4043    }
4144
4245    public  function  toString (): string 
@@ -98,6 +101,18 @@ private function evaluateArgumentValue(Definition $definition, bool $returnResul
98101    {
99102        $ actualValue  = $ definition ->getArgument ($ this  ->argumentIndex );
100103
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+ 
101116        $ constraint  = new  IsEqual ($ this  ->expectedValue );
102117
103118        if  (!$ constraint ->evaluate ($ actualValue , '' , true )) {
@@ -109,15 +124,15 @@ private function evaluateArgumentValue(Definition $definition, bool $returnResul
109124                $ message  = sprintf (
110125                    'The value of argument named "%s" (%s) is not equal to the expected value (%s) ' ,
111126                    $ this  ->argumentIndex ,
112-                     $ this  ->exporter () ->export ($ actualValue ),
113-                     $ this  ->exporter () ->export ($ this  ->expectedValue )
127+                     $ this  ->exporter ->export ($ actualValue ),
128+                     $ this  ->exporter ->export ($ this  ->expectedValue )
114129                );
115130            } else  {
116131                $ message  = sprintf (
117132                    'The value of argument with index %d (%s) is not equal to the expected value (%s) ' ,
118133                    $ this  ->argumentIndex ,
119-                     $ this  ->exporter () ->export ($ actualValue ),
120-                     $ this  ->exporter () ->export ($ this  ->expectedValue )
134+                     $ this  ->exporter ->export ($ actualValue ),
135+                     $ this  ->exporter ->export ($ this  ->expectedValue )
121136                );
122137            }
123138
0 commit comments