From f9d0b86231e3ff6ef09e4dea525bc8e91b780607 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Mon, 26 Mar 2018 15:07:03 -0500 Subject: [PATCH 1/2] Replaced deprecated methods --- src/ORM/LazyLoadEntityTrait.php | 6 ++-- .../TestCase/ORM/LazyLoadEntityTraitTest.php | 33 ++++++++++--------- tests/bootstrap.php | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/ORM/LazyLoadEntityTrait.php b/src/ORM/LazyLoadEntityTrait.php index e3e1d2f..d176fd8 100644 --- a/src/ORM/LazyLoadEntityTrait.php +++ b/src/ORM/LazyLoadEntityTrait.php @@ -132,7 +132,7 @@ protected function _lazyLoad($property) return null; } - $repository->loadInto($this, [$association->name()]); + $repository->loadInto($this, [$association->getName()]); // check if the association didn't exist and therefore didn't load if (!isset($this->_properties[$property])) { @@ -149,12 +149,12 @@ protected function _lazyLoad($property) */ protected function _repository() { - $source = $this->source(); + $source = $this->getSource(); if ($source === null) { list(, $class) = namespaceSplit(get_class($this)); $source = Inflector::pluralize($class); } - return TableRegistry::get($source); + return TableRegistry::getTableLocator()->get($source); } } diff --git a/tests/TestCase/ORM/LazyLoadEntityTraitTest.php b/tests/TestCase/ORM/LazyLoadEntityTraitTest.php index 0a87d4a..40a8e9b 100644 --- a/tests/TestCase/ORM/LazyLoadEntityTraitTest.php +++ b/tests/TestCase/ORM/LazyLoadEntityTraitTest.php @@ -3,6 +3,7 @@ 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; @@ -18,6 +19,8 @@ class LazyLoadEntityTraitTest extends TestCase { + use LocatorAwareTrait; + /** * Fixtures * @@ -41,8 +44,8 @@ public function setUp() { parent::setUp(); - $this->Articles = TableRegistry::get('Articles'); - $this->Articles->entityClass(LazyLoadableEntity::class); + $this->Articles = $this->getTableLocator()->get('Articles'); + $this->Articles->setEntityClass(LazyLoadableEntity::class); $this->Articles->belongsTo('Authors'); $this->Articles->hasMany('Comments'); $this->Articles->belongsToMany('Tags', [ @@ -57,7 +60,7 @@ public function setUp() */ public function testFormatResultsNonExistentRecord() { - $this->Articles->Authors->eventManager() + $this->Articles->Authors->getEventManager() ->on('Model.beforeFind', function ($event, $query) { $query->formatResults(function ($resultSet) { return $resultSet; @@ -86,7 +89,7 @@ public function testNullableAssociation() */ public function testMissingPrimaryKey() { - $this->Comments = TableRegistry::get('Comments'); + $this->Comments = $this->getTableLocator()->get('Comments'); $this->Comments->belongsTo('Authors', [ 'foreignKey' => 'user_id' ]); @@ -116,7 +119,7 @@ public function testTablelessEntity() */ public function testUnsetProperty() { - $this->Comments = TableRegistry::get('Comments'); + $this->Comments = $this->getTableLocator()->get('Comments'); $this->Comments->belongsTo('Authors', [ 'foreignKey' => 'user_id' ]); @@ -148,8 +151,8 @@ public function testUnsetProperty() */ public function testUnsetEagerLoadedProperty() { - $this->Comments = TableRegistry::get('Comments'); - $this->Comments->entityClass(LazyLoadableEntity::class); + $this->Comments = $this->getTableLocator()->get('Comments'); + $this->Comments->setEntityClass(LazyLoadableEntity::class); $this->Comments->belongsTo('Authors', [ 'foreignKey' => 'user_id' ]); @@ -170,7 +173,7 @@ public function testUnsetEagerLoadedProperty() */ public function testHasLazyLoadsOnce() { - $this->Comments = TableRegistry::get('Comments'); + $this->Comments = $this->getTableLocator()->get('Comments'); $this->Comments->belongsTo('Authors', [ 'foreignKey' => 'user_id' ]); @@ -198,7 +201,7 @@ public function testHasLazyLoadsOnce() */ public function testGetLazyLoadsOnce() { - $this->Comments = TableRegistry::get('Comments'); + $this->Comments = $this->getTableLocator()->get('Comments'); $this->Comments->belongsTo('Authors', [ 'foreignKey' => 'user_id' ]); @@ -228,8 +231,8 @@ public function testGetLazyLoadsOnce() */ public function testGetAccessor() { - $this->Comments = TableRegistry::get('Comments'); - $this->Comments->entityClass(Comment::class); + $this->Comments = $this->getTableLocator()->get('Comments'); + $this->Comments->setEntityClass(Comment::class); $comment = $this->Comments->get(1); $this->assertEquals('accessor', $comment->accessor); @@ -269,7 +272,7 @@ public function testEntityMethodGet() */ public function testEmptySource() { - $this->Comments = TableRegistry::get('Comments'); + $this->Comments = $this->getTableLocator()->get('Comments'); $this->Comments->belongsTo('Authors', [ 'foreignKey' => 'user_id' ]); @@ -287,8 +290,8 @@ public function testEmptySource() */ public function testDeepLazyLoad() { - $this->Comments = TableRegistry::get('Comments'); - $this->Comments->entityClass(LazyLoadableEntity::class); + $this->Comments = $this->getTableLocator()->get('Comments'); + $this->Comments->setEntityClass(LazyLoadableEntity::class); $this->Comments->belongsTo('Users'); $article = $this->Articles->get(1); @@ -380,7 +383,7 @@ public function testDuplicateTrait() // php 5.6 complains when classes are composed as such $this->skipIf(version_compare(PHP_VERSION, '7.0.0', '<')); - $this->Users = TableRegistry::get('Users'); + $this->Users = $this->getTableLocator()->get('Users'); $this->Users->setEntityClass(User::class); $this->Users->hasMany('Comments'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 83c6324..40e256f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -41,7 +41,7 @@ putenv('db_dsn=sqlite://127.0.0.0/' . TMP . 'cakephp-lazyload.sqlite'); } -ConnectionManager::config('test', [ +ConnectionManager::setConfig('test', [ 'url' => getenv('db_dsn'), 'timezone' => 'UTC', ]); From 754cae3cf7e7d0665dc9c65402df77888472ec61 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Mon, 16 Apr 2018 09:43:58 -0500 Subject: [PATCH 2/2] Upgraded deps --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ae9463e..e2349ee 100644 --- a/composer.json +++ b/composer.json @@ -8,10 +8,10 @@ "require-dev": { "phpunit/phpunit": "^5.7|^6.0", "cakephp/cakephp-codesniffer": "dev-master", - "cakephp/cakephp": ">=3.1.0 <4.0" + "cakephp/cakephp": ">=3.6.0 <4.0" }, "require": { - "cakephp/orm": ">=3.1.0 <4.0" + "cakephp/orm": ">=3.6.0 <4.0" }, "autoload": { "psr-4": {