Skip to content

Commit

Permalink
Merge pull request #589 from FriendsOfCake/cake-update
Browse files Browse the repository at this point in the history
Lower CakePHP version requiment to 3.5.
  • Loading branch information
ADmad authored Apr 23, 2018
2 parents 3d14ebf + 5dfa909 commit f34ec3f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 13 deletions.
18 changes: 11 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ matrix:
fast_finish: true

include:
- php: 7.0
- php: 7.1
env: PHPCS=1 DEFAULT=0

- php: 7.0
- php: 7.1
env: PHPSTAN=1 DEFAULT=0

- php: 5.6
env: PREFER_LOWEST=1

before_script:
- if [[ $TRAVIS_PHP_VERSION != 7.0 && $TRAVIS_PHP_VERSION != 7.2 ]]; then phpenv config-rm xdebug.ini; fi
- if [[ $TRAVIS_PHP_VERSION != 7.1 ]]; then phpenv config-rm xdebug.ini; fi

- composer install --prefer-dist --no-interaction
- if [[ $PREFER_LOWEST != 1 ]]; then composer install --no-interaction; fi
- if [[ $PREFER_LOWEST = 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; 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 @@ -38,14 +42,14 @@ 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 -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon -l 4 src; fi

after_success:
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then bash <(curl -s https://codecov.io/bash); fi

notifications:
email: false
15 changes: 15 additions & 0 deletions aliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
if (!class_exists('Cake\Http\Exception\MethodNotAllowedException')) {
class_alias(
'Cake\Network\Exception\MethodNotAllowedException',
'Cake\Http\Exception\MethodNotAllowedException'
);
class_alias(
'Cake\Network\Exception\NotImplementedException',
'Cake\Http\Exception\NotImplementedException'
);
class_alias(
'Cake\Network\Exception\BadRequestException',
'Cake\Http\Exception\BadRequestException'
);
}
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
],
"require": {
"cakephp/cakephp": "^3.6"
"cakephp/cakephp": "^3.5"
},
"require-dev": {
"phpunit/phpunit": "^5.7.14|^6.0",
Expand All @@ -50,7 +50,10 @@
"autoload": {
"psr-4": {
"Crud\\": "src"
}
},
"files": [
"aliases.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
12 changes: 12 additions & 0 deletions src/Controller/ControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ trait ControllerTrait
*/
public $dispatchComponents = [];

/**
* Get controller name.
*
* Added for backwards compatibility with CakePHP 3.5.
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Dispatches the controller action. Checks that the action exists and isn't private.
*
Expand Down
7 changes: 6 additions & 1 deletion src/Listener/RelatedModelsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public function implementedEvents()
*/
public function beforePaginate(Event $event)
{
$contained = $event->getSubject()->query->getContain();
$method = 'contain';
if (method_exists($event->getSubject()->query, 'getContain')) {
$method = 'getContain';
}
$contained = $event->getSubject()->query->$method();

if (!empty($contained)) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Controller/Component/CrudComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function getLog($params = [])

class CrudExamplesController extends \Cake\Controller\Controller
{
use \Crud\Controller\ControllerTrait;

public $modelClass = 'CrudExamples';

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Listener/ApiListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public function testEnsureSerializeWithoutViewVar()
->getMock();

$controller = $this
->getMockBuilder('\Cake\Controller\Controller')
->getMockBuilder('\Crud\Test\App\Controller\BlogsController')
->setMethods(['set'])
->disableOriginalConstructor()
->getMock();
Expand Down
8 changes: 6 additions & 2 deletions tests/TestCase/Listener/RelatedModelsListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function testbeforePaginate()
$table = $this
->getMockBuilder('\Cake\ORM\Table')
->disableOriginalConstructor()
->setMethods(['associations', 'findAssociation', 'getSchema'])
->setMethods(['associations', 'findAssociation', 'association', 'getSchema'])
->getMock();

$table
Expand All @@ -309,7 +309,11 @@ public function testbeforePaginate()
$event = new Event('beforePaginate', $subject);

$listener->beforePaginate($event);
$result = $event->getSubject()->query->getContain();
if (method_exists($event->getSubject()->query, 'getContain')) {
$result = $event->getSubject()->query->getContain();
} else {
$result = $event->getSubject()->query->contain();
}

$this->assertEquals(['Users' => []], $result);
}
Expand Down

0 comments on commit f34ec3f

Please sign in to comment.