Skip to content

Commit

Permalink
Merge pull request #35 from arilia/master
Browse files Browse the repository at this point in the history
other deprecations
  • Loading branch information
josegonzalez authored Apr 25, 2018
2 parents 18336b1 + 357712c commit 9805605
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 48 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

sudo: false

Expand All @@ -22,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
Expand All @@ -44,14 +45,14 @@ 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

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"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
}
],
"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",
"satooshi/php-coveralls": "dev-master"
"cakephp/cakephp-codesniffer": "dev-master"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./src</directory>
<directory suffix=".php">./tests</directory>
</whitelist>
<blacklist>
<directory suffix=".php">./docs</directory>
<directory suffix=".php">./vendor</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/Event/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Event/VersionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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())) {
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Behavior/Version/VersionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
28 changes: 14 additions & 14 deletions src/Model/Behavior/VersionBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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;
Expand All @@ -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);
}
}
Expand All @@ -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);
}

Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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'];
Expand All @@ -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
];
Expand Down Expand Up @@ -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);
Expand All @@ -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']);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
36 changes: 18 additions & 18 deletions tests/TestCase/Model/Behavior/VersionBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -225,19 +225,19 @@ public function testSaveWithValidMetaData()
]);
$table->addBehavior('Josegonzalez/Version.Version');
$article = $table->find('all')->first();
EventManager::instance()->attach(
EventManager::instance()->on(
'Model.Version.beforeSave',
function ($event) {
return [
'custom_field' => 'bar',
];
},
'Model.Version.beforeSave'
}
);
$versionTable = TableRegistry::get('Version');

$results = $versionTable->find('all')
->where(['foreign_key' => $article->id])
->hydrate(false)
->enableHydration(false)
->toArray();
$this->assertEquals('foo', $results[4]['custom_field']);

Expand All @@ -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']);
}
Expand All @@ -261,19 +261,19 @@ public function testSaveWithInvalidMetaData()
]);
$table->addBehavior('Josegonzalez/Version.Version');
$article = $table->find('all')->first();
EventManager::instance()->attach(
EventManager::instance()->on(
'Model.Version.beforeSave',
function ($event) {
return [
'nonsense' => 'bar',
];
},
'Model.Version.beforeSave'
}
);
$versionTable = TableRegistry::get('Version');

$results = $versionTable->find('all')
->where(['foreign_key' => $article->id])
->hydrate(false)
->enableHydration(false)
->toArray();
$this->assertEquals('foo', $results[4]['custom_field']);

Expand All @@ -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']);
}
Expand Down Expand Up @@ -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());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
]
];

Cake\Cache\Cache::config($cache);
Cake\Cache\Cache::setConfig($cache);
Cake\Core\Configure::write('Session', [
'defaults' => 'php'
]);
Expand All @@ -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'
]);

0 comments on commit 9805605

Please sign in to comment.