Skip to content

Commit e6eac18

Browse files
committed
refactor: Replace setExpectedException with expectException/expectExceptionMessage
1 parent 1c4f517 commit e6eac18

12 files changed

+32
-45
lines changed

tests/ConstraintErrorTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ public function testGetInvalidMessage()
2424
{
2525
$e = ConstraintError::MISSING_ERROR();
2626

27-
$this->setExpectedException(
28-
'\JsonSchema\Exception\InvalidArgumentException',
29-
'Missing error message for missingError'
30-
);
27+
$this->expectException('\JsonSchema\Exception\InvalidArgumentException');
28+
$this->expectExceptionMessage('Missing error message for missingError');
29+
3130
$e->getMessage();
3231
}
3332
}

tests/Constraints/FactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function constraintNameProvider()
8585
*/
8686
public function testExceptionWhenCreateInstanceForInvalidConstraintName($constraintName)
8787
{
88-
$this->setExpectedException('JsonSchema\Exception\InvalidArgumentException');
88+
$this->expectException('JsonSchema\Exception\InvalidArgumentException');
8989
$this->factory->createInstanceFor($constraintName);
9090
}
9191

tests/Constraints/SchemaValidationTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,16 @@ public function testValidCases($schema)
102102

103103
public function testNonObjectSchema()
104104
{
105-
$this->setExpectedException(
106-
'\JsonSchema\Exception\RuntimeException',
107-
'Cannot validate the schema of a non-object'
108-
);
105+
$this->expectException('\JsonSchema\Exception\RuntimeException');
106+
$this->expectExceptionMessage('Cannot validate the schema of a non-object');
107+
109108
$this->testValidCases('"notAnObject"');
110109
}
111110

112111
public function testInvalidSchemaException()
113112
{
114-
$this->setExpectedException(
115-
'\JsonSchema\Exception\InvalidSchemaException',
116-
'Schema did not pass validation'
117-
);
113+
$this->expectException('\JsonSchema\Exception\InvalidSchemaException');
114+
$this->expectExceptionMessage('Schema did not pass validation');
118115

119116
$input = json_decode('{}');
120117
$schema = json_decode('{"properties":{"propertyOne":{"type":"string","required":true}}}');

tests/Constraints/SelfDefinedSchemaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testInvalidArgumentException()
7474

7575
$v = new Validator();
7676

77-
$this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException');
77+
$this->expectException('\JsonSchema\Exception\InvalidArgumentException');
7878

7979
$v->validate($value, $schema);
8080
}

tests/Constraints/TypeTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ public function testInvalidateTypeNameWording()
125125
$m = $r->getMethod('validateTypeNameWording');
126126
$m->setAccessible(true);
127127

128-
$this->setExpectedException(
129-
'\UnexpectedValueException',
130-
"No wording for 'notAValidTypeName' available, expected wordings are: [an integer, a number, a boolean, an object, an array, a string, a null]"
131-
);
128+
$this->expectException('\UnexpectedValueException');
129+
$this->expectExceptionMessage("No wording for 'notAValidTypeName' available, expected wordings are: [an integer, a number, a boolean, an object, an array, a string, a null]");
130+
132131
$m->invoke($t, 'notAValidTypeName');
133132
}
134133

@@ -138,10 +137,9 @@ public function testValidateTypeException()
138137
$data = new \stdClass();
139138
$schema = json_decode('{"type": "notAValidTypeName"}');
140139

141-
$this->setExpectedException(
142-
'JsonSchema\Exception\InvalidArgumentException',
143-
'object is an invalid type for notAValidTypeName'
144-
);
140+
$this->expectException('JsonSchema\Exception\InvalidArgumentException');
141+
$this->expectExceptionMessage('object is an invalid type for notAValidTypeName');
142+
145143
$t->check($data, $schema);
146144
}
147145
}

tests/Constraints/ValidationExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testValidationException()
4545
$exception->getMessage()
4646
);
4747

48-
$this->setExpectedException('JsonSchema\Exception\ValidationException');
48+
$this->expectException('JsonSchema\Exception\ValidationException');
4949
throw $exception;
5050
}
5151
}

tests/Entity/JsonPointerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ public function testJsonPointerWithPropertyPaths()
113113

114114
public function testCreateWithInvalidValue()
115115
{
116-
$this->setExpectedException(
117-
'\JsonSchema\Exception\InvalidArgumentException',
118-
'Ref value must be a string'
119-
);
116+
$this->expectException('\JsonSchema\Exception\InvalidArgumentException');
117+
$this->expectExceptionMessage('Ref value must be a string');
118+
120119
new JsonPointer(null);
121120
}
122121
}

tests/RefTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testRefIgnoresSiblings($schema, $document, $isValid, $exception
6969

7070
$v = new Validator();
7171
if ($exception) {
72-
$this->setExpectedException($exception);
72+
$this->expectException($exception);
7373
}
7474

7575
$v->validate($document, $schema);

tests/SchemaStorageTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,8 @@ public function testSchemaWithLocalAndExternalReferencesWithCircularReference()
102102

103103
public function testUnresolvableJsonPointExceptionShouldBeThrown()
104104
{
105-
$this->setExpectedException(
106-
'JsonSchema\Exception\UnresolvableJsonPointerException',
107-
'File: http://www.example.com/schema.json is found, but could not resolve fragment: #/definitions/car'
108-
);
105+
$this->expectException('JsonSchema\Exception\UnresolvableJsonPointerException');
106+
$this->expectExceptionMessage('File: http://www.example.com/schema.json is found, but could not resolve fragment: #/definitions/car');
109107

110108
$mainSchema = $this->getInvalidSchema();
111109
$mainSchemaPath = 'http://www.example.com/schema.json';
@@ -121,10 +119,8 @@ public function testUnresolvableJsonPointExceptionShouldBeThrown()
121119

122120
public function testResolveRefWithNoAssociatedFileName()
123121
{
124-
$this->setExpectedException(
125-
'JsonSchema\Exception\UnresolvableJsonPointerException',
126-
"Could not resolve fragment '#': no file is defined"
127-
);
122+
$this->expectException('JsonSchema\Exception\UnresolvableJsonPointerException');
123+
$this->expectExceptionMessage("Could not resolve fragment '#': no file is defined");
128124

129125
$schemaStorage = new SchemaStorage();
130126
$schemaStorage->resolveRef('#');

tests/Uri/Retrievers/CurlTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ public function testRetrieveNonexistantFile()
1717
{
1818
$c = new Curl();
1919

20-
$this->setExpectedException(
21-
'\JsonSchema\Exception\ResourceNotFoundException',
22-
'JSON schema not found'
23-
);
20+
$this->expectException('\JsonSchema\Exception\ResourceNotFoundException');
21+
$this->expectExceptionMessage('JSON schema not found');
22+
2423
$c->retrieve(__DIR__ . '/notARealFile');
2524
}
2625

tests/Uri/UriRetrieverTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,9 @@ public function testLoadSchemaJSONDecodingException()
388388
{
389389
$retriever = new UriRetriever();
390390

391-
$this->setExpectedException(
392-
'JsonSchema\Exception\JsonDecodingException',
393-
'JSON syntax is malformed'
394-
);
391+
$this->expectException('JsonSchema\Exception\JsonDecodingException');
392+
$this->expectExceptionMessage('JSON syntax is malformed');
393+
395394
$retriever->retrieve('package://tests/fixtures/bad-syntax.json');
396395
}
397396

tests/ValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testBadAssocSchemaInput()
3131

3232
$validator = new Validator();
3333

34-
$this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException');
34+
$this->expectException('\JsonSchema\Exception\InvalidArgumentException');
3535
$validator->validate($data, $schema);
3636
}
3737

0 commit comments

Comments
 (0)