Skip to content
This repository was archived by the owner on Jul 7, 2022. It is now read-only.

Commit 13ac90f

Browse files
authored
Merge pull request #54 from AD7six/deprecations
Fix deprecation errors.
2 parents 3e20e23 + 480a77b commit 13ac90f

File tree

5 files changed

+37
-19
lines changed

5 files changed

+37
-19
lines changed

.travis.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ language: php
22

33
php:
44
- 5.6
5-
- 7.0
6-
- 7.1
75
- 7.2
6+
- 7.3
7+
- '7.4snapshot'
8+
9+
services:
10+
- postgresql
11+
- mysql
812

913
env:
1014
matrix:
@@ -21,31 +25,29 @@ matrix:
2125
- php: 5.6
2226
env: PREFER_LOWEST=1 DB=mysql db_dsn='mysql://[email protected]/cakephp_test'
2327

24-
- php: 7.1
28+
- php: 7.2
2529
env: PHPCS=1 DEFAULT=0
2630

27-
- php: 7.1
31+
- php: 7.2
2832
env: PHPSTAN=1 DEFAULT=0
2933

3034
before_script:
31-
- phpenv config-rm xdebug.ini
32-
3335
- if [[ $PREFER_LOWEST != 1 ]]; then composer install --no-interaction --prefer-source; fi
3436
- if [[ $PREFER_LOWEST = 1 ]]; then composer update --no-interaction --prefer-source --prefer-lowest --prefer-stable; fi
3537

3638
- if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
3739
- if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
3840

3941
script:
40-
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.1 ]]; then vendor/bin/phpunit; fi
41-
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=clover.xml; fi
42+
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi
43+
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=clover.xml; fi
4244

4345
- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p -n --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
4446

45-
- if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:^0.9 && vendor/bin/phpstan analyse -l 5 src; fi
47+
- if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:^0.11 && vendor/bin/phpstan analyse src; fi
4648

4749
after_success:
48-
- if [[ $DEFAULT = 1 && $DB = 'mysql' && $TRAVIS_PHP_VERSION = 7.1 ]]; then bash <(curl -s https://codecov.io/bash); fi
50+
- if [[ $DEFAULT = 1 && $DB = 'mysql' && $TRAVIS_PHP_VERSION = 7.2 ]]; then bash <(curl -s https://codecov.io/bash); fi
4951

5052
notifications:
5153
email: false

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 5
3+
ignoreErrors:
4+
-
5+
message: "#^Call to function method_exists\\(\\) with 'Cake\\\\\\\\ORM\\\\\\\\Entity' and 'getVisible' will always evaluate to false\\.$#"
6+
count: 1
7+
path: src/Model/Behavior/ShadowTranslateBehavior.php

src/Model/Behavior/ShadowTranslateBehavior.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Cake\Event\Event;
88
use Cake\I18n\I18n;
99
use Cake\ORM\Behavior\TranslateBehavior;
10+
use Cake\ORM\Entity;
1011
use Cake\ORM\Query;
1112
use Cake\ORM\Table;
1213
use Cake\ORM\TableRegistry;
@@ -16,6 +17,13 @@
1617
*/
1718
class ShadowTranslateBehavior extends TranslateBehavior
1819
{
20+
/**
21+
* Method to use to get visible properties
22+
*
23+
* @var string
24+
*/
25+
protected $_visiblePropertiesMethod = 'visibleProperties';
26+
1927
/**
2028
* Constructor
2129
*
@@ -44,6 +52,10 @@ public function __construct(Table $table, array $config = [])
4452
'hasOneAlias' => $tableAlias . 'Translation',
4553
];
4654

55+
if (method_exists(Entity::class, 'getVisible')) {
56+
$this->_visiblePropertiesMethod = 'getVisible';
57+
}
58+
4759
parent::__construct($table, $config);
4860
}
4961

@@ -457,7 +469,7 @@ protected function _rowMapper($results, $locale)
457469

458470
$translation = $row['translation'];
459471

460-
$keys = $hydrated ? $translation->visibleProperties() : array_keys($translation);
472+
$keys = $hydrated ? $translation->{$this->_visiblePropertiesMethod}() : array_keys($translation);
461473

462474
foreach ($keys as $field) {
463475
if ($field === 'locale') {

tests/TestCase/Model/Behavior/ShadowTranslateBehaviorTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ class ShadowTranslateBehaviorTest extends TranslateBehaviorTest
1414
{
1515
public $fixtures = [
1616
'core.Articles',
17-
'core.Authors',
18-
'core.Comments',
19-
'core.Tags',
2017
'core.ArticlesTags',
21-
'core.SpecialTags',
18+
'core.Authors',
2219
'core.Groups',
20+
'core.SpecialTags',
21+
'core.Tags',
22+
'core.Comments',
23+
'core.Translates',
2324
'plugin.ShadowTranslate.ArticlesTranslations',
2425
'plugin.ShadowTranslate.ArticlesMoreTranslations',
2526
'plugin.ShadowTranslate.AuthorsTranslations',

tests/bootstrap.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,3 @@
3131
}
3232

3333
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';
34-
35-
Plugin::load('ShadowTranslate', [
36-
'path' => dirname(dirname(__FILE__)) . DS
37-
]);

0 commit comments

Comments
 (0)