Skip to content

Commit 2740d33

Browse files
Merge pull request #7 from infoseci/cake-deprecations
Fix various deprecations for newer versions of Cake.
2 parents c32ba5b + 370a7ed commit 2740d33

File tree

9 files changed

+42
-36
lines changed

9 files changed

+42
-36
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ dist: trusty
55
sudo: false
66

77
php:
8-
- 5.5
98
- 5.6
109
- 7.0
1110
- 7.1
12-
11+
1312
env:
1413
global:
1514
- DEFAULT=1
@@ -20,11 +19,9 @@ matrix:
2019
include:
2120
- php: 5.6
2221
env: PHPCS=1 DEFAULT=0
23-
- php: 7.1
24-
env: PHPSTAN=4 DEFAULT=0
2522
- php: 7.1
2623
env: PHPSTAN=5 DEFAULT=0
27-
24+
2825
allow_failures:
2926
- env: PHPSTAN=5 DEFAULT=0
3027

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"type": "cakephp-plugin",
66
"license": "MIT",
77
"require": {
8-
"php": ">=5.5.9",
9-
"cakephp/orm": "~3.2"
8+
"php": ">=5.6",
9+
"cakephp/orm": "~3.5"
1010
},
1111
"require-dev": {
12-
"php": ">=5.5",
12+
"php": ">=5.6",
1313
"phpunit/phpunit": "<6.0",
14-
"cakephp/cakephp": "~3.2.0",
14+
"cakephp/cakephp": "~3.5",
1515
"cakephp/cakephp-codesniffer": "@stable"
1616
},
1717
"autoload": {

src/Model/Behavior/MatchesTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait MatchesTrait
1313
/**
1414
* Checks rules match.
1515
*
16-
* @param type $subject Subject
16+
* @param string $subject Subject
1717
* @param array $rules Rules list
1818
* @return bool
1919
*/

src/Model/Behavior/StiBehavior.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class StiBehavior extends Behavior
5454
public function initialize(array $config)
5555
{
5656
if ($this->_config['table'] !== null) {
57-
$this->_table->table($this->_config['table']);
57+
$this->_table->setTable($this->_config['table']);
5858
}
5959
if ($this->_config['discriminator'] !== null) {
6060
$this->setDiscriminator($this->_config['discriminator']);
@@ -86,7 +86,7 @@ public function discriminator($discriminator = null)
8686
public function getDiscriminator()
8787
{
8888
if ($this->_discriminator === null) {
89-
$this->_discriminator = $this->_table->alias();
89+
$this->_discriminator = $this->_table->getAlias();
9090
}
9191

9292
return $this->_discriminator;
@@ -223,7 +223,7 @@ public function checkRules(EntityInterface $entity)
223223
{
224224
$field = $this->_config['discriminatorField'];
225225

226-
if ($entity->dirty($field)) {
226+
if ($entity->isDirty($field)) {
227227
return $this->_matches($entity->get($field), $this->acceptedDiscriminators());
228228
}
229229

src/Model/Behavior/StiParentBehavior.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function addStiTable($discriminator, $table)
9292
$alias = $table;
9393
}
9494

95-
$table = $this->tableLocator()->get($alias, $options);
95+
$table = $this->getTableLocator()->get($alias, $options);
9696
}
9797

9898
$this->_childTables[$discriminator] = $table;
@@ -124,20 +124,20 @@ public function newStiEntity($data = null, array $options = [])
124124
*/
125125
public function beforeFind(Event $event, Query $query, ArrayAccess $options)
126126
{
127-
if (!$query->hydrate()) {
127+
if (!$query->isHydrationEnabled()) {
128128
return;
129129
}
130130
$query->formatResults(function ($results) {
131131
return $results->map(function ($row) {
132132
if ($row instanceof CopyableEntityInterface) {
133133
$table = $this->stiTable($row);
134-
$entityClass = $table->entityClass();
134+
$entityClass = $table->getEntityClass();
135135

136136
$row = new $entityClass($row->copyProperties(), [
137137
'markNew' => $row->isNew(),
138138
'markClean' => true,
139139
'guard' => false,
140-
'source' => $table->registryAlias()
140+
'source' => $table->getRegistryAlias()
141141
]);
142142
}
143143

src/Plugin.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Robotusers\TableInheritance;
4+
5+
use Cake\Core\BasePlugin;
6+
7+
class Plugin extends BasePlugin
8+
{
9+
}

tests/TestCase/Model/Behavior/StiBehaviorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class StiBehaviorTest extends TestCase
1414
{
1515
public $fixtures = [
16-
'plugin.Robotusers\TableInheritance.users'
16+
'plugin.Robotusers\TableInheritance.Users'
1717
];
1818

1919
public function tearDown()
@@ -74,7 +74,7 @@ public function testSave()
7474
]);
7575
$table->save($entity);
7676

77-
$this->assertEmpty($entity->errors());
77+
$this->assertEmpty($entity->getErrors());
7878
$this->assertEquals('Authors', $entity->discriminator);
7979

8080
$entity2 = $table->newEntity([
@@ -83,7 +83,7 @@ public function testSave()
8383
]);
8484
$table->save($entity2);
8585

86-
$this->assertArrayHasKey('discriminator', $entity2->errors());
86+
$this->assertArrayHasKey('discriminator', $entity2->getErrors());
8787
$this->assertEquals('Editors', $entity2->discriminator);
8888
}
8989

@@ -102,7 +102,7 @@ public function testSaveNoRules()
102102
]);
103103
$table->save($entity);
104104

105-
$this->assertEmpty($entity->errors());
105+
$this->assertEmpty($entity->getErrors());
106106
$this->assertEquals('Editors', $entity->discriminator);
107107
}
108108

@@ -121,7 +121,7 @@ public function testSaveWildcard()
121121
]);
122122
$table->save($entity);
123123

124-
$this->assertEmpty($entity->errors());
124+
$this->assertEmpty($entity->getErrors());
125125
$this->assertEquals('author_foo', $entity->discriminator);
126126
}
127127

tests/TestCase/Model/Behavior/StiParentBehaviorTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class StiParentBehaviorTest extends TestCase
1818
{
1919
public $fixtures = [
20-
'plugin.Robotusers\TableInheritance.users'
20+
'plugin.Robotusers\TableInheritance.Users'
2121
];
2222

2323
/**
@@ -39,16 +39,16 @@ public function setUp()
3939
'' => User::class
4040
];
4141

42-
$this->table = TableRegistry::get('Users');
43-
$this->table->entityClass(User::class);
42+
$this->table = TableRegistry::getTableLocator()->get('Users');
43+
$this->table->setEntityClass(User::class);
4444

45-
$authors = TableRegistry::get('Authors', [
45+
$authors = TableRegistry::getTableLocator()->get('Authors', [
4646
'table' => 'users'
4747
]);
48-
$editors = TableRegistry::get('Editors', [
48+
$editors = TableRegistry::getTableLocator()->get('Editors', [
4949
'table' => 'users'
5050
]);
51-
$readers = TableRegistry::get('Readers', [
51+
$readers = TableRegistry::getTableLocator()->get('Readers', [
5252
'table' => 'users'
5353
]);
5454

@@ -68,18 +68,18 @@ public function setUp()
6868
]
6969
]);
7070

71-
$authors->entityClass(Author::class);
72-
$editors->entityClass(Editor::class);
73-
$readers->entityClass(Reader::class);
71+
$authors->setEntityClass(Author::class);
72+
$editors->setEntityClass(Editor::class);
73+
$readers->setEntityClass(Reader::class);
7474
}
7575

7676
public function testStiTable()
7777
{
78-
$this->table->behaviors()->get('StiParent')->config('tableMap', [
78+
$this->table->behaviors()->get('StiParent')->setConfig('tableMap', [
7979
'Readers' => 'reader_*'
8080
], false);
81-
$this->table->behaviors()->get('StiParent')->config('discriminatorMap', [
82-
'*author' => TableRegistry::get('Authors')
81+
$this->table->behaviors()->get('StiParent')->setConfig('discriminatorMap', [
82+
'*author' => TableRegistry::getTableLocator()->get('Authors')
8383
], false);
8484

8585
$map = [
@@ -96,7 +96,7 @@ public function testStiTable()
9696
'discriminator' => $discriminator
9797
]);
9898
$table = $this->table->stiTable($entity);
99-
$this->assertEquals($alias, $table->alias());
99+
$this->assertEquals($alias, $table->getAlias());
100100
}
101101
}
102102

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727

2828
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';
2929

30-
\Cake\Core\Plugin::load('Robotusers/TableInheritance', ['path' => dirname(dirname(__FILE__)) . DS]);
30+
\Cake\Core\Plugin::getCollection()->add(new \Robotusers\TableInheritance\Plugin());

0 commit comments

Comments
 (0)