Skip to content

Commit c58e9b5

Browse files
committed
Added integration tests with simple resource
1 parent 7a2e97d commit c58e9b5

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

phpunit.xml.dist renamed to phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<testsuites>
1818
<testsuite name="all">
1919
<directory suffix="Test.php">tests/unit/</directory>
20+
<directory suffix="Test.php">tests/integration/</directory>
2021
</testsuite>
2122
</testsuites>
2223
<filter>

tests/files/01_simple_resource.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"data": {
3+
"type": "articles",
4+
"id": "1",
5+
"attributes": {
6+
},
7+
"relationships": {
8+
}
9+
}
10+
}

tests/integration/IntegrationTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)