Skip to content

Commit 152d43c

Browse files
committed
Close #181
and fix a few code style issues found by newer versions of dev tools.
1 parent c2a41bb commit 152d43c

File tree

9 files changed

+61
-21
lines changed

9 files changed

+61
-21
lines changed

src/Exceptions/ErrorCollection.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,31 @@ public function addDataIdError(
199199
return $this->addResourceError($title, $pointer, $detail, $status, $idx, $aboutLink, $code, $meta);
200200
}
201201

202+
/**
203+
* @param string $title
204+
* @param string|null $detail
205+
* @param int|string|null $status
206+
* @param int|string|null $idx
207+
* @param LinkInterface|null $aboutLink
208+
* @param int|string|null $code
209+
* @param mixed|null $meta
210+
*
211+
* @return $this
212+
*/
213+
public function addAttributesError(
214+
$title,
215+
$detail = null,
216+
$status = null,
217+
$idx = null,
218+
LinkInterface $aboutLink = null,
219+
$code = null,
220+
$meta = null
221+
) {
222+
$pointer = $this->getPathToAttributes();
223+
224+
return $this->addResourceError($title, $pointer, $detail, $status, $idx, $aboutLink, $code, $meta);
225+
}
226+
202227
/**
203228
* @param string $name
204229
* @param string $title
@@ -416,6 +441,14 @@ protected function getPathToId()
416441
return $this->getPathToData() . '/' . DocumentInterface::KEYWORD_ID;
417442
}
418443

444+
/**
445+
* @return string
446+
*/
447+
protected function getPathToAttributes()
448+
{
449+
return $this->getPathToData() . '/' . DocumentInterface::KEYWORD_ATTRIBUTES;
450+
}
451+
419452
/**
420453
* @param string $name
421454
*

tests/Document/DocumentTest.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,37 +1264,26 @@ private function getSchema(
12641264
$relPrimaryMeta = null,
12651265
$relIncMeta = null
12661266
) {
1267+
/** @var Mockery\Mock $schema */
12671268
$schema = Mockery::mock(SchemaProviderinterface::class);
12681269

1269-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12701270
$schema->shouldReceive('getResourceType')->zeroOrMoreTimes()->andReturn($type);
1271-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12721271
$schema->shouldReceive('getId')->zeroOrMoreTimes()->andReturn($idx);
1273-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12741272
$schema->shouldReceive('getSelfSubLink')->zeroOrMoreTimes()->andReturn($selfLink);
1275-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12761273
$schema->shouldReceive('getAttributes')->zeroOrMoreTimes()->andReturn($attributes);
1277-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12781274
$schema->shouldReceive('getResourceLinks')->zeroOrMoreTimes()->andReturn($resourceLinks);
1279-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12801275
$schema->shouldReceive('getIncludedResourceLinks')->zeroOrMoreTimes()->andReturn($includedResLinks);
1281-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12821276
$schema->shouldReceive('isShowAttributesInIncluded')->zeroOrMoreTimes()->andReturn($showAttributesInIncluded);
1283-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12841277
$schema->shouldReceive('isShowRelationshipsInIncluded')->zeroOrMoreTimes()->andReturn($relShipsInIncluded);
1285-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12861278
$schema->shouldReceive('getIncludePaths')->zeroOrMoreTimes()->andReturn($includePaths);
1287-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12881279
$schema->shouldReceive('getPrimaryMeta')->zeroOrMoreTimes()->andReturn($primaryMeta);
1289-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12901280
$schema->shouldReceive('getLinkageMeta')->zeroOrMoreTimes()->andReturn($relationshipMeta);
1291-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12921281
$schema->shouldReceive('getInclusionMeta')->zeroOrMoreTimes()->andReturn($inclusionMeta);
1293-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12941282
$schema->shouldReceive('getRelationshipsPrimaryMeta')->zeroOrMoreTimes()->andReturn($relPrimaryMeta);
1295-
/** @noinspection PhpMethodParametersCountMismatchInspection */
12961283
$schema->shouldReceive('getRelationshipsInclusionMeta')->zeroOrMoreTimes()->andReturn($relIncMeta);
12971284

1285+
/** @var SchemaProviderInterface $schema */
1286+
12981287
return $schema;
12991288
}
13001289
}

tests/Encoder/EncoderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function testEncodeInvalidData()
6060
Author::class => AuthorSchema::class
6161
], $this->encoderOptions);
6262

63+
/** @noinspection PhpParamsInspection */
6364
$encoder->encodeData('input must be an object or array of objects or iterator over objects');
6465
}
6566

tests/Exceptions/ErrorCollectionTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
use \Mockery;
2019
use \Neomerx\JsonApi\Document\Error;
2120
use \Neomerx\Tests\JsonApi\BaseTestCase;
2221
use \Neomerx\JsonApi\Exceptions\ErrorCollection;
@@ -130,6 +129,18 @@ public function testAddDataIdError()
130129
], $this->collection[0]->getSource());
131130
}
132131

132+
/**
133+
* Test adding error.
134+
*/
135+
public function testAddAttributesError()
136+
{
137+
$this->collection->addAttributesError('some title');
138+
$this->assertNotEmpty($this->collection);
139+
$this->assertEquals([
140+
Error::SOURCE_POINTER => self::ATTR_PATH
141+
], $this->collection[0]->getSource());
142+
}
143+
133144
/**
134145
* Test adding error.
135146
*/

tests/Exceptions/JsonApiExceptionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
use \Mockery;
2019
use \Neomerx\JsonApi\Document\Error;
2120
use \Neomerx\Tests\JsonApi\BaseTestCase;
2221
use \Neomerx\JsonApi\Exceptions\ErrorCollection;

tests/Extensions/Issue154/CustomEncoder.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class CustomEncoder extends Encoder implements CustomEncoderInterface
3333
*/
3434
public static function instance(array $schemas = [], EncoderOptions $encodeOptions = null)
3535
{
36-
return parent::instance($schemas, $encodeOptions);
36+
/** @var CustomEncoderInterface $encoder */
37+
$encoder = parent::instance($schemas, $encodeOptions);
38+
39+
return $encoder;
3740
}
3841

3942
/**
@@ -59,6 +62,9 @@ protected static function createFactory()
5962
*/
6063
protected function getContainer()
6164
{
62-
return parent::getContainer();
65+
/** @var CustomContainerInterface $container */
66+
$container = parent::getContainer();
67+
68+
return $container;
6369
}
6470
}

tests/Extensions/Issue169/CustomEncoder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ class CustomEncoder extends Encoder
3636
*/
3737
public static function instance(array $schemas = [], EncoderOptions $encodeOptions = null)
3838
{
39-
return parent::instance($schemas, $encodeOptions);
39+
/** @var CustomEncoder $encoder */
40+
$encoder = parent::instance($schemas, $encodeOptions);
41+
42+
return $encoder;
4043
}
4144

4245
/**

tests/Extensions/Issue91/IssueTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
use \Mockery;
2019
use \Neomerx\JsonApi\Encoder\Encoder;
2120
use \Neomerx\Tests\JsonApi\BaseTestCase;
2221

tests/Http/Query/EncodingParametersTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
use \Mockery;
2019
use \Neomerx\Tests\JsonApi\BaseTestCase;
2120
use \Neomerx\JsonApi\Encoder\Parameters\EncodingParameters;
2221

0 commit comments

Comments
 (0)