From 5e887fd2e4cf89fe645e3841509f3c459c89004c Mon Sep 17 00:00:00 2001 From: arilia Date: Tue, 24 Apr 2018 11:15:01 +0200 Subject: [PATCH 01/11] deprecations --- src/Model/Behavior/VersionBehavior.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Model/Behavior/VersionBehavior.php b/src/Model/Behavior/VersionBehavior.php index 0eb5da6..d892d3b 100644 --- a/src/Model/Behavior/VersionBehavior.php +++ b/src/Model/Behavior/VersionBehavior.php @@ -160,14 +160,14 @@ public function versionAssociation($field = null, $options = []) public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options) { $association = $this->versionAssociation(); - $name = $association->name(); + $name = $association->getName(); $newOptions = [$name => ['validate' => false]]; $options['associated'] = $newOptions + $options['associated']; $fields = $this->_fields(); $values = $entity->extract($fields, $this->_config['onlyDirty']); - $primaryKey = (array)$this->_table->primaryKey(); + $primaryKey = (array)$this->_table->getPrimaryKey(); $versionField = $this->_config['versionField']; if (isset($options['versionId'])) { @@ -177,7 +177,7 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o } $created = new DateTime(); $new = []; - $entityClass = TableRegistry::get($this->_config['versionTable'])->entityClass(); + $entityClass = TableRegistry::get($this->_config['versionTable'])->getEntityClass(); foreach ($values as $field => $content) { if (in_array($field, $primaryKey) || $field == $versionField) { continue; @@ -203,8 +203,8 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o ]); } - $entity->set($association->property(), $new); - if (!empty($versionField) && in_array($versionField, $this->_table->schema()->columns())) { + $entity->set($association->getProperty(), $new); + if (!empty($versionField) && in_array($versionField, $this->_table->getSchema()->columns())) { $entity->set($this->_config['versionField'], $versionId); } } @@ -218,7 +218,7 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o */ public function afterSave(Event $event, EntityInterface $entity) { - $property = $this->versionAssociation()->property(); + $property = $this->versionAssociation()->getProperty(); $entity->unsetProperty($property); } @@ -238,7 +238,7 @@ public function getVersionId(EntityInterface $entity) ] + $this->_extractForeignKey($entity)) ->order(['id desc']) ->limit(1) - ->hydrate(false) + ->enableHydration(false) ->toArray(); return Hash::get($preexistent, '0.version_id', 0); @@ -263,7 +263,7 @@ public function getVersionId(EntityInterface $entity) public function findVersions(Query $query, array $options) { $association = $this->versionAssociation(); - $name = $association->name(); + $name = $association->getName(); return $query ->contain([$name => function (Query $q) use ($name, $options, $query) { @@ -295,7 +295,7 @@ public function findVersions(Query $query, array $options) */ public function groupVersions($results) { - $property = $this->versionAssociation()->property(); + $property = $this->versionAssociation()->getProperty(); return $results->map(function (EntityInterface $row) use ($property) { $versionField = $this->_config['versionField']; @@ -304,7 +304,7 @@ public function groupVersions($results) $result = []; foreach ($grouped->combine('field', 'content', 'version_id') as $versionId => $keys) { - $entityClass = $this->_table->entityClass(); + $entityClass = $this->_table->getEntityClass(); $versionData = [ $versionField => $versionId ]; @@ -371,7 +371,7 @@ public function getVersions(EntityInterface $entity) */ protected function _fields() { - $schema = $this->_table->schema(); + $schema = $this->_table->getSchema(); $fields = $schema->columns(); if ($this->_config['fields'] !== null) { $fields = array_intersect($fields, (array)$this->_config['fields']); @@ -389,7 +389,7 @@ protected function _fields() protected function _extractForeignKey($entity) { $foreignKey = (array)$this->_config['foreignKey']; - $primaryKey = (array)$this->_table->primaryKey(); + $primaryKey = (array)$this->_table->getPrimaryKey(); $pkValue = $entity->extract($primaryKey); return array_combine($foreignKey, $pkValue); From e8c47400579be93a74e3382618d96c7ea48ac034 Mon Sep 17 00:00:00 2001 From: arilia Date: Tue, 24 Apr 2018 15:17:37 +0200 Subject: [PATCH 02/11] removed deprecations --- composer.json | 6 ++-- src/Event/EventListener.php | 2 +- src/Event/VersionListener.php | 3 +- src/Model/Behavior/Version/VersionTrait.php | 2 +- src/Model/Behavior/VersionBehavior.php | 4 +-- .../Model/Behavior/VersionBehaviorTest.php | 28 +++++++++---------- tests/bootstrap.php | 4 +-- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index b6e959a..72ee4bf 100644 --- a/composer.json +++ b/composer.json @@ -13,13 +13,13 @@ ], "require": { "cakephp/orm": "~3.0", - "php": ">=5.5" + "php": ">=5.5", + "satooshi/php-coveralls": "^2.0" }, "require-dev": { "cakephp/cakephp": "~3.0", "phpunit/phpunit": "^4.1 || ^5.0", - "cakephp/cakephp-codesniffer": "dev-master", - "satooshi/php-coveralls": "dev-master" + "cakephp/cakephp-codesniffer": "dev-master" }, "autoload": { "psr-4": { diff --git a/src/Event/EventListener.php b/src/Event/EventListener.php index 80d36a8..c56c2b9 100644 --- a/src/Event/EventListener.php +++ b/src/Event/EventListener.php @@ -24,7 +24,7 @@ abstract class EventListener implements EventListenerInterface public function __construct(CakeEvent $event) { $this->event = $event; - $this->eventManager()->attach($this); + $this->eventManager()->on($this); } /** diff --git a/src/Event/VersionListener.php b/src/Event/VersionListener.php index e9f52df..3a9f4ac 100644 --- a/src/Event/VersionListener.php +++ b/src/Event/VersionListener.php @@ -46,6 +46,7 @@ public function beforeRenderTable(Event $event) { $this->_checkAssociation($event, 'versions'); $this->_fixVersionTables($event); + } /** @@ -79,7 +80,7 @@ protected function _checkAssociation(Event $event, $tableSuffix) { $subject = $event->subject; $connection = ConnectionManager::get($subject->viewVars['connection']); - $schema = $connection->schemaCollection(); + $schema = $connection->getSchemaCollection(); $versionTable = sprintf('%s_%s', Hash::get($event->subject->viewVars, 'table'), $tableSuffix); if (!in_array($versionTable, $schema->listTables())) { diff --git a/src/Model/Behavior/Version/VersionTrait.php b/src/Model/Behavior/Version/VersionTrait.php index 1b36967..8e0479e 100644 --- a/src/Model/Behavior/Version/VersionTrait.php +++ b/src/Model/Behavior/Version/VersionTrait.php @@ -39,7 +39,7 @@ public function versions($reset = false) * @var \Josegonzalez\Version\Model\Behavior\VersionBehavior $table * @var \Cake\Datasource\EntityInterface $this */ - $table = TableRegistry::get($this->source()); + $table = TableRegistry::get($this->getSource()); $versions = $table->getVersions($this); $this->set('_versions', $versions); diff --git a/src/Model/Behavior/VersionBehavior.php b/src/Model/Behavior/VersionBehavior.php index d892d3b..86d3bbe 100644 --- a/src/Model/Behavior/VersionBehavior.php +++ b/src/Model/Behavior/VersionBehavior.php @@ -344,7 +344,7 @@ public function groupVersions($results) */ public function getVersions(EntityInterface $entity) { - $primaryKey = (array)$this->_table->primaryKey(); + $primaryKey = (array)$this->_table->getPrimaryKey(); $query = $this->_table->find('versions'); $pkValue = $entity->extract($primaryKey); @@ -422,7 +422,7 @@ protected function _referenceName() $name = namespaceSplit(get_class($table)); $name = substr(end($name), 0, -5); if (empty($name)) { - $name = $table->table() ?: $table->getAlias(); + $name = $table->getTable() ?: $table->getAlias(); $name = Inflector::camelize($name); } diff --git a/tests/TestCase/Model/Behavior/VersionBehaviorTest.php b/tests/TestCase/Model/Behavior/VersionBehaviorTest.php index 85bfcd9..c3e9b61 100644 --- a/tests/TestCase/Model/Behavior/VersionBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/VersionBehaviorTest.php @@ -53,7 +53,7 @@ public function testSaveNew() $versionTable = TableRegistry::get('Version'); $results = $versionTable->find('all') ->where(['foreign_key' => $article->id]) - ->hydrate(false) + ->enableHydration(false) ->toArray(); $this->assertCount(8, $results); @@ -63,7 +63,7 @@ public function testSaveNew() $versionTable = TableRegistry::get('Version'); $results = $versionTable->find('all') ->where(['foreign_key' => $article->id]) - ->hydrate(false) + ->enableHydration(false) ->toArray(); $this->assertEquals(3, $article->version_id); @@ -166,7 +166,7 @@ public function testSaveLimitFields() $versionTable = TableRegistry::get('Version'); $results = $versionTable->find('all') ->where(['foreign_key' => $article->id, 'version_id' => 3]) - ->hydrate(false) + ->enableHydration(false) ->toArray(); $this->assertCount(1, $results); @@ -191,7 +191,7 @@ public function testSaveDirtyFields() $versionTable = TableRegistry::get('Version'); $results = $versionTable->find('all') ->where(['foreign_key' => $article->id, 'version_id' => 3]) - ->hydrate(false) + ->enableHydration(false) ->toArray(); $this->assertCount(2, $results); @@ -225,7 +225,7 @@ public function testSaveWithValidMetaData() ]); $table->addBehavior('Josegonzalez/Version.Version'); $article = $table->find('all')->first(); - EventManager::instance()->attach( + EventManager::instance()->on( function ($event) { return [ 'custom_field' => 'bar', @@ -237,7 +237,7 @@ function ($event) { $results = $versionTable->find('all') ->where(['foreign_key' => $article->id]) - ->hydrate(false) + ->enableHydration(false) ->toArray(); $this->assertEquals('foo', $results[4]['custom_field']); @@ -246,7 +246,7 @@ function ($event) { $results = $versionTable->find('all') ->where(['foreign_key' => $article->id]) - ->hydrate(false) + ->enableHydration(false) ->toArray(); $this->assertEquals('bar', $results[9]['custom_field']); } @@ -261,7 +261,7 @@ public function testSaveWithInvalidMetaData() ]); $table->addBehavior('Josegonzalez/Version.Version'); $article = $table->find('all')->first(); - EventManager::instance()->attach( + EventManager::instance()->on( function ($event) { return [ 'nonsense' => 'bar', @@ -273,7 +273,7 @@ function ($event) { $results = $versionTable->find('all') ->where(['foreign_key' => $article->id]) - ->hydrate(false) + ->enableHydration(false) ->toArray(); $this->assertEquals('foo', $results[4]['custom_field']); @@ -282,7 +282,7 @@ function ($event) { $results = $versionTable->find('all') ->where(['foreign_key' => $article->id]) - ->hydrate(false) + ->enableHydration(false) ->toArray(); $this->assertNull($results[9]['custom_field']); } @@ -360,14 +360,14 @@ public function testAssociations() $table->addBehavior('Josegonzalez/Version.Version'); $this->assertTrue($table->associations()->has('articleversion')); - $versions = $table->association('articleversion'); + $versions = $table->getAssociation('articleversion'); $this->assertInstanceOf('Cake\Orm\Association\HasMany', $versions); - $this->assertEquals('__version', $versions->property()); + $this->assertEquals('__version', $versions->getProperty()); $this->assertTrue($table->associations()->has('articlebodyversion')); - $bodyVersions = $table->association('articlebodyversion'); + $bodyVersions = $table->getAssociation('articlebodyversion'); $this->assertInstanceOf('Cake\Orm\Association\HasMany', $bodyVersions); - $this->assertEquals('body_version', $bodyVersions->property()); + $this->assertEquals('body_version', $bodyVersions->getProperty()); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 11fced8..0ee5765 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -66,7 +66,7 @@ ] ]; -Cake\Cache\Cache::config($cache); +Cake\Cache\Cache::getConfig($cache); Cake\Core\Configure::write('Session', [ 'defaults' => 'php' ]); @@ -78,7 +78,7 @@ putenv('db_dsn=sqlite:///:memory:'); } -Cake\Datasource\ConnectionManager::config('test', [ +Cake\Datasource\ConnectionManager::setConfig('test', [ 'url' => getenv('db_dsn'), 'timezone' => 'UTC' ]); From f7298619a0dcd8f1c918e2be289c01c56cd39e2e Mon Sep 17 00:00:00 2001 From: arilia Date: Tue, 24 Apr 2018 15:39:14 +0200 Subject: [PATCH 03/11] removed last deprecations and test pass --- config/bootstrap_cli.php | 2 +- tests/TestCase/Model/Behavior/VersionBehaviorTest.php | 8 ++++---- tests/bootstrap.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/bootstrap_cli.php b/config/bootstrap_cli.php index 6abdb50..db12f98 100644 --- a/config/bootstrap_cli.php +++ b/config/bootstrap_cli.php @@ -3,6 +3,6 @@ use Cake\Event\EventManager; use Josegonzalez\Version\Event\VersionListener; -EventManager::instance()->on('Bake.beforeRender', function (Event $event) { +EventManager::instance()->on('Bake.beforeRender', function (Event $event) { (new VersionListener($event))->execute(); }); diff --git a/tests/TestCase/Model/Behavior/VersionBehaviorTest.php b/tests/TestCase/Model/Behavior/VersionBehaviorTest.php index c3e9b61..bba5909 100644 --- a/tests/TestCase/Model/Behavior/VersionBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/VersionBehaviorTest.php @@ -226,12 +226,12 @@ public function testSaveWithValidMetaData() $table->addBehavior('Josegonzalez/Version.Version'); $article = $table->find('all')->first(); EventManager::instance()->on( + 'Model.Version.beforeSave', function ($event) { return [ 'custom_field' => 'bar', ]; - }, - 'Model.Version.beforeSave' + } ); $versionTable = TableRegistry::get('Version'); @@ -262,12 +262,12 @@ public function testSaveWithInvalidMetaData() $table->addBehavior('Josegonzalez/Version.Version'); $article = $table->find('all')->first(); EventManager::instance()->on( + 'Model.Version.beforeSave', function ($event) { return [ 'nonsense' => 'bar', ]; - }, - 'Model.Version.beforeSave' + } ); $versionTable = TableRegistry::get('Version'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0ee5765..f08a7c4 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -66,7 +66,7 @@ ] ]; -Cake\Cache\Cache::getConfig($cache); +Cake\Cache\Cache::setConfig($cache); Cake\Core\Configure::write('Session', [ 'defaults' => 'php' ]); From c1a54050b6ec41181e43e18613968ddc38387576 Mon Sep 17 00:00:00 2001 From: arilia Date: Tue, 24 Apr 2018 15:43:55 +0200 Subject: [PATCH 04/11] replaced attach() with on() --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff4238c..0c14520 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ use App\Event\VersionListener; use Cake\Event\EventManager; $VersionListener = new VersionListener(); -EventManager::instance()->attach($VersionListener); +EventManager::instance()->on($VersionListener); ``` Note that handling this event also allows you to modify/overwrite values generated by the plugin. From 681b03545e204c859fe6d025e5450caa0dc9f7ca Mon Sep 17 00:00:00 2001 From: arilia Date: Tue, 24 Apr 2018 15:47:44 +0200 Subject: [PATCH 05/11] updated composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 72ee4bf..612f5b5 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "cakephp/orm": "~3.0", "php": ">=5.5", - "satooshi/php-coveralls": "^2.0" + "php-coveralls/php-coveralls": "^2.0" }, "require-dev": { "cakephp/cakephp": "~3.0", From 77cff813faf1e7de3368aa25549cc6aabfa30cd3 Mon Sep 17 00:00:00 2001 From: arilia Date: Tue, 24 Apr 2018 16:20:23 +0200 Subject: [PATCH 06/11] update travis removed php 5.5. added 7.1, 7.2 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ddf0444..df0ea5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: php php: - - 5.5 - 5.6 - 7.0 + - 7.1 + - 7.2 sudo: false From 86e2309d6c3722805262159d149c63cad9582654 Mon Sep 17 00:00:00 2001 From: arilia Date: Tue, 24 Apr 2018 16:37:51 +0200 Subject: [PATCH 07/11] Update .travis.yml --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index df0ea5c..3d225d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,10 +23,10 @@ matrix: fast_finish: true include: - - php: 5.5 + - php: 5.6 env: PHPCS=1 DEFAULT=0 - - php: 5.5 + - php: 5.6 env: COVERALLS=1 DEFAULT=0 - php: hhvm @@ -45,7 +45,7 @@ before_script: - sh -c "if [ '$PHPCS' = '1' ]; then composer require 'cakephp/cakephp-codesniffer:dev-master'; fi" - - sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev php-coveralls/php-coveralls; fi" - sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi" - command -v phpenv > /dev/null && phpenv rehash || true From 61f9d5702c982f252890b69d01027e0eef19c3ba Mon Sep 17 00:00:00 2001 From: arilia Date: Tue, 24 Apr 2018 17:04:41 +0200 Subject: [PATCH 08/11] fixed code standards --- config/bootstrap_cli.php | 2 +- src/Event/VersionListener.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config/bootstrap_cli.php b/config/bootstrap_cli.php index db12f98..6abdb50 100644 --- a/config/bootstrap_cli.php +++ b/config/bootstrap_cli.php @@ -3,6 +3,6 @@ use Cake\Event\EventManager; use Josegonzalez\Version\Event\VersionListener; -EventManager::instance()->on('Bake.beforeRender', function (Event $event) { +EventManager::instance()->on('Bake.beforeRender', function (Event $event) { (new VersionListener($event))->execute(); }); diff --git a/src/Event/VersionListener.php b/src/Event/VersionListener.php index 3a9f4ac..143fe90 100644 --- a/src/Event/VersionListener.php +++ b/src/Event/VersionListener.php @@ -46,7 +46,6 @@ public function beforeRenderTable(Event $event) { $this->_checkAssociation($event, 'versions'); $this->_fixVersionTables($event); - } /** From d635e3c83b9320d6bdc7fb1f6cc89a74330ee4c7 Mon Sep 17 00:00:00 2001 From: arilia Date: Wed, 25 Apr 2018 15:26:47 +0200 Subject: [PATCH 09/11] composer constraints --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 612f5b5..423f670 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,12 @@ } ], "require": { - "cakephp/orm": "~3.0", - "php": ">=5.5", + "cakephp/orm": "~3.6", + "php": ">=5.6", "php-coveralls/php-coveralls": "^2.0" }, "require-dev": { - "cakephp/cakephp": "~3.0", + "cakephp/cakephp": "~3.6", "phpunit/phpunit": "^4.1 || ^5.0", "cakephp/cakephp-codesniffer": "dev-master" }, From bb908553375ed75fcea395fb604acc9379c0ce78 Mon Sep 17 00:00:00 2001 From: arilia Date: Wed, 25 Apr 2018 15:38:57 +0200 Subject: [PATCH 10/11] .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3d225d8..e3dfa07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,7 +52,7 @@ before_script: script: - sh -c "if [ '$COVERALLS' = '1' ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi" - - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -v; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/php-coveralls -v; fi" - sh -c "if [ '$DEFAULT' = '1' ]; then vendor/bin/phpunit ; fi" - sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=vendor --ignore=docs --ignore=tests/bootstrap.php . ; fi" From 357712cfed75f4719b4816876773a8b4947b2c39 Mon Sep 17 00:00:00 2001 From: arilia Date: Wed, 25 Apr 2018 17:31:37 +0200 Subject: [PATCH 11/11] phpunit --- phpunit.xml.dist | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5337e92..00b4454 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,6 +18,10 @@ + + ./src + ./tests + ./docs ./vendor