33namespace Swaggest \JsonDiff \Tests ;
44
55use Swaggest \JsonDiff \Exception ;
6+ use Swaggest \JsonDiff \InvalidFieldTypeException ;
67use Swaggest \JsonDiff \JsonDiff ;
78use Swaggest \JsonDiff \JsonPatch ;
89use Swaggest \JsonDiff \JsonPatch \OpPath ;
@@ -114,17 +115,21 @@ public function testInvalidOp()
114115 * @dataProvider provideInvalidFieldType
115116 *
116117 * @param object $operation
117- * @param string $expectedException
118118 * @param string $expectedMessage
119+ * @param string $expectedField
120+ * @param string $expectedType
119121 */
120- public function testInvalidFieldType ($ operation , $ expectedException , $ expectedMessage )
122+ public function testInvalidFieldType ($ operation , $ expectedMessage , $ expectedField , $ expectedType )
121123 {
122124 try {
123125 JsonPatch::import (array ($ operation ));
124126 $ this ->fail ('Expected exception was not thrown ' );
125127 } catch (Exception $ exception ) {
126- $ this ->assertInstanceOf ($ expectedException , $ exception );
128+ $ this ->assertInstanceOf (InvalidFieldTypeException::class , $ exception );
127129 $ this ->assertSame ($ expectedMessage , $ exception ->getMessage ());
130+ $ this ->assertSame ($ expectedField , $ exception ->getField ());
131+ $ this ->assertSame ($ expectedType , $ exception ->getExpectedType ());
132+ $ this ->assertSame ($ operation , $ exception ->getOperation ());
128133 }
129134 }
130135
@@ -133,18 +138,21 @@ public function provideInvalidFieldType()
133138 return [
134139 '"op" invalid type ' => [
135140 (object )array ('op ' => array ('foo ' => 'bar ' ), 'path ' => '/123 ' , 'value ' => 'test ' ),
136- Exception::class,
137- 'Invalid field type - "op" should be of type: string '
141+ 'Invalid field type - "op" should be of type: string ' ,
142+ 'op ' ,
143+ 'string '
138144 ],
139145 '"path" invalid type ' => [
140146 (object )array ('op ' => 'add ' , 'path ' => array ('foo ' => 'bar ' ), 'value ' => 'test ' ),
141- Exception::class,
142- 'Invalid field type - "path" should be of type: string '
147+ 'Invalid field type - "path" should be of type: string ' ,
148+ 'path ' ,
149+ 'string '
143150 ],
144151 '"from" invalid type ' => [
145152 (object )array ('op ' => 'move ' , 'path ' => '/123 ' , 'from ' => array ('foo ' => 'bar ' )),
146- Exception::class,
147- 'Invalid field type - "from" should be of type: string '
153+ 'Invalid field type - "from" should be of type: string ' ,
154+ 'from ' ,
155+ 'string '
148156 ]
149157 ];
150158 }
0 commit comments