Skip to content

Commit d5b5dff

Browse files
authored
Doc2test (#68)
1 parent 814505e commit d5b5dff

8 files changed

+28
-20
lines changed

.codeclimate.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ engines:
22
phpmd:
33
enabled: true
44
checks:
5-
Controversial/CamelCasePropertyName:
6-
enabled: false
75
Naming/ShortVariable:
86
enabled: false
97
CleanCode/StaticAccess:
10-
enabled: false
8+
enabled: false

.doc2test.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source = ./README.md
2+
destination = ./doc-test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
composer.phar
2+
/doc-test/
23
/vendor/
34
/composer.lock
45
/.php_cs.cache

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ before_script:
1010
script:
1111
- vendor/bin/php-cs-fixer fix -v --dry-run
1212
- phpunit --coverage-clover build/logs/clover.xml
13+
- vendor/bin/doc2test && vendor/bin/phpunit -c doc-test/phpunit.xml
14+
15+
matrix:
16+
exclude:
17+
- php: '7.0'
18+
script: vendor/bin/doc2test && vendor/bin/phpunit -c doc-test/phpunit.xml

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This library is an attempt to express business rules of JSON API specification i
33

44
A simple example to illustrate the general idea. This JSON representation from
55
[the documentation](http://jsonapi.org/format/#document-resource-objects)
6-
6+
<!-- name=my_json -->
77
```json
88
{
99
"data": {
@@ -28,19 +28,20 @@ A simple example to illustrate the general idea. This JSON representation from
2828
}
2929
```
3030
can be built with the following php code (less imports):
31+
<!-- assert=output expect=my_json -->
3132
```php
3233
<?php
33-
$articles = new ResourceObject('articles', '1');
34-
$author = Relationship::fromLinkage(
35-
new SingleLinkage(
36-
new ResourceIdentifier('people', '9')
34+
$articles = new \JsonApiPhp\JsonApi\Document\Resource\ResourceObject('articles', '1');
35+
$author = \JsonApiPhp\JsonApi\Document\Resource\Relationship::fromLinkage(
36+
new \JsonApiPhp\JsonApi\Document\Resource\Linkage\SingleLinkage(
37+
new \JsonApiPhp\JsonApi\Document\Resource\ResourceIdentifier('people', '9')
3738
)
3839
);
3940
$author->setLink('self', '/articles/1/relationships/author');
4041
$author->setLink('related','/articles/1/author');
4142
$articles->setRelationship('author', $author);
4243
$articles->setAttribute('title', 'Rails is Omakase');
43-
$doc = Document::fromResource($articles);
44+
$doc = \JsonApiPhp\JsonApi\Document::fromResource($articles);
4445
echo json_encode($doc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
4546
```
4647

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "json-api-php/json-api",
33
"description": "An attempt to express JSON API specs (jsonapi.org) in object-oriented way as a set of PHP 7 classes",
44
"type": "library",
5-
5+
"prefer-stable": true,
66
"license": "MIT",
77
"authors": [
88
{
@@ -15,7 +15,8 @@
1515
},
1616
"require-dev": {
1717
"phpunit/phpunit": "^6.0",
18-
"friendsofphp/php-cs-fixer": "^2.2"
18+
"friendsofphp/php-cs-fixer": "^2.2",
19+
"doc2test/doc2test": "dev-master"
1920
},
2021
"autoload": {
2122
"psr-4": {

phpunit.xml.dist

-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<!--
3-
~ This file is part of JSON:API implementation for PHP.
4-
~
5-
~ (c) Alexey Karapetov <karapetov@gmail.com>
6-
~
7-
~ For the full copyright and license information, please view the LICENSE
8-
~ file that was distributed with this source code.
9-
-->
10-
112
<phpunit
123
bootstrap="vendor/autoload.php"
134
stopOnFailure="false"

test/Document/CompoundDocumentTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,18 @@ public function testOfficialDocsExample()
7777

7878
$doc = Document::fromResources($article);
7979
$doc->setIncluded($dan, $comment05, $comment12);
80+
$doc->setLink('self', 'http://example.com/articles');
81+
$doc->setLink('next', 'http://example.com/articles?page[offset]=2');
82+
$doc->setLink('last', 'http://example.com/articles?page[offset]=10');
8083

8184
$this->assertEncodesTo(
8285
'
8386
{
87+
"links": {
88+
"self": "http://example.com/articles",
89+
"next": "http://example.com/articles?page[offset]=2",
90+
"last": "http://example.com/articles?page[offset]=10"
91+
},
8492
"data": [{
8593
"type": "articles",
8694
"id": "1",

0 commit comments

Comments
 (0)