From d05cb9d9076d2e230a11afb0a0e28dcc45f61422 Mon Sep 17 00:00:00 2001 From: Joseph Shanak Date: Thu, 15 Oct 2020 15:29:11 -0500 Subject: [PATCH 1/2] Update to support CakePHP 4 --- composer.json | 13 ++++++++----- phpunit.xml.dist | 6 ++---- src/Model/Behavior/StiBehavior.php | 2 +- src/Model/Behavior/StiParentBehavior.php | 7 ++++--- src/Model/Entity/CopyableEntityTrait.php | 2 +- tests/TestCase/Model/Behavior/StiBehaviorTest.php | 2 +- .../Model/Behavior/StiParentBehaviorTest.php | 4 ++-- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 0ffd0ce..bd71fd8 100644 --- a/composer.json +++ b/composer.json @@ -5,13 +5,13 @@ "type": "cakephp-plugin", "license": "MIT", "require": { - "php": ">=5.6", - "cakephp/orm": "~3.5" + "php": ">=7.2.0", + "cakephp/orm": "^4.0" }, "require-dev": { - "php": ">=5.6", - "phpunit/phpunit": "<6.0", - "cakephp/cakephp": "~3.5", + "php": ">=7.2.0", + "phpunit/phpunit": "^8.0", + "cakephp/cakephp": "^4.0", "cakephp/cakephp-codesniffer": "@stable" }, "autoload": { @@ -24,5 +24,8 @@ "Cake\\Test\\": "vendor/cakephp/cakephp/tests", "Robotusers\\TableInheritance\\Test\\": "tests" } + }, + "scripts": { + "test": "./vendor/bin/phpunit" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index af2e373..ccc5f73 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,7 +4,6 @@ colors="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > @@ -18,14 +17,13 @@ - + - - ./src/ diff --git a/src/Model/Behavior/StiBehavior.php b/src/Model/Behavior/StiBehavior.php index d386070..ac97c22 100644 --- a/src/Model/Behavior/StiBehavior.php +++ b/src/Model/Behavior/StiBehavior.php @@ -51,7 +51,7 @@ class StiBehavior extends Behavior * @param array $config Config. * @return void */ - public function initialize(array $config) + public function initialize(array $config): void { if ($this->_config['table'] !== null) { $this->_table->setTable($this->_config['table']); diff --git a/src/Model/Behavior/StiParentBehavior.php b/src/Model/Behavior/StiParentBehavior.php index 278279d..24bed38 100644 --- a/src/Model/Behavior/StiParentBehavior.php +++ b/src/Model/Behavior/StiParentBehavior.php @@ -3,7 +3,8 @@ namespace Robotusers\TableInheritance\Model\Behavior; use ArrayAccess; -use Cake\Event\Event; +use Cake\Datasource\EntityInterface; +use Cake\Event\EventInterface; use Cake\ORM\Behavior; use Cake\ORM\Locator\LocatorAwareTrait; use Cake\ORM\Query; @@ -122,13 +123,13 @@ public function newStiEntity($data = null, array $options = []) * @param \ArrayAccess $options Options. * @return void */ - public function beforeFind(Event $event, Query $query, ArrayAccess $options) + public function beforeFind(EventInterface $event, Query $query, ArrayAccess $options) { if (!$query->isHydrationEnabled()) { return; } $query->formatResults(function ($results) { - return $results->map(function ($row) { + return $results->map(function (EntityInterface $row) { if ($row instanceof CopyableEntityInterface) { $table = $this->stiTable($row); $entityClass = $table->getEntityClass(); diff --git a/src/Model/Entity/CopyableEntityTrait.php b/src/Model/Entity/CopyableEntityTrait.php index daefceb..5427de1 100644 --- a/src/Model/Entity/CopyableEntityTrait.php +++ b/src/Model/Entity/CopyableEntityTrait.php @@ -16,6 +16,6 @@ trait CopyableEntityTrait */ public function copyProperties() { - return $this->_properties; + return $this->_fields; } } diff --git a/tests/TestCase/Model/Behavior/StiBehaviorTest.php b/tests/TestCase/Model/Behavior/StiBehaviorTest.php index d0f0548..be87fdf 100644 --- a/tests/TestCase/Model/Behavior/StiBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/StiBehaviorTest.php @@ -16,7 +16,7 @@ class StiBehaviorTest extends TestCase 'plugin.Robotusers\TableInheritance.Users' ]; - public function tearDown() + public function tearDown(): void { parent::tearDown(); diff --git a/tests/TestCase/Model/Behavior/StiParentBehaviorTest.php b/tests/TestCase/Model/Behavior/StiParentBehaviorTest.php index 3867e7e..14c8258 100644 --- a/tests/TestCase/Model/Behavior/StiParentBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/StiParentBehaviorTest.php @@ -26,7 +26,7 @@ class StiParentBehaviorTest extends TestCase */ public $table; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -100,7 +100,7 @@ public function testStiTable() } } - public function tearDown() + public function tearDown(): void { parent::tearDown(); From 9e7208ce5dbf934702b8eaf46df77303500dfe45 Mon Sep 17 00:00:00 2001 From: Joseph Shanak Date: Sun, 1 Nov 2020 09:18:36 -0600 Subject: [PATCH 2/2] Update Travis to test against correct PHP versions --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6961550..1db18ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,9 @@ dist: trusty sudo: false php: - - 5.6 - - 7.0 - - 7.1 + - 7.2 + - 7.3 + - 7.4 env: global: