File tree 3 files changed +42
-3
lines changed
3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change 2
2
namespace JeremyHarris \LazyLoad \ORM ;
3
3
4
4
use Cake \Datasource \RepositoryInterface ;
5
+ use Cake \ORM \Entity ;
5
6
use Cake \ORM \Table ;
6
7
use Cake \ORM \TableRegistry ;
7
8
use Cake \Utility \Inflector ;
@@ -48,7 +49,7 @@ public function &get($property)
48
49
*/
49
50
protected function &_parentGet ($ property )
50
51
{
51
- return parent ::get ($ property );
52
+ return Entity ::get ($ property );
52
53
}
53
54
54
55
/**
@@ -81,7 +82,7 @@ public function has($property)
81
82
*/
82
83
protected function _parentHas ($ property )
83
84
{
84
- return parent ::has ($ property );
85
+ return Entity ::has ($ property );
85
86
}
86
87
87
88
/**
@@ -96,7 +97,8 @@ public function unsetProperty($property)
96
97
foreach ($ property as $ prop ) {
97
98
$ this ->_unsetProperties [] = $ prop ;
98
99
}
99
- return parent ::unsetProperty ($ property );
100
+
101
+ return Entity::unsetProperty ($ property );
100
102
}
101
103
102
104
/**
Original file line number Diff line number Diff line change 7
7
use JeremyHarris \LazyLoad \TestApp \Model \Entity \Comment ;
8
8
use JeremyHarris \LazyLoad \TestApp \Model \Entity \LazyLoadableEntity ;
9
9
use JeremyHarris \LazyLoad \TestApp \Model \Entity \TablelessEntity ;
10
+ use JeremyHarris \LazyLoad \TestApp \Model \Entity \User ;
10
11
11
12
/**
12
13
* LazyLoadEntityTrait test
@@ -362,4 +363,25 @@ public function testDontInterfereWithContain()
362
363
363
364
$ this ->assertEquals ('mariano ' , $ article ->author ->name );
364
365
}
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
+ }
365
387
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments