Skip to content

Commit

Permalink
Merge pull request #95 from FriendsOfCake/update-neomerx
Browse files Browse the repository at this point in the history
Update neomerx/jsonapi to ^3.0.0
  • Loading branch information
dakota committed May 6, 2019
2 parents f2263f7 + d7a9350 commit 540292b
Show file tree
Hide file tree
Showing 98 changed files with 2,280 additions and 1,002 deletions.
19 changes: 10 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

sudo: false

Expand All @@ -15,6 +14,7 @@ env:
- DB=sqlite db_dsn='sqlite:///:memory:'
global:
- DEFAULT=1
- LOWEST=0

matrix:
fast_finish: true
Expand All @@ -26,14 +26,15 @@ matrix:
- php: 7.2
env: PHPCS=1 DEFAULT=0

before_script:
- if [[ $TRAVIS_PHP_VERSION != 7.0 ]]; then phpenv config-rm xdebug.ini; fi
- php: 7.2
env: LOWEST=1 DEFAULT=1

- if [[ $TRAVIS_PHP_VERSION = 5.5 ]]; then composer require --dev friendsofcake/search:^3.0; fi
- if [[ $TRAVIS_PHP_VERSION != 5.5 ]]; then composer install --prefer-dist --no-interaction; fi
before_script:
- if [[ $TRAVIS_PHP_VERSION != 7.1 ]]; then phpenv config-rm xdebug.ini; fi

- composer self-update
- composer install --prefer-dist --no-interaction
- if [[ $LOWEST != 1 ]]; then composer install --prefer-dist --no-interaction; fi
- if [[ $LOWEST = 1 ]]; then composer update --prefer-lowest --prefer-dist --no-interaction; fi

- if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
- if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
Expand All @@ -42,8 +43,8 @@ before_script:
- if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan:^0.9; fi

script:
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.0 ]]; then vendor/bin/phpunit; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.1 ]]; then vendor/bin/phpunit; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi

- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon --level 7 ./src; fi
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
}
],
"require":{
"cakephp/cakephp": "^3.6",
"friendsofcake/crud": "*",
"neomerx/json-api": "^1.0"
"php": ">=7.1.0",
"cakephp/cakephp": "^3.7",
"friendsofcake/crud": "^5.4.6",
"neomerx/json-api": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.14|^6.0",
Expand Down
7 changes: 0 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ parameters:
- Crud\Event\Subject
ignoreErrors:
# ORM
- '#Call to an undefined method Cake\\Datasource\\EntityInterface::source\(\)#'
- '#Call to an undefined method Cake\\Datasource\\RepositoryInterface::associations\(\)#'
- '#Call to an undefined method Cake\\Datasource\\RepositoryInterface::getAssociation\(\)#'
- '#Call to an undefined method Cake\\Datasource\\RepositoryInterface::getEntityClass\(\)#'
- '#Call to an undefined method Cake\\Datasource\\RepositoryInterface::getPrimaryKey\(\)#'
- '#Call to an undefined method Cake\\Datasource\\RepositoryInterface::getRegistryAlias\(\)#'
- '#Call to an undefined method Cake\\Datasource\\RepositoryInterface::hasAssociation\(\)#'

# Crud properties
- '#Access to an undefined property object::\$created#'
Expand Down
24 changes: 11 additions & 13 deletions src/Error/JsonApiExceptionRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Cake\Error\Debugger;
use Crud\Error\ExceptionRenderer;
use Crud\Listener\ApiQueryLogListener;
use Neomerx\JsonApi\Document\Error;
use Neomerx\JsonApi\Encoder\Encoder;
use Neomerx\JsonApi\Exceptions\ErrorCollection;
use Neomerx\JsonApi\Schema\Error;
use Neomerx\JsonApi\Schema\ErrorCollection;
use Zend\Diactoros\Stream;

/**
Expand All @@ -34,7 +34,7 @@ protected function _outputMessage($template)
}

$viewVars = $this->controller->viewVars;
$code = $this->controller->response->getStatusCode(); // e.g. 404
$status = (string)$this->controller->response->getStatusCode(); // e.g. 404
$title = $this->controller->response->getReasonPhrase(); // e,g. Not Found

// Only set JSON API `detail` field if `message` viewVar field is not
Expand All @@ -48,12 +48,11 @@ protected function _outputMessage($template)
$errorCollection->add(new Error(
$idx = null,
$aboutLink = null,
$status = null,
$code,
$typeLinks = null,
$status,
$code = null,
$title,
$detail,
$source = null,
$meta = null
$detail
));

$encoder = Encoder::instance();
Expand Down Expand Up @@ -127,14 +126,13 @@ public function validation($exception)
* - creating a new collection from CakePHP validation errors
*
* @param array $validationErrors CakePHP validation errors
* @return \Neomerx\JsonApi\Exceptions\ErrorCollection
* @return \Neomerx\JsonApi\Schema\ErrorCollection
*/
protected function _getNeoMerxErrorCollection($validationErrors)
{
if (isset($validationErrors['CrudJsonApiListener']['NeoMerxErrorCollection'])) {
if (is_a($validationErrors['CrudJsonApiListener']['NeoMerxErrorCollection'], '\Neomerx\JsonApi\Exceptions\ErrorCollection')) {
return $validationErrors['CrudJsonApiListener']['NeoMerxErrorCollection'];
}
if (isset($validationErrors['CrudJsonApiListener']['NeoMerxErrorCollection']) &&
$validationErrors['CrudJsonApiListener']['NeoMerxErrorCollection'] instanceof ErrorCollection) {
return $validationErrors['CrudJsonApiListener']['NeoMerxErrorCollection'];
}

// Create new NeoMerx ErrorCollection from CakePHP validation errors
Expand Down
13 changes: 7 additions & 6 deletions src/Listener/JsonApi/DocumentValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Crud\Core\BaseObject;
use Crud\Error\Exception\CrudException;
use Crud\Error\Exception\ValidationException;
use Neomerx\JsonApi\Document\Error;
use Neomerx\JsonApi\Document\Link;
use Neomerx\JsonApi\Exceptions\ErrorCollection;
use Neomerx\JsonApi\Schema\Error;
use Neomerx\JsonApi\Schema\ErrorCollection;
use Neomerx\JsonApi\Schema\Link;
use stdClass;

/**
Expand All @@ -30,7 +30,7 @@ class DocumentValidator extends stdClass
protected $_document;

/**
* @var \Neomerx\JsonApi\Exceptions\ErrorCollection
* @var \Neomerx\JsonApi\Schema\ErrorCollection
*/
protected $_errorCollection;

Expand Down Expand Up @@ -116,6 +116,7 @@ protected function _documentMustHavePrimaryData()
$this->_errorCollection->add(new Error(
$idx = null,
$aboutLink = $this->_getAboutLink('http://jsonapi.org/format/#document-top-level'),
$typeLinks = null,
$status = null,
$code = null,
$title = null,
Expand Down Expand Up @@ -596,15 +597,15 @@ protected function _getPathObject($path)
* Helper method that displays aboutLink only if enabled in Listener config.
*
* @param string $url URL
* @return \Neomerx\JsonApi\Document\Link|null
* @return \Neomerx\JsonApi\Schema\Link|null
*/
protected function _getAboutLink($url)
{
if ($this->_config['docValidatorAboutLinks'] === false) {
return null;
}

return new Link($url);
return new Link(false, $url, false);
}

/**
Expand Down

0 comments on commit 540292b

Please sign in to comment.