Skip to content

Commit f0c02ef

Browse files
authored
Merge pull request #14 from UseMuffin/cake-3
Cake 3
2 parents 352757e + 479cc08 commit f0c02ef

File tree

14 files changed

+63
-79
lines changed

14 files changed

+63
-79
lines changed

.travis.yml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
language: php
22

33
php:
4-
- 5.4
5-
- 5.5
64
- 5.6
7-
- 7
5+
- 7.2
6+
- 7.3
87

9-
sudo: false
8+
services:
9+
- mysql
10+
- postgresql
1011

1112
env:
1213
matrix:
13-
- DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test'
14-
- DB=pgsql db_dsn='postgres://postgres@127.0.0.1/cakephp_test'
1514
- DB=sqlite db_dsn='sqlite:///:memory:'
15+
- DB=mysql db_dsn='mysql://root@127.0.0.1/cakephp_test?init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'
16+
- DB=pgsql db_dsn='postgres://postgres@127.0.0.1/cakephp_test'
1617

1718
global:
1819
- DEFAULT=1
@@ -21,33 +22,31 @@ matrix:
2122
fast_finish: true
2223

2324
include:
24-
- php: 5.4
25+
- php: 7.3
2526
env: PHPCS=1 DEFAULT=0
2627

27-
- php: 7
28-
env: COVERALLS=1 DEFAULT=0 DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test'
28+
- php: 5.6
29+
env: PREFER_LOWEST=1
2930

3031
before_script:
31-
- sh -c "if [ '$COVERALLS' != '1' ]; then phpenv config-rm xdebug.ini; fi"
32-
33-
- composer self-update
34-
- composer install --prefer-dist --no-interaction
32+
- if [[ $TRAVIS_PHP_VERSION != 7.2 ]]; then phpenv config-rm xdebug.ini; fi
3533

36-
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi"
37-
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi"
34+
- if [[ $PREFER_LOWEST != 1 ]]; then composer install --no-interaction; fi
35+
- if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi
3836

39-
- sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer:dev-master; fi"
37+
- if [[ $DB == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
38+
- if [[ $DB == 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
4039

41-
- sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi"
42-
- sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi"
40+
- if [[ $PHPCS == '1' ]]; then composer require cakephp/cakephp-codesniffer:^3.0; fi
4341

4442
script:
45-
- sh -c "if [ '$DEFAULT' = '1' ]; then ./vendor/bin/phpunit; fi"
43+
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.2 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
44+
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi
4645

47-
- sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi"
46+
- if [[ $PHPCS == 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
4847

49-
- sh -c "if [ '$COVERALLS' = '1' ]; then ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi"
50-
- sh -c "if [ '$COVERALLS' = '1' ]; then vendor/bin/coveralls -v; fi"
48+
after_success:
49+
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.2 ]]; then bash <(curl -s https://codecov.io/bash); fi
5150

5251
notifications:
5352
email: false

README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,26 @@
11
# Obfuscate
22

33
[![Build Status](https://img.shields.io/travis/UseMuffin/Obfuscate/master.svg?style=flat-square)](https://travis-ci.org/UseMuffin/Obfuscate)
4-
[![Coverage](https://img.shields.io/coveralls/UseMuffin/Obfuscate/master.svg?style=flat-square)](https://coveralls.io/r/UseMuffin/Obfuscate)
4+
[![Coverage](https://img.shields.io/codecov/c/github/UseMuffin/Obfuscate.svg?style=flat-square)](https://codecov.io/github/UseMuffin/Obfuscate)
55
[![Total Downloads](https://img.shields.io/packagist/dt/muffin/obfuscate.svg?style=flat-square)](https://packagist.org/packages/muffin/obfuscate)
66
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
77

8-
Primary key obfuscation for CakePHP 3 using HashIds, Optimus, Tiny and/or custom obfuscation strategies.
9-
10-
## Requirements
11-
12-
- CakePHP 3.0+
8+
Primary key obfuscation for CakePHP using HashIds, Optimus, Tiny and/or custom obfuscation strategies.
139

1410
## Installation
1511

1612
Install the plugin using [Composer](https://getcomposer.org):
1713

1814
```
19-
composer require muffin/obfuscate:1.0.x-dev
15+
composer require muffin/obfuscate
2016
```
2117

22-
You then need to load the plugin by either running this shell command:
18+
Load the plugin by either running this console command:
2319

2420
```
2521
bin/cake plugin load Muffin/Obfuscate
2622
```
2723

28-
or by manually adding the following line to ``config/bootstrap.php``:
29-
30-
```php
31-
Plugin::load('Muffin/Obfuscate');
32-
```
33-
3424
Lastly, composer install (any combination of) the obfuscation libraries you
3525
want to use in your application:
3626

composer.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "muffin/obfuscate",
3-
"description": "CakePHP 3 support for ID obfuscation",
3+
"description": "CakePHP support for ID obfuscation",
44
"type": "cakephp-plugin",
55
"keywords": [
66
"cakephp",
@@ -31,13 +31,14 @@
3131
"source": "https://github.com/usemuffin/obfuscate"
3232
},
3333
"require": {
34+
"cakephp/orm": "^3.5"
3435
},
3536
"require-dev": {
36-
"cakephp/cakephp": "~3.0",
37-
"phpunit/phpunit": "<6.0",
38-
"zackkitzmiller/tiny": "1.2.0",
39-
"jenssegers/optimus": "0.2.0",
40-
"hashids/hashids": "1.0.5"
37+
"cakephp/cakephp": "^3.5",
38+
"phpunit/phpunit": "^5.7.14|^6.0",
39+
"zackkitzmiller/tiny": "^1.2",
40+
"jenssegers/optimus": "^0.2",
41+
"hashids/hashids": "^1.0.5"
4142
},
4243
"suggest": {
4344
"zackkitzmiller/tiny": "A reversible base62 ID obfuscater",
@@ -53,10 +54,5 @@
5354
"psr-4": {
5455
"Muffin\\Obfuscate\\Test\\": "tests"
5556
}
56-
},
57-
"extra": {
58-
"branch-alias": {
59-
"dev-master": "1.0.x-dev"
60-
}
6157
}
6258
}

src/Model/Behavior/ObfuscateBehavior.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ObfuscateBehavior extends Behavior
2424
'strategy' => null,
2525
'implementedFinders' => [
2626
'obfuscated' => 'findObfuscated',
27-
'obfuscate' => 'findObfuscate'
27+
'obfuscate' => 'findObfuscate',
2828
],
2929
'implementedMethods' => [
3030
'obfuscate' => 'obfuscate',
@@ -50,7 +50,8 @@ public function initialize(array $config)
5050
*/
5151
public function verifyConfig()
5252
{
53-
if (!$strategy = $this->config('strategy')) {
53+
$strategy = $this->getConfig('strategy');
54+
if (!$strategy) {
5455
throw new Exception('Missing required obfuscation strategy.');
5556
}
5657

@@ -73,9 +74,9 @@ public function verifyConfig()
7374
*/
7475
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options)
7576
{
76-
$pk = $this->_table->primaryKey();
77+
$pk = $this->_table->getPrimaryKey();
7778
$entity->set($pk, $this->obfuscate($entity->{$pk}));
78-
$entity->dirty($pk, false);
79+
$entity->setDirty($pk, false);
7980
}
8081

8182
/**
@@ -94,8 +95,9 @@ public function beforeFind(Event $event, Query $query, ArrayObject $options, $pr
9495
}
9596

9697
$query->traverseExpressions(function ($expression) {
97-
$pk = $this->_table->primaryKey();
98-
if (method_exists($expression, 'getField')
98+
$pk = $this->_table->getPrimaryKey();
99+
if (
100+
method_exists($expression, 'getField')
99101
&& in_array($expression->getField(), [$pk, $this->_table->aliasField($pk)])
100102
) {
101103
$expression->setValue($this->elucidate($expression->getValue()));
@@ -105,8 +107,8 @@ public function beforeFind(Event $event, Query $query, ArrayObject $options, $pr
105107
});
106108

107109
foreach ($this->_table->associations() as $association) {
108-
if ($association->target()->hasBehavior('Obfuscate') && 'all' === $association->finder()) {
109-
$association->finder('obfuscate');
110+
if ($association->getTarget()->hasBehavior('Obfuscate') && $association->getFinder() === 'all') {
111+
$association->setFinder('obfuscate');
110112
}
111113
}
112114
}
@@ -136,7 +138,7 @@ public function findObfuscate(Query $query, array $options)
136138

137139
$query->formatResults(function ($results) {
138140
return $results->map(function ($row) {
139-
$pk = $this->_table->primaryKey();
141+
$pk = $this->_table->getPrimaryKey();
140142
$row[$pk] = $this->obfuscate($row[$pk]);
141143

142144
return $row;
@@ -175,6 +177,6 @@ public function elucidate($str)
175177
*/
176178
public function strategy()
177179
{
178-
return $this->config('strategy');
180+
return $this->getConfig('strategy');
179181
}
180182
}

tests/Fixture/ArticlesFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ArticlesFixture extends TestFixture
1818
'title' => ['type' => 'string', 'null' => false],
1919
'created' => ['type' => 'datetime', 'null' => true],
2020
'modified' => ['type' => 'datetime', 'null' => true],
21-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
21+
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
2222
];
2323

2424
/**

tests/Fixture/ArticlesTagsFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ArticlesTagsFixture extends TestFixture
1616
'id' => ['type' => 'integer'],
1717
'obfuscate_article_id' => ['type' => 'integer'],
1818
'tag_id' => ['type' => 'integer'],
19-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
19+
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
2020
];
2121

2222
/**

tests/Fixture/AuthorsFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AuthorsFixture extends TestFixture
1717
'name' => ['type' => 'string', 'null' => false],
1818
'created' => ['type' => 'datetime', 'null' => true],
1919
'modified' => ['type' => 'datetime', 'null' => true],
20-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
20+
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
2121
];
2222

2323
/**

tests/Fixture/CommentsFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CommentsFixture extends TestFixture
1818
'title' => ['type' => 'string', 'null' => false],
1919
'created' => ['type' => 'datetime', 'null' => true],
2020
'modified' => ['type' => 'datetime', 'null' => true],
21-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
21+
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
2222
];
2323

2424
/**

tests/Fixture/TagsFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TagsFixture extends TestFixture
1717
'name' => ['type' => 'string', 'null' => false],
1818
'created' => ['type' => 'datetime', 'null' => true],
1919
'modified' => ['type' => 'datetime', 'null' => true],
20-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
20+
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
2121
];
2222

2323
/**

tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function setUp()
5050
$this->Articles->belongsToMany('Muffin/Obfuscate.Tags', [
5151
'foreignKey' => 'obfuscate_article_id',
5252
'joinTable' => 'obfuscate_articles_tags',
53-
'through' => TableRegistry::get('Muffin/Obfuscate.ArticlesTags', ['table' => 'obfuscate_articles_tags'])
53+
'through' => TableRegistry::get('Muffin/Obfuscate.ArticlesTags', ['table' => 'obfuscate_articles_tags']),
5454
]);
5555

5656
$this->Obfuscate = $this->Articles->behaviors()->Obfuscate;
@@ -76,7 +76,7 @@ public function testAfterSave()
7676
$entity = new Entity(['id' => 5, 'title' => 'foo']);
7777
$this->Articles->save($entity);
7878
$this->assertEquals('E', $entity['id']);
79-
$this->assertFalse($entity->dirty('id'));
79+
$this->assertFalse($entity->isDirty('id'));
8080
}
8181

8282
/**
@@ -86,9 +86,9 @@ public function testAfterSave()
8686
public function testFindObfuscate()
8787
{
8888
$result = $this->Articles->find('obfuscate')->contain([
89-
$this->Authors->alias(),
90-
$this->Comments->alias(),
91-
$this->Tags->alias(),
89+
$this->Authors->getAlias(),
90+
$this->Comments->getAlias(),
91+
$this->Tags->getAlias(),
9292
])->first();
9393

9494
$this->assertEquals('S', $result['author']['id']);
@@ -104,9 +104,9 @@ public function testFindObfuscate()
104104
public function testFindWithoutObfuscate()
105105
{
106106
$result = $this->Articles->find()->contain([
107-
$this->Authors->alias(),
108-
$this->Comments->alias(),
109-
$this->Tags->alias(),
107+
$this->Authors->getAlias(),
108+
$this->Comments->getAlias(),
109+
$this->Tags->getAlias(),
110110
])->first();
111111

112112
$this->assertEquals('1', $result['author']['id']);
@@ -148,8 +148,4 @@ public function testElucidate()
148148
{
149149
$this->assertEquals(1, $this->Articles->elucidate('S'));
150150
}
151-
152-
public function testStrategy()
153-
{
154-
}
155151
}

0 commit comments

Comments
 (0)