|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Art4\JsonApiClient\Integration\Tests; |
| 4 | + |
| 5 | +use Art4\JsonApiClient\Utils\Helper; |
| 6 | +use InvalidArgumentException; |
| 7 | + |
| 8 | +class IntegrationTest extends \PHPUnit_Framework_TestCase |
| 9 | +{ |
| 10 | + |
| 11 | + /** |
| 12 | + * returns a json string |
| 13 | + */ |
| 14 | + protected function getJsonString($filename) |
| 15 | + { |
| 16 | + $content = file_get_contents(__DIR__ . '/../files/' . $filename); |
| 17 | + |
| 18 | + return $content; |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * @test parse() with valid JSON API returns Document Object |
| 23 | + */ |
| 24 | + public function testParseSimpleResource() |
| 25 | + { |
| 26 | + $string = $this->getJsonString('01_simple_resource.js'); |
| 27 | + $document = Helper::parse($string); |
| 28 | + |
| 29 | + $this->assertInstanceOf('Art4\JsonApiClient\Document', $document); |
| 30 | + $this->assertFalse($document->hasErrors()); |
| 31 | + $this->assertFalse($document->hasMeta()); |
| 32 | + $this->assertFalse($document->hasJsonapi()); |
| 33 | + $this->assertFalse($document->hasLinks()); |
| 34 | + $this->assertFalse($document->hasIncluded()); |
| 35 | + $this->assertTrue($document->hasData()); |
| 36 | + |
| 37 | + $resource = $document->getData(); |
| 38 | + |
| 39 | + $this->assertInstanceOf('Art4\JsonApiClient\Resource', $resource); |
| 40 | + $this->assertFalse($resource->hasMeta()); |
| 41 | + $this->assertSame($resource->getType(), 'articles'); |
| 42 | + $this->assertSame($resource->getId(), '1'); |
| 43 | + $this->assertTrue($resource->hasAttributes()); |
| 44 | + $this->assertInstanceOf('Art4\JsonApiClient\Attributes', $resource->getAttributes()); |
| 45 | + $this->assertTrue($resource->hasRelationships()); |
| 46 | + $this->assertInstanceOf('Art4\JsonApiClient\RelationshipCollection', $resource->getRelationships()); |
| 47 | + } |
| 48 | +} |
0 commit comments