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 diff --git a/.travis.yml b/.travis.yml index b354a79..57742af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,34 @@ language: php +services: + - postgresql + - mysql + php: - - 5.6 - - 7.0 - - 7.1 + - 7.2 + - 7.3 + - 7.4 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.0 - 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 diff --git a/composer.json b/composer.json index e2349ee..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": ">=3.6.0 <4.0" + "cakephp/cakephp": "^4.0" }, "require": { - "cakephp/orm": ">=3.6.0 <4.0" + "cakephp/orm": "^4.0" }, "autoload": { "psr-4": { 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" > diff --git a/src/ORM/LazyLoadEntityTrait.php b/src/ORM/LazyLoadEntityTrait.php index d176fd8..0068b54 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); @@ -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]; } /** @@ -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 40a8e9b..1ecf704 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(); @@ -259,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]); } @@ -358,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