Skip to content

Commit

Permalink
Close #181
Browse files Browse the repository at this point in the history
and fix a few code style issues found by newer versions of dev tools.
  • Loading branch information
neomerx committed Jul 29, 2017
1 parent c2a41bb commit 152d43c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 21 deletions.
33 changes: 33 additions & 0 deletions src/Exceptions/ErrorCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down
17 changes: 3 additions & 14 deletions tests/Document/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions tests/Encoder/EncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
13 changes: 12 additions & 1 deletion tests/Exceptions/ErrorCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down
1 change: 0 additions & 1 deletion tests/Exceptions/JsonApiExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions tests/Extensions/Issue154/CustomEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -59,6 +62,9 @@ protected static function createFactory()
*/
protected function getContainer()
{
return parent::getContainer();
/** @var CustomContainerInterface $container */
$container = parent::getContainer();

return $container;
}
}
5 changes: 4 additions & 1 deletion tests/Extensions/Issue169/CustomEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
1 change: 0 additions & 1 deletion tests/Extensions/Issue91/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* limitations under the License.
*/

use \Mockery;
use \Neomerx\JsonApi\Encoder\Encoder;
use \Neomerx\Tests\JsonApi\BaseTestCase;

Expand Down
1 change: 0 additions & 1 deletion tests/Http/Query/EncodingParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* limitations under the License.
*/

use \Mockery;
use \Neomerx\Tests\JsonApi\BaseTestCase;
use \Neomerx\JsonApi\Encoder\Parameters\EncodingParameters;

Expand Down

0 comments on commit 152d43c

Please sign in to comment.