- md5
- 50544e5483d8d0e2a9e7e5818c20a493
- sha1
- 73dbb6cbf3a67bba85e79c416297e19eaf93000c
- sha256
- ee05dd37fbfe94d49ed786b10078a7ea0d5eab2c1cefcafbf57c87412f143967
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
<?php
/*
* This file is part of JSON-API.
*
* (c) Toby Zerner <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tobscure\Tests\JsonApi;
use Tobscure\JsonApi\AbstractSerializer;
use Tobscure\JsonApi\Collection;
use Tobscure\JsonApi\Relationship;
use Tobscure\JsonApi\Resource;
class AbstractSerializerTest extends AbstractTestCase
{
public function testGetTypeReturnsTheType()
{
$serializer = new PostSerializer1;
$this->assertEquals('posts', $serializer->getType(null));
}
public function testGetAttributesReturnsTheAttributes()
{
$serializer = new PostSerializer1;
$post = (object) ['foo' => 'bar'];
$this->assertEquals(['foo' => 'bar'], $serializer->getAttributes($post));
}
public function testGetRelationshipReturnsRelationshipFromMethod()
{
$serializer = new PostSerializer1;
$relationship = $serializer->getRelationship(null, 'comments');
$this->assertTrue($relationship instanceof Relationship);
}
public function testGetRelationshipReturnsRelationshipFromMethodUnderscored()
{
$serializer = new PostSerializer1;
$relationship = $serializer->getRelationship(null, 'parent_post');
$this->assertTrue($relationship instanceof Relationship);
}
public function testGetRelationshipReturnsRelationshipFromMethodKebabCase()
{
$serializer = new PostSerializer1;
$relationship = $serializer->getRelationship(null, 'parent-post');
$this->assertTrue($relationship instanceof Relationship);
}
/**
* @expectedException \LogicException
*/
public function testGetRelationshipValidatesRelationship()
{
$serializer = new PostSerializer1;
$serializer->getRelationship(null, 'invalid');
}
}
class PostSerializer1 extends AbstractSerializer
{
protected $type = 'posts';
public function getAttributes($post, array $fields = null)
{
return ['foo' => $post->foo];
}
public function comments($post)
{
$element = new Collection([], new self);
return new Relationship($element);
}
public function parentPost($post)
{
$element = new Resource([], new self);
return new Relationship($element);
}
public function invalid($post)
{
return 'invalid';
}
}
The same content is in 9 releases, Joomla 4.1.0-rc1 to 4.1.2. See them all, or every version of this file.