3
3
namespace Swaggest \JsonDiff \Tests ;
4
4
5
5
use Swaggest \JsonDiff \Exception ;
6
+ use Swaggest \JsonDiff \InvalidFieldTypeException ;
6
7
use Swaggest \JsonDiff \JsonDiff ;
7
8
use Swaggest \JsonDiff \JsonPatch ;
8
9
use Swaggest \JsonDiff \JsonPatch \OpPath ;
@@ -114,17 +115,21 @@ public function testInvalidOp()
114
115
* @dataProvider provideInvalidFieldType
115
116
*
116
117
* @param object $operation
117
- * @param string $expectedException
118
118
* @param string $expectedMessage
119
+ * @param string $expectedField
120
+ * @param string $expectedType
119
121
*/
120
- public function testInvalidFieldType ($ operation , $ expectedException , $ expectedMessage )
122
+ public function testInvalidFieldType ($ operation , $ expectedMessage , $ expectedField , $ expectedType )
121
123
{
122
124
try {
123
125
JsonPatch::import (array ($ operation ));
124
126
$ this ->fail ('Expected exception was not thrown ' );
125
127
} catch (Exception $ exception ) {
126
- $ this ->assertInstanceOf ($ expectedException , $ exception );
128
+ $ this ->assertInstanceOf (InvalidFieldTypeException::class , $ exception );
127
129
$ this ->assertSame ($ expectedMessage , $ exception ->getMessage ());
130
+ $ this ->assertSame ($ expectedField , $ exception ->getField ());
131
+ $ this ->assertSame ($ expectedType , $ exception ->getExpectedType ());
132
+ $ this ->assertSame ($ operation , $ exception ->getOperation ());
128
133
}
129
134
}
130
135
@@ -133,18 +138,21 @@ public function provideInvalidFieldType()
133
138
return [
134
139
'"op" invalid type ' => [
135
140
(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 '
138
144
],
139
145
'"path" invalid type ' => [
140
146
(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 '
143
150
],
144
151
'"from" invalid type ' => [
145
152
(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 '
148
156
]
149
157
];
150
158
}
0 commit comments