Skip to content

Commit 4aa6fd3

Browse files
Correct misconfigured mocks in JsonSchema\Tests\Uri\UriRetrieverTest (#741)
* test: Correct misconfigured mocks * test: Refactor to use willReturn() method * test: Make use of already imported classname * test: Ignore return value when exception is expected to be thrown * test: Mock complete interface * docs: Add changelog entry
1 parent a38c619 commit 4aa6fd3

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Fixed
10+
- Correct misconfigured mocks in JsonSchema\Tests\Uri\UriRetrieverTest ([#741](https://github.com/jsonrainbow/json-schema/pull/741))
911

1012
## [6.0.0] - 2024-07-30
1113
### Added

tests/Uri/UriRetrieverTest.php

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private function getRetrieverMock($returnSchema)
3939
$retriever->expects($this->at(0))
4040
->method('retrieve')
4141
->with($this->equalTo(null), $this->equalTo('http://some.host.at/somewhere/parent'))
42-
->will($this->returnValue($jsonSchema));
42+
->willReturn($jsonSchema);
4343

4444
return $retriever;
4545
}
@@ -153,7 +153,7 @@ public function testResolvePointerNoFragment()
153153
'title' => 'schema'
154154
);
155155

156-
$retriever = new \JsonSchema\Uri\UriRetriever();
156+
$retriever = new UriRetriever();
157157
$this->assertEquals(
158158
$schema,
159159
$retriever->resolvePointer(
@@ -173,7 +173,7 @@ public function testResolvePointerFragment()
173173
'title' => 'schema'
174174
);
175175

176-
$retriever = new \JsonSchema\Uri\UriRetriever();
176+
$retriever = new UriRetriever();
177177
$this->assertEquals(
178178
$schema->definitions->foo,
179179
$retriever->resolvePointer(
@@ -196,7 +196,7 @@ public function testResolvePointerFragmentNotFound()
196196
'title' => 'schema'
197197
);
198198

199-
$retriever = new \JsonSchema\Uri\UriRetriever();
199+
$retriever = new UriRetriever();
200200
$retriever->resolvePointer(
201201
$schema, 'http://example.org/schema.json#/definitions/bar'
202202
);
@@ -216,7 +216,7 @@ public function testResolvePointerFragmentNoArray()
216216
'title' => 'schema'
217217
);
218218

219-
$retriever = new \JsonSchema\Uri\UriRetriever();
219+
$retriever = new UriRetriever();
220220
$retriever->resolvePointer(
221221
$schema, 'http://example.org/schema.json#/definitions/foo'
222222
);
@@ -227,46 +227,49 @@ public function testResolvePointerFragmentNoArray()
227227
*/
228228
public function testResolveExcessLevelUp()
229229
{
230-
$retriever = new \JsonSchema\Uri\UriRetriever();
230+
$retriever = new UriRetriever();
231231
$retriever->resolve(
232232
'../schema.json#', 'http://example.org/schema.json#'
233233
);
234234
}
235235

236236
public function testConfirmMediaTypeAcceptsJsonSchemaType()
237237
{
238-
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
238+
$uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
239+
$retriever = new UriRetriever();
239240

240-
$retriever->expects($this->at(0))
241+
$uriRetriever->expects($this->at(0))
241242
->method('getContentType')
242-
->will($this->returnValue('application/schema+json'));
243+
->willReturn('application/schema+json');
243244

244-
$this->assertEquals(null, $retriever->confirmMediaType($retriever, null));
245+
$this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null));
245246
}
246247

247248
public function testConfirmMediaTypeAcceptsJsonType()
248249
{
249-
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
250+
$uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
251+
$retriever = new UriRetriever();
250252

251-
$retriever->expects($this->at(0))
253+
$uriRetriever->expects($this->at(0))
252254
->method('getContentType')
253-
->will($this->returnValue('application/json'));
255+
->willReturn('application/json');
254256

255-
$this->assertEquals(null, $retriever->confirmMediaType($retriever, null));
257+
$this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null));
256258
}
257259

258260
/**
259261
* @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException
260262
*/
261263
public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes()
262264
{
263-
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
265+
$uriRetriever = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
266+
$retriever = new UriRetriever();
264267

265-
$retriever->expects($this->at(0))
268+
$uriRetriever->expects($this->at(0))
266269
->method('getContentType')
267-
->will($this->returnValue('text/html'));
270+
->willReturn('text/html');
268271

269-
$this->assertEquals(null, $retriever->confirmMediaType($retriever, null));
272+
$this->assertEquals(null, $retriever->confirmMediaType($uriRetriever, null));
270273
}
271274

272275
private function mockRetriever($schema)
@@ -332,7 +335,7 @@ public function testRetrieveSchemaFromPackage()
332335

333336
public function testInvalidContentTypeEndpointsDefault()
334337
{
335-
$mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
338+
$mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
336339
$mock->method('getContentType')->willReturn('Application/X-Fake-Type');
337340
$retriever = new UriRetriever();
338341

@@ -345,7 +348,7 @@ public function testInvalidContentTypeEndpointsDefault()
345348
*/
346349
public function testInvalidContentTypeEndpointsUnknown()
347350
{
348-
$mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
351+
$mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
349352
$mock->method('getContentType')->willReturn('Application/X-Fake-Type');
350353
$retriever = new UriRetriever();
351354

@@ -354,7 +357,7 @@ public function testInvalidContentTypeEndpointsUnknown()
354357

355358
public function testInvalidContentTypeEndpointsAdded()
356359
{
357-
$mock = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
360+
$mock = $this->getMock('JsonSchema\Uri\Retrievers\UriRetrieverInterface');
358361
$mock->method('getContentType')->willReturn('Application/X-Fake-Type');
359362
$retriever = new UriRetriever();
360363
$retriever->addInvalidContentTypeEndpoint('http://example.com');
@@ -389,7 +392,7 @@ public function testLoadSchemaJSONDecodingException()
389392
'JsonSchema\Exception\JsonDecodingException',
390393
'JSON syntax is malformed'
391394
);
392-
$schema = $retriever->retrieve('package://tests/fixtures/bad-syntax.json');
395+
$retriever->retrieve('package://tests/fixtures/bad-syntax.json');
393396
}
394397

395398
public function testGenerateURI()

0 commit comments

Comments
 (0)