Skip to content

Commit e618e58

Browse files
committed
Improve JsonPatch::import exception tests
1 parent 8900b8e commit e618e58

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

tests/src/JsonPatchTest.php

+20-5
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,16 @@ public function testNull()
7777

7878
public function testMissingOp()
7979
{
80-
$this->setExpectedException(MissingFieldException::class, 'Missing "op" in operation data');
81-
JsonPatch::import(array((object)array('path' => '/123')));
80+
$operation = (object)array('path' => '/123');
81+
try {
82+
JsonPatch::import(array($operation));
83+
$this->fail('Expected exception was not thrown');
84+
} catch (Exception $exception) {
85+
$this->assertInstanceOf(MissingFieldException::class, $exception);
86+
$this->assertSame('Missing "op" in operation data', $exception->getMessage());
87+
$this->assertSame('op', $exception->getMissingField());
88+
$this->assertSame($operation, $exception->getOperation());
89+
}
8290
}
8391

8492
public function testMissingPath()
@@ -89,8 +97,15 @@ public function testMissingPath()
8997

9098
public function testInvalidOp()
9199
{
92-
$this->setExpectedException(UnknownOperationException::class, 'Unknown "op": wat');
93-
JsonPatch::import(array((object)array('op' => 'wat', 'path' => '/123')));
100+
$operation = (object)array('op' => 'wat', 'path' => '/123');
101+
try {
102+
JsonPatch::import(array($operation));
103+
$this->fail('Expected exception was not thrown');
104+
} catch (Exception $exception) {
105+
$this->assertInstanceOf(UnknownOperationException::class, $exception);
106+
$this->assertSame('Unknown "op": wat', $exception->getMessage());
107+
$this->assertSame($operation, $exception->getOperation());
108+
}
94109
}
95110

96111
public function testMissingFrom()
@@ -154,4 +169,4 @@ public function testTestOperationFailed()
154169
$this->assertInstanceOf(PatchTestOperationFailedException::class, $errors[0]);
155170
}
156171

157-
}
172+
}

0 commit comments

Comments
 (0)