Skip to content

Commit

Permalink
Merge pull request #20 from jeremyharris/3.next
Browse files Browse the repository at this point in the history
Replaced deprecated methods
  • Loading branch information
jeremyharris authored Apr 16, 2018
2 parents 7e1bcc1 + 754cae3 commit 766dbbe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions src/ORM/LazyLoadEntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand All @@ -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);
}
}
33 changes: 18 additions & 15 deletions tests/TestCase/ORM/LazyLoadEntityTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +19,8 @@
class LazyLoadEntityTraitTest extends TestCase
{

use LocatorAwareTrait;

/**
* Fixtures
*
Expand All @@ -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', [
Expand All @@ -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;
Expand Down Expand Up @@ -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'
]);
Expand Down Expand Up @@ -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'
]);
Expand Down Expand Up @@ -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'
]);
Expand All @@ -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'
]);
Expand Down Expand Up @@ -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'
]);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'
]);
Expand All @@ -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);
Expand Down Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);

0 comments on commit 766dbbe

Please sign in to comment.