From 152d43cb91543062977677bf955125a1f4e5dc4b Mon Sep 17 00:00:00 2001 From: EK Date: Sat, 29 Jul 2017 18:32:57 +0300 Subject: [PATCH] Close #181 and fix a few code style issues found by newer versions of dev tools. --- src/Exceptions/ErrorCollection.php | 33 +++++++++++++++++++++ tests/Document/DocumentTest.php | 17 ++--------- tests/Encoder/EncoderTest.php | 1 + tests/Exceptions/ErrorCollectionTest.php | 13 +++++++- tests/Exceptions/JsonApiExceptionTest.php | 1 - tests/Extensions/Issue154/CustomEncoder.php | 10 +++++-- tests/Extensions/Issue169/CustomEncoder.php | 5 +++- tests/Extensions/Issue91/IssueTest.php | 1 - tests/Http/Query/EncodingParametersTest.php | 1 - 9 files changed, 61 insertions(+), 21 deletions(-) diff --git a/src/Exceptions/ErrorCollection.php b/src/Exceptions/ErrorCollection.php index 80bf1f35..e204bb6a 100644 --- a/src/Exceptions/ErrorCollection.php +++ b/src/Exceptions/ErrorCollection.php @@ -199,6 +199,31 @@ public function addDataIdError( return $this->addResourceError($title, $pointer, $detail, $status, $idx, $aboutLink, $code, $meta); } + /** + * @param string $title + * @param string|null $detail + * @param int|string|null $status + * @param int|string|null $idx + * @param LinkInterface|null $aboutLink + * @param int|string|null $code + * @param mixed|null $meta + * + * @return $this + */ + public function addAttributesError( + $title, + $detail = null, + $status = null, + $idx = null, + LinkInterface $aboutLink = null, + $code = null, + $meta = null + ) { + $pointer = $this->getPathToAttributes(); + + return $this->addResourceError($title, $pointer, $detail, $status, $idx, $aboutLink, $code, $meta); + } + /** * @param string $name * @param string $title @@ -416,6 +441,14 @@ protected function getPathToId() return $this->getPathToData() . '/' . DocumentInterface::KEYWORD_ID; } + /** + * @return string + */ + protected function getPathToAttributes() + { + return $this->getPathToData() . '/' . DocumentInterface::KEYWORD_ATTRIBUTES; + } + /** * @param string $name * diff --git a/tests/Document/DocumentTest.php b/tests/Document/DocumentTest.php index 3d9f2928..58096080 100644 --- a/tests/Document/DocumentTest.php +++ b/tests/Document/DocumentTest.php @@ -1264,37 +1264,26 @@ private function getSchema( $relPrimaryMeta = null, $relIncMeta = null ) { + /** @var Mockery\Mock $schema */ $schema = Mockery::mock(SchemaProviderinterface::class); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getResourceType')->zeroOrMoreTimes()->andReturn($type); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getId')->zeroOrMoreTimes()->andReturn($idx); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getSelfSubLink')->zeroOrMoreTimes()->andReturn($selfLink); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getAttributes')->zeroOrMoreTimes()->andReturn($attributes); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getResourceLinks')->zeroOrMoreTimes()->andReturn($resourceLinks); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getIncludedResourceLinks')->zeroOrMoreTimes()->andReturn($includedResLinks); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('isShowAttributesInIncluded')->zeroOrMoreTimes()->andReturn($showAttributesInIncluded); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('isShowRelationshipsInIncluded')->zeroOrMoreTimes()->andReturn($relShipsInIncluded); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getIncludePaths')->zeroOrMoreTimes()->andReturn($includePaths); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getPrimaryMeta')->zeroOrMoreTimes()->andReturn($primaryMeta); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getLinkageMeta')->zeroOrMoreTimes()->andReturn($relationshipMeta); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getInclusionMeta')->zeroOrMoreTimes()->andReturn($inclusionMeta); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getRelationshipsPrimaryMeta')->zeroOrMoreTimes()->andReturn($relPrimaryMeta); - /** @noinspection PhpMethodParametersCountMismatchInspection */ $schema->shouldReceive('getRelationshipsInclusionMeta')->zeroOrMoreTimes()->andReturn($relIncMeta); + /** @var SchemaProviderInterface $schema */ + return $schema; } } diff --git a/tests/Encoder/EncoderTest.php b/tests/Encoder/EncoderTest.php index 063f5d07..291a8d3b 100644 --- a/tests/Encoder/EncoderTest.php +++ b/tests/Encoder/EncoderTest.php @@ -60,6 +60,7 @@ public function testEncodeInvalidData() Author::class => AuthorSchema::class ], $this->encoderOptions); + /** @noinspection PhpParamsInspection */ $encoder->encodeData('input must be an object or array of objects or iterator over objects'); } diff --git a/tests/Exceptions/ErrorCollectionTest.php b/tests/Exceptions/ErrorCollectionTest.php index 4b35f045..664a5014 100644 --- a/tests/Exceptions/ErrorCollectionTest.php +++ b/tests/Exceptions/ErrorCollectionTest.php @@ -16,7 +16,6 @@ * limitations under the License. */ -use \Mockery; use \Neomerx\JsonApi\Document\Error; use \Neomerx\Tests\JsonApi\BaseTestCase; use \Neomerx\JsonApi\Exceptions\ErrorCollection; @@ -130,6 +129,18 @@ public function testAddDataIdError() ], $this->collection[0]->getSource()); } + /** + * Test adding error. + */ + public function testAddAttributesError() + { + $this->collection->addAttributesError('some title'); + $this->assertNotEmpty($this->collection); + $this->assertEquals([ + Error::SOURCE_POINTER => self::ATTR_PATH + ], $this->collection[0]->getSource()); + } + /** * Test adding error. */ diff --git a/tests/Exceptions/JsonApiExceptionTest.php b/tests/Exceptions/JsonApiExceptionTest.php index 150e9138..2c72c0ed 100644 --- a/tests/Exceptions/JsonApiExceptionTest.php +++ b/tests/Exceptions/JsonApiExceptionTest.php @@ -16,7 +16,6 @@ * limitations under the License. */ -use \Mockery; use \Neomerx\JsonApi\Document\Error; use \Neomerx\Tests\JsonApi\BaseTestCase; use \Neomerx\JsonApi\Exceptions\ErrorCollection; diff --git a/tests/Extensions/Issue154/CustomEncoder.php b/tests/Extensions/Issue154/CustomEncoder.php index 13ef58e8..fc0c7082 100644 --- a/tests/Extensions/Issue154/CustomEncoder.php +++ b/tests/Extensions/Issue154/CustomEncoder.php @@ -33,7 +33,10 @@ class CustomEncoder extends Encoder implements CustomEncoderInterface */ public static function instance(array $schemas = [], EncoderOptions $encodeOptions = null) { - return parent::instance($schemas, $encodeOptions); + /** @var CustomEncoderInterface $encoder */ + $encoder = parent::instance($schemas, $encodeOptions); + + return $encoder; } /** @@ -59,6 +62,9 @@ protected static function createFactory() */ protected function getContainer() { - return parent::getContainer(); + /** @var CustomContainerInterface $container */ + $container = parent::getContainer(); + + return $container; } } diff --git a/tests/Extensions/Issue169/CustomEncoder.php b/tests/Extensions/Issue169/CustomEncoder.php index e20c1570..890f82a5 100644 --- a/tests/Extensions/Issue169/CustomEncoder.php +++ b/tests/Extensions/Issue169/CustomEncoder.php @@ -36,7 +36,10 @@ class CustomEncoder extends Encoder */ public static function instance(array $schemas = [], EncoderOptions $encodeOptions = null) { - return parent::instance($schemas, $encodeOptions); + /** @var CustomEncoder $encoder */ + $encoder = parent::instance($schemas, $encodeOptions); + + return $encoder; } /** diff --git a/tests/Extensions/Issue91/IssueTest.php b/tests/Extensions/Issue91/IssueTest.php index 1e5cefed..fc55dc9e 100644 --- a/tests/Extensions/Issue91/IssueTest.php +++ b/tests/Extensions/Issue91/IssueTest.php @@ -16,7 +16,6 @@ * limitations under the License. */ -use \Mockery; use \Neomerx\JsonApi\Encoder\Encoder; use \Neomerx\Tests\JsonApi\BaseTestCase; diff --git a/tests/Http/Query/EncodingParametersTest.php b/tests/Http/Query/EncodingParametersTest.php index 775e8f7d..bf41221a 100644 --- a/tests/Http/Query/EncodingParametersTest.php +++ b/tests/Http/Query/EncodingParametersTest.php @@ -16,7 +16,6 @@ * limitations under the License. */ -use \Mockery; use \Neomerx\Tests\JsonApi\BaseTestCase; use \Neomerx\JsonApi\Encoder\Parameters\EncodingParameters;