Skip to content

Bugfix: Add tests and code for pagination links #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Fixed

- **BREAKING**: pagination links moved from `Pagination` to `DocumentLink` and `RelationshipLink`

### Removed

- **BREAKING**: object `Pagination` was removed

## [0.5] - 2015-10-12

### Added
Expand Down
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* [Document Link object](objects-document-link.md)
* [Relationship Link object](objects-relationship-link.md)
* [Error Link object](objects-error-link.md)
* [Pagination object](objects-pagination.md)
* [Jsonapi object](objects-jsonapi.md)
* [Meta object](objects-meta.md)

Expand Down
5 changes: 4 additions & 1 deletion docs/objects-document-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ _[Symbols definition](objects-introduction.md#symbols)_
--- | ---- | ----- | ----
? | self | `string` |
? | related | `string` |
? | pagination | [Pagination object](objects-pagination.md) |
? | first | - `null`<br />- `string` |
? | last | - `null`<br />- `string` |
? | prev | - `null`<br />- `string` |
? | next | - `null`<br />- `string` |
1 change: 0 additions & 1 deletion docs/objects-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ All possible objects and their hierarchical structure are listet below.
1. [Document Link object](objects-document-link.md)
1. [Relationship Link object](objects-relationship-link.md)
1. [Error Link object](objects-error-link.md)
1. [Pagination object](objects-pagination.md)
1. [Jsonapi object](objects-jsonapi.md)
1. [Meta object](objects-meta.md)

Expand Down
21 changes: 0 additions & 21 deletions docs/objects-pagination.md

This file was deleted.

5 changes: 4 additions & 1 deletion docs/objects-relationship-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ _[Symbols definition](objects-introduction.md#symbols)_
--- | ---- | ----- | ----
# | self | `string` |
# | related | `string` |
? | pagination | [Pagination object](objects-pagination.md) | Only exists if the parent relationship object represents a to-many relationship
? | first | - `null`<br />- `string` | Only exists if the parent relationship object represents a to-many relationship |
? | last | - `null`<br />- `string` | Only exists if the parent relationship object represents a to-many relationship |
? | prev | - `null`<br />- `string` | Only exists if the parent relationship object represents a to-many relationship |
? | next | - `null`<br />- `string` | Only exists if the parent relationship object represents a to-many relationship |
56 changes: 51 additions & 5 deletions src/DocumentLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,58 @@ public function __construct($object, FactoryManagerInterface $manager)
$this->container->set('related', $object->related);
}

if ( property_exists($object, 'pagination') )
// Pagination links

if ( property_exists($object, 'first') )
{
if ( ! is_string($object->first) and ! is_null($object->first) )
{
throw new ValidationException('property "first" has to be a string or null, "' . gettype($object->first) . '" given.');
}

if ( ! is_null($object->first) )
{
$this->container->set('first', strval($object->first));
}
}

if ( property_exists($object, 'last') )
{
if ( ! is_string($object->last) and ! is_null($object->last) )
{
throw new ValidationException('property "last" has to be a string or null, "' . gettype($object->last) . '" given.');
}

if ( ! is_null($object->last) )
{
$this->container->set('last', strval($object->last));
}
}

if ( property_exists($object, 'prev') )
{
$this->container->set('pagination', $this->manager->getFactory()->make(
'Pagination',
[$object->pagination, $this->manager]
));
if ( ! is_string($object->prev) and ! is_null($object->prev) )
{
throw new ValidationException('property "prev" has to be a string or null, "' . gettype($object->prev) . '" given.');
}

if ( ! is_null($object->prev) )
{
$this->container->set('prev', strval($object->prev));
}
}

if ( property_exists($object, 'next') )
{
if ( ! is_string($object->next) and ! is_null($object->next) )
{
throw new ValidationException('property "next" has to be a string or null, "' . gettype($object->next) . '" given.');
}

if ( ! is_null($object->next) )
{
$this->container->set('next', strval($object->next));
}
}
}

Expand Down
128 changes: 0 additions & 128 deletions src/Pagination.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/PaginationInterface.php

This file was deleted.

56 changes: 51 additions & 5 deletions src/RelationshipLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,58 @@ public function __construct($object, FactoryManagerInterface $manager)
$this->container->set('related', strval($object->related));
}

if ( property_exists($object, 'pagination') )
// Pagination links

if ( property_exists($object, 'first') )
{
if ( ! is_string($object->first) and ! is_null($object->first) )
{
throw new ValidationException('property "first" has to be a string or null, "' . gettype($object->first) . '" given.');
}

if ( ! is_null($object->first) )
{
$this->container->set('first', strval($object->first));
}
}

if ( property_exists($object, 'last') )
{
if ( ! is_string($object->last) and ! is_null($object->last) )
{
throw new ValidationException('property "last" has to be a string or null, "' . gettype($object->last) . '" given.');
}

if ( ! is_null($object->last) )
{
$this->container->set('last', strval($object->last));
}
}

if ( property_exists($object, 'prev') )
{
$this->container->set('pagination', $this->manager->getFactory()->make(
'Pagination',
[$object->pagination, $this->manager]
));
if ( ! is_string($object->prev) and ! is_null($object->prev) )
{
throw new ValidationException('property "prev" has to be a string or null, "' . gettype($object->prev) . '" given.');
}

if ( ! is_null($object->prev) )
{
$this->container->set('prev', strval($object->prev));
}
}

if ( property_exists($object, 'next') )
{
if ( ! is_string($object->next) and ! is_null($object->next) )
{
throw new ValidationException('property "next" has to be a string or null, "' . gettype($object->next) . '" given.');
}

if ( ! is_null($object->next) )
{
$this->container->set('next', strval($object->next));
}
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Utils/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class Factory implements FactoryInterface
'Jsonapi' => 'Art4\JsonApiClient\Jsonapi',
'Link' => 'Art4\JsonApiClient\Link',
'Meta' => 'Art4\JsonApiClient\Meta',
'Pagination' => 'Art4\JsonApiClient\Pagination',
'Relationship' => 'Art4\JsonApiClient\Relationship',
'RelationshipCollection' => 'Art4\JsonApiClient\RelationshipCollection',
'RelationshipLink' => 'Art4\JsonApiClient\RelationshipLink',
Expand Down
24 changes: 24 additions & 0 deletions tests/files/06_pagination_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"meta": {
"total-pages": 13
},
"data": [
{
"type": "articles",
"id": "3",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever.",
"created": "2015-05-22T14:56:29.000Z",
"updated": "2015-05-22T14:56:28.000Z"
}
}
],
"links": {
"self": "http://example.com/articles?page[number]=3&page[size]=1",
"first": "http://example.com/articles?page[number]=1&page[size]=1",
"prev": "http://example.com/articles?page[number]=2&page[size]=1",
"next": "http://example.com/articles?page[number]=4&page[size]=1",
"last": "http://example.com/articles?page[number]=13&page[size]=1"
}
}
Loading