Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cake 4.x EntityTrait _properties changed to _fields #24

Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor
/composer.lock
/phpunit.xml
/.phpunit.result.cache
/.vscode
37 changes: 16 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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://[email protected]/cakephp_test'
- DB=pgsql db_dsn='postgres://[email protected]/cakephp_test'
- DB=sqlite
matrix:
- DB=mysql DB_DSN='mysql://[email protected]/cakephp_test'
- DB=pgsql DB_DSN='postgres://[email protected]/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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>

Expand Down
12 changes: 6 additions & 6 deletions src/ORM/LazyLoadEntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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];
}

/**
Expand All @@ -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);
}
Expand Down
22 changes: 12 additions & 10 deletions tests/TestCase/ORM/LazyLoadEntityTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,20 +26,20 @@ 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',
];

/**
* setUp
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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
Expand Down