Skip to content

Commit e3fdd5f

Browse files
committed
Merge branch 'master' of github.com:jeremyharris/cakephp-lazyload
2 parents 3db6c27 + 308560f commit e3fdd5f

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/ORM/LazyLoadEntityTrait.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace JeremyHarris\LazyLoad\ORM;
33

44
use Cake\Datasource\RepositoryInterface;
5+
use Cake\ORM\Entity;
56
use Cake\ORM\Table;
67
use Cake\ORM\TableRegistry;
78
use Cake\Utility\Inflector;
@@ -48,7 +49,7 @@ public function &get($property)
4849
*/
4950
protected function &_parentGet($property)
5051
{
51-
return parent::get($property);
52+
return Entity::get($property);
5253
}
5354

5455
/**
@@ -81,7 +82,7 @@ public function has($property)
8182
*/
8283
protected function _parentHas($property)
8384
{
84-
return parent::has($property);
85+
return Entity::has($property);
8586
}
8687

8788
/**
@@ -96,7 +97,8 @@ public function unsetProperty($property)
9697
foreach ($property as $prop) {
9798
$this->_unsetProperties[] = $prop;
9899
}
99-
return parent::unsetProperty($property);
100+
101+
return Entity::unsetProperty($property);
100102
}
101103

102104
/**

tests/TestCase/ORM/LazyLoadEntityTraitTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use JeremyHarris\LazyLoad\TestApp\Model\Entity\Comment;
88
use JeremyHarris\LazyLoad\TestApp\Model\Entity\LazyLoadableEntity;
99
use JeremyHarris\LazyLoad\TestApp\Model\Entity\TablelessEntity;
10+
use JeremyHarris\LazyLoad\TestApp\Model\Entity\User;
1011

1112
/**
1213
* LazyLoadEntityTrait test
@@ -362,4 +363,25 @@ public function testDontInterfereWithContain()
362363

363364
$this->assertEquals('mariano', $article->author->name);
364365
}
366+
367+
/**
368+
* test that checks that we don't get an infinite loop when including the trait twice
369+
*
370+
* User extends LazyLoadableEntity, uses Trait
371+
* LazyLoadableEntity uses Trait
372+
*
373+
* @return void
374+
*/
375+
public function testDuplicateTrait()
376+
{
377+
// php 5.6 complains when classes are composed as such
378+
$this->skipIf(version_compare(PHP_VERSION, '7.0.0', '<'));
379+
380+
$this->Users = TableRegistry::get('Users');
381+
$this->Users->setEntityClass(User::class);
382+
$this->Users->hasMany('Comments');
383+
384+
$user = $this->Users->get(1);
385+
$this->assertTrue($user->has('comments'));
386+
}
365387
}

tests/test_app/Model/Entity/User.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace JeremyHarris\LazyLoad\TestApp\Model\Entity;
3+
4+
use JeremyHarris\LazyLoad\ORM\LazyLoadEntityTrait;
5+
6+
class User extends LazyLoadableEntity
7+
{
8+
// to test including the trait twice
9+
use LazyLoadEntityTrait;
10+
11+
protected function _getAccessor()
12+
{
13+
return 'accessor';
14+
}
15+
}

0 commit comments

Comments
 (0)