From 94d51eb8ce2218dd0788217a37756bbd093faedc Mon Sep 17 00:00:00 2001 From: Jason Horvath Date: Wed, 19 Feb 2020 13:58:51 -0500 Subject: [PATCH 01/12] Cake 4.x EntityTrait:: changed to --- src/ORM/LazyLoadEntityTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ORM/LazyLoadEntityTrait.php b/src/ORM/LazyLoadEntityTrait.php index d176fd8..3442624 100644 --- a/src/ORM/LazyLoadEntityTrait.php +++ b/src/ORM/LazyLoadEntityTrait.php @@ -115,8 +115,8 @@ protected function _lazyLoad($property) } // check if the property was set as null to begin with - if (array_key_exists($property, $this->_properties)) { - return $this->_properties[$property]; + if (array_key_exists($property, $this->_fields)) { + return $this->_fields[$property]; } $repository = $this->_repository($property); @@ -135,11 +135,11 @@ protected function _lazyLoad($property) $repository->loadInto($this, [$association->getName()]); // check if the association didn't exist and therefore didn't load - if (!isset($this->_properties[$property])) { + if (!isset($this->_fields[$property])) { return null; } - return $this->_properties[$property]; + return $this->_fields[$property]; } /** From 6ec8e89d5ae854e117210e71308c8ce0222ed298 Mon Sep 17 00:00:00 2001 From: Jason Horvath Date: Wed, 19 Feb 2020 14:35:24 -0500 Subject: [PATCH 02/12] update cakephp requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e2349ee..a3c8e19 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require-dev": { "phpunit/phpunit": "^5.7|^6.0", "cakephp/cakephp-codesniffer": "dev-master", - "cakephp/cakephp": ">=3.6.0 <4.0" + "cakephp/cakephp": "^4.0" }, "require": { "cakephp/orm": ">=3.6.0 <4.0" From 1b418fefdb05e07766a7972c73cbbc26b4b0336e Mon Sep 17 00:00:00 2001 From: Jason Horvath Date: Wed, 19 Feb 2020 14:42:51 -0500 Subject: [PATCH 03/12] update phpunit and orm versions --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a3c8e19..0fa922b 100644 --- a/composer.json +++ b/composer.json @@ -6,12 +6,12 @@ "cakephp", "plugin", "lazy load" ], "require-dev": { - "phpunit/phpunit": "^5.7|^6.0", + "phpunit/phpunit": "^8.5", "cakephp/cakephp-codesniffer": "dev-master", "cakephp/cakephp": "^4.0" }, "require": { - "cakephp/orm": ">=3.6.0 <4.0" + "cakephp/orm": "^4.0" }, "autoload": { "psr-4": { From 1ec75504aa19d1c1795bfb6c9ac97d6c8ec830cd Mon Sep 17 00:00:00 2001 From: Jason Horvath Date: Wed, 19 Feb 2020 14:58:46 -0500 Subject: [PATCH 04/12] cakephp 4 return type compatibility --- .phpunit.result.cache | 1 + src/ORM/LazyLoadEntityTrait.php | 2 +- tests/TestCase/ORM/LazyLoadEntityTraitTest.php | 15 +++++++-------- 3 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..b9be881 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +C:37:"PHPUnit\Runner\DefaultTestResultCache":2383:{a:2:{s:7:"defects";a:3:{s:84:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testEntityMethodGet";i:6;s:80:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testEmptySource";i:4;s:93:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testDontInterfereWithContain";i:6;}s:5:"times";a:20:{s:99:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testFormatResultsNonExistentRecord";d:0.376;s:88:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testNullableAssociation";d:0.01;s:86:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testMissingPrimaryKey";d:0.005;s:84:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testTablelessEntity";d:0.002;s:82:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testUnsetProperty";d:0.081;s:93:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testUnsetEagerLoadedProperty";d:0.007;s:85:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testHasLazyLoadsOnce";d:0.01;s:85:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testGetLazyLoadsOnce";d:0.007;s:80:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testGetAccessor";d:0.004;s:72:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testGet";d:0.004;s:84:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testEntityMethodGet";d:0.026;s:80:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testEmptySource";d:0.004;s:81:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testDeepLazyLoad";d:0.027;s:77:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testLazyLoad";d:0.02;s:72:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testHas";d:0.012;s:77:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testHasArray";d:0.009;s:93:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testDontInterfereWithContain";d:0.004;s:83:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testDuplicateTrait";d:0.013;s:112:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testByRefArrayFunctionsWorkOnNormalCakeEntities";d:0.01;s:114:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testByRefArrayFunctionsWorkOnLazyLoadCakeEntities";d:0.009;}}} \ No newline at end of file diff --git a/src/ORM/LazyLoadEntityTrait.php b/src/ORM/LazyLoadEntityTrait.php index 3442624..137bcfe 100644 --- a/src/ORM/LazyLoadEntityTrait.php +++ b/src/ORM/LazyLoadEntityTrait.php @@ -58,7 +58,7 @@ protected function &_parentGet($property) * @param string|array $property Property * @return bool */ - public function has($property) + public function has($property): bool { foreach ((array)$property as $prop) { $has = $this->_parentHas($prop); diff --git a/tests/TestCase/ORM/LazyLoadEntityTraitTest.php b/tests/TestCase/ORM/LazyLoadEntityTraitTest.php index 40a8e9b..a87991b 100644 --- a/tests/TestCase/ORM/LazyLoadEntityTraitTest.php +++ b/tests/TestCase/ORM/LazyLoadEntityTraitTest.php @@ -4,7 +4,6 @@ use Cake\Datasource\EntityInterface; use Cake\ORM\Entity; use Cake\ORM\Locator\LocatorAwareTrait; -use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; use JeremyHarris\LazyLoad\TestApp\Model\Entity\Comment; use JeremyHarris\LazyLoad\TestApp\Model\Entity\LazyLoadableEntity; @@ -27,12 +26,12 @@ class LazyLoadEntityTraitTest extends TestCase * @var array */ public $fixtures = [ - 'plugin.JeremyHarris\LazyLoad.articles', - 'plugin.JeremyHarris\LazyLoad.articles_tags', - 'plugin.JeremyHarris\LazyLoad.authors', - 'plugin.JeremyHarris\LazyLoad.comments', - 'plugin.JeremyHarris\LazyLoad.tags', - 'plugin.JeremyHarris\LazyLoad.users', + 'plugin.JeremyHarris\LazyLoad.Articles', + 'plugin.JeremyHarris\LazyLoad.ArticlesTags', + 'plugin.JeremyHarris\LazyLoad.Authors', + 'plugin.JeremyHarris\LazyLoad.Comments', + 'plugin.JeremyHarris\LazyLoad.Tags', + 'plugin.JeremyHarris\LazyLoad.Users', ]; /** @@ -40,7 +39,7 @@ class LazyLoadEntityTraitTest extends TestCase * * @return void */ - public function setUp() + public function setUp(): void { parent::setUp(); From 16cb699d3bdfaa524229a8842c659669b74e160f Mon Sep 17 00:00:00 2001 From: Jason Horvath Date: Wed, 19 Feb 2020 15:01:38 -0500 Subject: [PATCH 05/12] phpunit.result.cache --- .phpunit.result.cache | 1 - .vscode/launch.json | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) delete mode 100644 .phpunit.result.cache create mode 100644 .vscode/launch.json diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index b9be881..0000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":2383:{a:2:{s:7:"defects";a:3:{s:84:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testEntityMethodGet";i:6;s:80:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testEmptySource";i:4;s:93:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testDontInterfereWithContain";i:6;}s:5:"times";a:20:{s:99:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testFormatResultsNonExistentRecord";d:0.376;s:88:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testNullableAssociation";d:0.01;s:86:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testMissingPrimaryKey";d:0.005;s:84:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testTablelessEntity";d:0.002;s:82:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testUnsetProperty";d:0.081;s:93:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testUnsetEagerLoadedProperty";d:0.007;s:85:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testHasLazyLoadsOnce";d:0.01;s:85:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testGetLazyLoadsOnce";d:0.007;s:80:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testGetAccessor";d:0.004;s:72:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testGet";d:0.004;s:84:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testEntityMethodGet";d:0.026;s:80:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testEmptySource";d:0.004;s:81:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testDeepLazyLoad";d:0.027;s:77:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testLazyLoad";d:0.02;s:72:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testHas";d:0.012;s:77:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testHasArray";d:0.009;s:93:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testDontInterfereWithContain";d:0.004;s:83:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testDuplicateTrait";d:0.013;s:112:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testByRefArrayFunctionsWorkOnNormalCakeEntities";d:0.01;s:114:"JeremyHarris\LazyLoad\Test\TestCase\ORM\LazyLoadEntityTraitTest::testByRefArrayFunctionsWorkOnLazyLoadCakeEntities";d:0.009;}}} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2fb6719 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "HCP Core XDebug", + "type": "php", + "request": "launch", + "port": 9000, + "pathMappings": { + "/mnt/c/www": "c:/www" + }, + "xdebugSettings": { + "max_children": 128, + "max_data": 4096, + "max_depth": 5 + } + } + ] +} From 91c9c9e724c444077f57192932e10bae250f99df Mon Sep 17 00:00:00 2001 From: Jason Horvath Date: Wed, 19 Feb 2020 15:03:03 -0500 Subject: [PATCH 06/12] removing vscode folder, woops! --- .vscode/launch.json | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 2fb6719..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - - { - "name": "HCP Core XDebug", - "type": "php", - "request": "launch", - "port": 9000, - "pathMappings": { - "/mnt/c/www": "c:/www" - }, - "xdebugSettings": { - "max_children": 128, - "max_data": 4096, - "max_depth": 5 - } - } - ] -} From 765e5ccbcecb00931a3ba659b2157b138abccdfe Mon Sep 17 00:00:00 2001 From: Jason Horvath Date: Wed, 19 Feb 2020 15:04:48 -0500 Subject: [PATCH 07/12] return type and ignore updates --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index abb9c75..c535968 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /vendor /composer.lock /phpunit.xml +/.phpunit.result.cache +/.vscode From 6692cfd311ea0ee3ca1ae15d1a86a6a613e026b3 Mon Sep 17 00:00:00 2001 From: Jason Horvath Date: Wed, 19 Feb 2020 15:30:53 -0500 Subject: [PATCH 08/12] update source check to look for empty, not null, empty string is not returned --- src/ORM/LazyLoadEntityTrait.php | 2 +- tests/TestCase/ORM/LazyLoadEntityTraitTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ORM/LazyLoadEntityTrait.php b/src/ORM/LazyLoadEntityTrait.php index 137bcfe..0068b54 100644 --- a/src/ORM/LazyLoadEntityTrait.php +++ b/src/ORM/LazyLoadEntityTrait.php @@ -150,7 +150,7 @@ protected function _lazyLoad($property) protected function _repository() { $source = $this->getSource(); - if ($source === null) { + if (empty($source)) { list(, $class) = namespaceSplit(get_class($this)); $source = Inflector::pluralize($class); } diff --git a/tests/TestCase/ORM/LazyLoadEntityTraitTest.php b/tests/TestCase/ORM/LazyLoadEntityTraitTest.php index a87991b..4cd87c7 100644 --- a/tests/TestCase/ORM/LazyLoadEntityTraitTest.php +++ b/tests/TestCase/ORM/LazyLoadEntityTraitTest.php @@ -258,7 +258,7 @@ public function testEntityMethodGet() { $article = $this->Articles->get(1); $comments = $article->comments; - $this->assertInternalType('array', $comments); + $this->assertIsArray($comments); $this->assertCount(4, $comments); $this->assertInstanceOf(\Cake\Datasource\EntityInterface::class, $comments[0]); } From 716f8a50bda93c6a9aacb89101710c5377eaffb2 Mon Sep 17 00:00:00 2001 From: Jason Horvath Date: Wed, 19 Feb 2020 15:51:58 -0500 Subject: [PATCH 09/12] fixed unit test warning to use addMethods --- tests/TestCase/ORM/LazyLoadEntityTraitTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/TestCase/ORM/LazyLoadEntityTraitTest.php b/tests/TestCase/ORM/LazyLoadEntityTraitTest.php index 4cd87c7..1ecf704 100644 --- a/tests/TestCase/ORM/LazyLoadEntityTraitTest.php +++ b/tests/TestCase/ORM/LazyLoadEntityTraitTest.php @@ -357,7 +357,10 @@ public function testHasArray() */ public function testDontInterfereWithContain() { - $this->Articles = $this->getMockForModel('Articles', ['_lazyLoad'], ['table' => 'articles']); + $this->Articles = $this->getMockBuilder(ArticlesTable::class) + ->addMethods(['_lazyLoad']) + ->setConstructorArgs([['table' => 'articles']]) + ->getMock(); $this->Articles->belongsTo('Authors'); $this->Articles From 22565806775d8b4cffc1736c68beb23c650d05bf Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Thu, 20 Feb 2020 09:31:50 -0600 Subject: [PATCH 10/12] Removed syntaxCheck from phpunit xml --- phpunit.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 90dce14..05b40ff 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,6 @@ colors="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > From 88f8273679c25c1990fb8ac03b24c3021bad19e1 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Thu, 20 Feb 2020 09:32:14 -0600 Subject: [PATCH 11/12] Updated travis to test php 7.2-7.4 --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b354a79..43eb807 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: php php: - - 5.6 - - 7.0 - - 7.1 + - 7.2 + - 7.3 + - 7.4 sudo: false @@ -15,7 +15,7 @@ env: matrix: fast_finish: true include: - - php: 7.0 + - php: 7.2 env: COVERAGE=1 install: From 202bce1e0bac89786a818d0870a008c6915d17e7 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Thu, 20 Feb 2020 09:41:55 -0600 Subject: [PATCH 12/12] Updated travis yaml --- .travis.yml | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 43eb807..57742af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: php +services: + - postgresql + - mysql + php: - 7.2 - 7.3 @@ -8,32 +12,23 @@ php: sudo: false env: - - DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test' - - DB=pgsql db_dsn='postgres://travis@127.0.0.1/cakephp_test' - - DB=sqlite + matrix: + - DB=mysql DB_DSN='mysql://root@127.0.0.1/cakephp_test' + - DB=pgsql DB_DSN='postgres://postgres@127.0.0.1/cakephp_test' + - DB=sqlite DB_DSN='sqlite:///:memory:' matrix: fast_finish: true - include: - - php: 7.2 - env: COVERAGE=1 + +before_install: + - if [[ $DB == 'mysql' ]]; then mysql -u root -e 'CREATE DATABASE cakephp_test;'; fi + - if [[ $DB == 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi install: - - composer self-update - composer install --prefer-dist --no-interaction -before_script: - - if [[ $DB == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi - - if [[ $DB == 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi - - phpenv rehash - - set +H - script: - - if [[ $COVERAGE == 1 ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - - if [[ $COVERAGE != 1 ]]; then vendor/bin/phpunit; fi - -after_success: - - if [[ $COVERAGE == 1 ]]; then bash <(curl -s https://codecov.io/bash); fi + - vendor/bin/phpunit notifications: email: false