Skip to content

Commit

Permalink
Renamed test mock MasterItem to ParentItem
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Sep 8, 2022
1 parent 826dcde commit 1e7c60b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 69 deletions.
10 changes: 5 additions & 5 deletions tests/Concerns/HasRelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Swis\JsonApi\Client\Relations\HasOneRelation;
use Swis\JsonApi\Client\Relations\MorphToManyRelation;
use Swis\JsonApi\Client\Relations\MorphToRelation;
use Swis\JsonApi\Client\Tests\Mocks\Items\MasterItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\ParentItem;
use Swis\JsonApi\Client\Util;

class HasRelationsTest extends TestCase
Expand Down Expand Up @@ -197,7 +197,7 @@ public function itCanDefineAHasOneRelation()
/** @var \PHPUnit\Framework\MockObject\MockObject&\Swis\JsonApi\Client\Concerns\HasRelations $mock */
$mock = $this->getMockForTrait(HasRelations::class);

$relation = $mock->hasOne(MasterItem::class, 'foo-bar');
$relation = $mock->hasOne(ParentItem::class, 'foo-bar');

$this->assertInstanceOf(HasOneRelation::class, $relation);
$this->assertSame($relation, $mock->getRelation('foo-bar'));
Expand All @@ -211,7 +211,7 @@ public function itCanDefineAHasOneRelationWithTheCallingMethodAsFallbackName()
/** @var \PHPUnit\Framework\MockObject\MockObject&\Swis\JsonApi\Client\Concerns\HasRelations $mock */
$mock = $this->getMockForTrait(HasRelations::class);

$relation = $mock->hasOne(MasterItem::class);
$relation = $mock->hasOne(ParentItem::class);

$this->assertInstanceOf(HasOneRelation::class, $relation);
$this->assertSame($relation, $mock->getRelation(Util::stringSnake(__FUNCTION__)));
Expand All @@ -225,7 +225,7 @@ public function itCanDefineAHasManyRelation()
/** @var \PHPUnit\Framework\MockObject\MockObject&\Swis\JsonApi\Client\Concerns\HasRelations $mock */
$mock = $this->getMockForTrait(HasRelations::class);

$relation = $mock->hasMany(MasterItem::class, 'foo-bar');
$relation = $mock->hasMany(ParentItem::class, 'foo-bar');

$this->assertInstanceOf(HasManyRelation::class, $relation);
$this->assertSame($relation, $mock->getRelation('foo-bar'));
Expand All @@ -239,7 +239,7 @@ public function itCanDefineAHasManyRelationWithTheCallingMethodAsFallbackName()
/** @var \PHPUnit\Framework\MockObject\MockObject&\Swis\JsonApi\Client\Concerns\HasRelations $mock */
$mock = $this->getMockForTrait(HasRelations::class);

$relation = $mock->hasMany(MasterItem::class);
$relation = $mock->hasMany(ParentItem::class);

$this->assertInstanceOf(HasManyRelation::class, $relation);
$this->assertSame($relation, $mock->getRelation(Util::stringSnake(__FUNCTION__)));
Expand Down
6 changes: 3 additions & 3 deletions tests/ItemHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Swis\JsonApi\Client\Relations\MorphToManyRelation;
use Swis\JsonApi\Client\Relations\MorphToRelation;
use Swis\JsonApi\Client\Tests\Mocks\Items\AnotherRelatedItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\MasterItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\ParentItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\RelatedItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\WithRelationshipItem;
use Swis\JsonApi\Client\TypeMapper;
Expand Down Expand Up @@ -589,10 +589,10 @@ public function itThrowsWhenRelationshipIsPresentInAvailableRelationshipsButTheM
'does_not_exist' => '1',
];

$item = new MasterItem();
$item = new ParentItem();

$this->expectException(HydrationException::class);
$this->expectExceptionMessage(sprintf('Method doesNotExist not found on %s', MasterItem::class));
$this->expectExceptionMessage(sprintf('Method doesNotExist not found on %s', ParentItem::class));

$this->getItemHydrator()->hydrate($item, $data);
}
Expand Down
24 changes: 12 additions & 12 deletions tests/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Swis\JsonApi\Client\Links;
use Swis\JsonApi\Client\Meta;
use Swis\JsonApi\Client\Tests\Mocks\Items\ChildItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\MasterItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\ParentItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\RelatedItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\WithHiddenItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\WithRelationshipItem;
Expand Down Expand Up @@ -491,11 +491,11 @@ public function itIsNewWhenNoIdIsset()
*/
public function itCanGetARelationValueUsingGetAttributeMethod()
{
$masterItem = new MasterItem();
$parentItem = new ParentItem();
$childItem = new ChildItem();
$masterItem->child()->associate($childItem);
$parentItem->child()->associate($childItem);

$this->assertSame($childItem, $masterItem->getAttribute('child'));
$this->assertSame($childItem, $parentItem->getAttribute('child'));
}

/**
Expand Down Expand Up @@ -528,14 +528,14 @@ public function itReturnsABooleanIndicatingIfItHasAttributes()
*/
public function itCanGetAllRelationships()
{
$masterItem = new MasterItem();
$parentItem = new ParentItem();
$childItem = new ChildItem();
$childItem->setId('1');
$childItem->setMeta(new Meta(['foo' => 'bar']));
$masterItem->child()->associate($childItem);
$masterItem->children()->associate(new Collection([$childItem]));
$parentItem->child()->associate($childItem);
$parentItem->children()->associate(new Collection([$childItem]));

$relations = $masterItem->getRelationships();
$relations = $parentItem->getRelationships();

$this->assertSame([
'child' => [
Expand Down Expand Up @@ -566,13 +566,13 @@ public function itCanGetAllRelationships()
*/
public function itReturnsABooleanIndicatingIfItHasRelationships()
{
$masterItem = new MasterItem();
$this->assertFalse($masterItem->hasRelationships());
$parentItem = new ParentItem();
$this->assertFalse($parentItem->hasRelationships());

$childItem = (new ChildItem())->setId('1');
$masterItem->child()->associate($childItem);
$parentItem->child()->associate($childItem);

$this->assertTrue($masterItem->hasRelationships());
$this->assertTrue($parentItem->hasRelationships());
}

/**
Expand Down
46 changes: 23 additions & 23 deletions tests/Parsers/DocumentParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Swis\JsonApi\Client\Meta;
use Swis\JsonApi\Client\Parsers\DocumentParser;
use Swis\JsonApi\Client\Tests\Mocks\Items\ChildItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\MasterItem;
use Swis\JsonApi\Client\Tests\Mocks\Items\ParentItem;
use Swis\JsonApi\Client\TypeMapper;

class DocumentParserTest extends TestCase
Expand Down Expand Up @@ -201,7 +201,7 @@ public function itThrowsWhenItFindsDuplicateResources()
[
'data' => [
[
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand All @@ -210,7 +210,7 @@ public function itThrowsWhenItFindsDuplicateResources()
],
'included' => [
[
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand All @@ -232,7 +232,7 @@ public function itParsesAResourceDocument()
json_encode(
[
'data' => [
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand All @@ -244,7 +244,7 @@ public function itParsesAResourceDocument()

$this->assertInstanceOf(ItemDocument::class, $document);
$this->assertInstanceOf(ItemInterface::class, $document->getData());
$this->assertEquals('master', $document->getData()->getType());
$this->assertEquals('parent', $document->getData()->getType());
$this->assertEquals('1', $document->getData()->getId());
}

Expand All @@ -259,7 +259,7 @@ public function itParsesAResourceCollectionDocument()
[
'data' => [
[
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand All @@ -273,7 +273,7 @@ public function itParsesAResourceCollectionDocument()
$this->assertInstanceOf(CollectionDocument::class, $document);
$this->assertInstanceOf(Collection::class, $document->getData());
$this->assertCount(1, $document->getData());
$this->assertEquals('master', $document->getData()->get(0)->getType());
$this->assertEquals('parent', $document->getData()->get(0)->getType());
$this->assertEquals('1', $document->getData()->get(0)->getId());
}

Expand Down Expand Up @@ -308,7 +308,7 @@ public function itParsesIncluded()
'data' => [],
'included' => [
[
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand All @@ -322,7 +322,7 @@ public function itParsesIncluded()
$this->assertInstanceOf(CollectionDocument::class, $document);
$this->assertInstanceOf(Collection::class, $document->getIncluded());
$this->assertCount(1, $document->getIncluded());
$this->assertEquals('master', $document->getIncluded()->get(0)->getType());
$this->assertEquals('parent', $document->getIncluded()->get(0)->getType());
$this->assertEquals('1', $document->getIncluded()->get(0)->getId());
}

Expand All @@ -332,15 +332,15 @@ public function itParsesIncluded()
public function itLinksSingularRelationsToItemsFromIncluded()
{
$typeMapper = new TypeMapper();
$typeMapper->setMapping('master', MasterItem::class);
$typeMapper->setMapping('parent', ParentItem::class);
$typeMapper->setMapping('child', ChildItem::class);
$parser = DocumentParser::create($typeMapper);

$document = $parser->parse(
json_encode(
[
'data' => [
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand All @@ -367,7 +367,7 @@ public function itLinksSingularRelationsToItemsFromIncluded()
)
);

$this->assertInstanceOf(MasterItem::class, $document->getData());
$this->assertInstanceOf(ParentItem::class, $document->getData());
$this->assertInstanceOf(ChildItem::class, $document->getData()->child()->getIncluded());
$this->assertSame($document->getIncluded()->get(0), $document->getData()->child()->getIncluded());
}
Expand All @@ -378,15 +378,15 @@ public function itLinksSingularRelationsToItemsFromIncluded()
public function itDoesNotLinkEmptySingularRelations()
{
$typeMapper = new TypeMapper();
$typeMapper->setMapping('master', MasterItem::class);
$typeMapper->setMapping('parent', ParentItem::class);
$typeMapper->setMapping('child', ChildItem::class);
$parser = DocumentParser::create($typeMapper);

$document = $parser->parse(
json_encode(
[
'data' => [
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand All @@ -410,7 +410,7 @@ public function itDoesNotLinkEmptySingularRelations()
)
);

$this->assertInstanceOf(MasterItem::class, $document->getData());
$this->assertInstanceOf(ParentItem::class, $document->getData());
$this->assertNull($document->getData()->child()->getIncluded());
$this->assertInstanceOf(ChildItem::class, $document->getIncluded()->get(0));
}
Expand All @@ -421,15 +421,15 @@ public function itDoesNotLinkEmptySingularRelations()
public function itLinksPluralRelationsToItemsFromIncluded()
{
$typeMapper = new TypeMapper();
$typeMapper->setMapping('master', MasterItem::class);
$typeMapper->setMapping('parent', ParentItem::class);
$typeMapper->setMapping('child', ChildItem::class);
$parser = DocumentParser::create($typeMapper);

$document = $parser->parse(
json_encode(
[
'data' => [
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand Down Expand Up @@ -469,7 +469,7 @@ public function itLinksPluralRelationsToItemsFromIncluded()
)
);

$this->assertInstanceOf(MasterItem::class, $document->getData());
$this->assertInstanceOf(ParentItem::class, $document->getData());
$this->assertInstanceOf(Collection::class, $document->getData()->children()->getIncluded());
$this->assertInstanceOf(ChildItem::class, $document->getData()->children()->getIncluded()->get(0));
$this->assertSame($document->getIncluded()->get(0), $document->getData()->children()->getIncluded()->get(0));
Expand All @@ -482,15 +482,15 @@ public function itLinksPluralRelationsToItemsFromIncluded()
public function itDoesNotLinkEmptyPluralRelations()
{
$typeMapper = new TypeMapper();
$typeMapper->setMapping('master', MasterItem::class);
$typeMapper->setMapping('parent', ParentItem::class);
$typeMapper->setMapping('child', ChildItem::class);
$parser = DocumentParser::create($typeMapper);

$document = $parser->parse(
json_encode(
[
'data' => [
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand Down Expand Up @@ -521,7 +521,7 @@ public function itDoesNotLinkEmptyPluralRelations()
)
);

$this->assertInstanceOf(MasterItem::class, $document->getData());
$this->assertInstanceOf(ParentItem::class, $document->getData());
$this->assertInstanceOf(Collection::class, $document->getData()->children()->getIncluded());
$this->assertEmpty($document->getData()->children()->getIncluded());
$this->assertInstanceOf(ChildItem::class, $document->getIncluded()->get(0));
Expand Down Expand Up @@ -605,15 +605,15 @@ public function itParsesMeta()
public function itParsesMetaInRelationshipDataAndIncluded()
{
$typeMapper = new TypeMapper();
$typeMapper->setMapping('master', MasterItem::class);
$typeMapper->setMapping('parent', ParentItem::class);
$typeMapper->setMapping('child', ChildItem::class);
$parser = DocumentParser::create($typeMapper);

$document = $parser->parse(
json_encode(
[
'data' => [
'type' => 'master',
'type' => 'parent',
'id' => '1',
'attributes' => [
'foo' => 'bar',
Expand Down
Loading

0 comments on commit 1e7c60b

Please sign in to comment.