From 05725d179dc2f265ac8a0d5591e87744db76f081 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 00:39:59 -0500 Subject: [PATCH 01/18] refactor: upgrade for cake4 --- .editorconfig | 6 +- .gitattributes | 5 +- .gitignore | 10 +- .scrutinizer.yml | 21 ++++ .semver | 6 - .sticker.yml | 11 ++ .travis.yml | 49 +++++--- CONTRIBUTING.md | 83 ++++++++++++++ VERSION | 1 - composer.json | 8 +- phpstan-baseline.neon | 2 + phpstan.neon | 9 ++ phpunit.xml.dist | 1 + psalm.xml | 29 +++++ src/Model/Behavior/ObfuscateBehavior.php | 29 +++-- .../Behavior/Strategy/HashidStrategy.php | 29 +---- .../Behavior/Strategy/OptimusStrategy.php | 24 +++- .../Behavior/Strategy/StrategyInterface.php | 5 +- src/Model/Behavior/Strategy/TinyStrategy.php | 3 +- src/Plugin.php | 19 +++ tests/Fixture/ArticlesFixture.php | 4 +- tests/Fixture/ArticlesTagsFixture.php | 2 + tests/Fixture/AuthorsFixture.php | 4 +- tests/Fixture/CommentsFixture.php | 4 +- tests/Fixture/TagsFixture.php | 4 +- .../Model/Behavior/ObfuscateBehaviorTest.php | 33 +++--- .../Behavior/Strategy/HashidStrategyTest.php | 21 ++-- .../Behavior/Strategy/OptimusStrategyTest.php | 8 +- .../Behavior/Strategy/TinyStrategyTest.php | 8 +- tests/bootstrap.php | 108 ++++++++++++++---- 30 files changed, 414 insertions(+), 132 deletions(-) create mode 100644 .scrutinizer.yml delete mode 100644 .semver create mode 100644 .sticker.yml create mode 100644 CONTRIBUTING.md delete mode 100644 VERSION create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon create mode 100644 psalm.xml create mode 100644 src/Plugin.php diff --git a/.editorconfig b/.editorconfig index a84f86c..de2fe7e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,13 +6,11 @@ root = true [*] indent_style = space indent_size = 4 +charset = "utf-8" end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[*.bat] -end_of_line = crlf - [*.yml] indent_style = space -indent_size = 2 \ No newline at end of file +indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 17493ec..d912dbb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,11 @@ # Remove files for archives generated using `git archive` +CONTRIBUTING.md export-ignore .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.semver export-ignore phpunit.xml.dist export-ignore .travis.yml export-ignore +.scrutinizer.yml export-ignore tests export-ignore +docs export-ignore +.github export-ignore diff --git a/.gitignore b/.gitignore index 364f9bd..5209c91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ -/composer.lock -/plugins -/vendor +*.pyc +docs/_build +phpunit.xml +vendor/ +composer.lock +tmp +.phpunit.result.cache diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..27146f7 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,21 @@ +imports: + - php + +filter: + excluded_paths: + - docs/ + - tests/ +tools: + php_mess_detector: true + php_cpd: + excluded_dirs: + - docs/ + - tests/ + php_loc: + excluded_dirs: + - docs/ + - tests/ + php_pdepend: + excluded_dirs: + 1: docs/ + 2: tests/ diff --git a/.semver b/.semver deleted file mode 100644 index 3581f63..0000000 --- a/.semver +++ /dev/null @@ -1,6 +0,0 @@ ---- -:major: 0 -:minor: 0 -:patch: 0 -:special: '' -:metadata: '' diff --git a/.sticker.yml b/.sticker.yml new file mode 100644 index 0000000..6ace1fe --- /dev/null +++ b/.sticker.yml @@ -0,0 +1,11 @@ +linters: + phpcs: + standard: CakePHP + extensions: 'php,ctp' + fixer: true +files: + ignore: + - 'vendor/*' +fixers: + enable: true + workflow: commit diff --git a/.travis.yml b/.travis.yml index 9c729f2..af10731 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,52 +1,65 @@ language: php php: - - 5.6 - 7.2 - 7.3 - -services: - - mysql - - postgresql + - 7.4 env: matrix: - - DB=sqlite db_dsn='sqlite:///:memory:' - - 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"' + - DB=mysql db_dsn='mysql://root@127.0.0.1/cakephp_test' - DB=pgsql db_dsn='postgres://postgres@127.0.0.1/cakephp_test' + - DB=sqlite db_dsn='sqlite:///:memory:' global: - DEFAULT=1 +services: + - mysql + - postgresql + matrix: fast_finish: true include: - - php: 7.3 + - php: 7.2 env: PHPCS=1 DEFAULT=0 - - php: 5.6 - env: PREFER_LOWEST=1 + - php: 7.2 + env: STATIC_ANALYSIS=1 DEFAULT=0 before_script: - if [[ $TRAVIS_PHP_VERSION != 7.2 ]]; then phpenv config-rm xdebug.ini; fi - - if [[ $PREFER_LOWEST != 1 ]]; then composer install --no-interaction; fi + - if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction; fi - if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi - - if [[ $DB == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi - - if [[ $DB == 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi + - if [[ $DB = 'mysql' ]]; then mysql -u root -e 'CREATE DATABASE cakephp_test;'; fi + - if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi - - if [[ $PHPCS == '1' ]]; then composer require cakephp/cakephp-codesniffer:^3.0; fi + - if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer:^4.0; fi + - if [[ $STATIC_ANALYSIS = 1 ]]; then composer require --dev phpstan/phpstan:^0.12 psalm/phar:^3.7; fi script: - - if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.2 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi - - if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi + - | + if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then + mkdir -p build/logs + vendor/bin/phpunit --coverage-clover=build/logs/clover.xml + fi + + - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi + + - if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi - - if [[ $PHPCS == 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi + - if [[ $STATIC_ANALYSIS = 1 ]]; then vendor/bin/phpstan.phar analyse src && vendor/bin/psalm.phar --show-info=false; fi after_success: - - if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.2 ]]; then bash <(curl -s https://codecov.io/bash); fi + - | + if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then + wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar + chmod +x php-coveralls.phar + ./php-coveralls.phar + fi notifications: email: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..88bec4a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,83 @@ +# How to contribute + +Obfuscate loves to welcome your contributions. There are several ways to help out: +* Create a ticket in GitHub, if you have found a bug +* Write testcases for open bug tickets +* Write patches for open bug/feature tickets, preferably with testcases included +* Contribute to the [documentation](https://github.com/UseMuffin/Obfuscate/tree/gh-pages) + +There are a few guidelines that we need contributors to follow so that we have a +chance of keeping on top of things. + +## Getting Started + +* Make sure you have a [GitHub account](https://github.com/signup/free) +* Submit a ticket for your issue, assuming one does not already exist. + * Clearly describe the issue including steps to reproduce when it is a bug. + * Make sure you fill in the earliest version that you know has the issue. +* Fork the repository on GitHub. + +## Making Changes + +* Create a topic branch from where you want to base your work. + * This is usually the develop branch + * To quickly create a topic branch based on master; `git branch + master/my_contribution master` then checkout the new branch with `git + checkout master/my_contribution`. Better avoid working directly on the + `master` branch, to avoid conflicts if you pull in updates from origin. +* Make commits of logical units. +* Check for unnecessary whitespace with `git diff --check` before committing. +* Use descriptive commit messages and reference the #ticket number +* Core testcases should continue to pass. You can run tests locally or enable + [travis-ci](https://travis-ci.org/) for your fork, so all tests and codesniffs + will be executed. +* Your work should apply the CakePHP coding standards. + +## Which branch to base the work + +* Bugfix branches will be based on develop branch. +* New features that are backwards compatible will be based on develop branch +* New features or other non-BC changes will go in the next major release branch. + +## Submitting Changes + +* Push your changes to a topic branch in your fork of the repository. +* Submit a pull request to the repository with the correct target branch. + +## Testcases and codesniffer + +Obfuscate tests requires [PHPUnit](http://www.phpunit.de/manual/current/en/installation.html) +8.5.0 or higher. To run the testcases locally use the following command: + + phpunit + +To run the sniffs for CakePHP coding standards + + phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=vendor --ignore=docs src/ tests/ + +Check the [cakephp-codesniffer](https://github.com/cakephp/cakephp-codesniffer) +repository to setup the CakePHP standard. The README contains installation info +for the sniff and phpcs. + +## Documentation + +You can build the documentation using Docker via the following commands: + + # go to the docs dir + cd docs + + # build the docs + docker build . + + # make the html + docker run -it --rm -v $(pwd)/docs:/data UseMuffin/Obfuscate make html + + # open the generated html docs in docs/_build/html + +# Additional Resources + +* [CakePHP coding standards](https://book.cakephp.org/4/en/contributing/cakephp-coding-conventions.html) +* [Bug tracker](https://github.com/UseMuffin/Obfuscate/issues) +* [General GitHub documentation](https://help.github.com/) +* [GitHub pull request documentation](https://help.github.com/send-pull-requests/) +* #cakephp IRC channel on freenode.org diff --git a/VERSION b/VERSION deleted file mode 100644 index ae39fab..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -v0.0.0 diff --git a/composer.json b/composer.json index 5b9dd03..56a360d 100644 --- a/composer.json +++ b/composer.json @@ -31,10 +31,14 @@ "source": "https://github.com/usemuffin/obfuscate" }, "require": { - "cakephp/orm": "^3.5" + "cakephp/orm": "~4.0" }, "require-dev": { - "cakephp/cakephp": "^3.5", + "cakephp/cakephp": "^4.0", + "cakephp/cakephp-codesniffer": "^4.0", + "phpstan/phpstan": "^0.12", + "phpunit/phpunit": "~8.5.0", + "psalm/phar": "^3.7", "phpunit/phpunit": "^5.7.14|^6.0", "zackkitzmiller/tiny": "^1.2", "jenssegers/optimus": "^0.2", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..f51e71c --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,2 @@ +parameters: + ignoreErrors: [] diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a61fda5 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,9 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 6 + checkGenericClassInNonGenericObjectType: false + checkMissingIterableValueType: false + excludes_analyse: + - */src/TestSuite/* diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 813017e..be542ad 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -25,6 +25,7 @@ ./src/ + ./src/ diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..15a7cd6 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Model/Behavior/ObfuscateBehavior.php b/src/Model/Behavior/ObfuscateBehavior.php index dde0a92..003802f 100644 --- a/src/Model/Behavior/ObfuscateBehavior.php +++ b/src/Model/Behavior/ObfuscateBehavior.php @@ -1,14 +1,17 @@ verifyConfig(); } @@ -48,10 +50,10 @@ public function initialize(array $config) * * @return void */ - public function verifyConfig() + public function verifyConfig(): void { $strategy = $this->getConfig('strategy'); - if (!$strategy) { + if (empty($strategy)) { throw new Exception('Missing required obfuscation strategy.'); } @@ -67,14 +69,17 @@ public function verifyConfig() /** * Callback to obfuscate the record(s)' primary key returned after a save operation. * - * @param \Cake\ORM\Behavior\Event $event Event. - * @param \Cake\ORM\Behavior\EntityInterface $entity Entity. + * @param \Cake\Event\Event $event Event. + * @param \Cake\Datasource\EntityInterface $entity Entity. * @param \ArrayObject $options Options. * @return void */ public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) { $pk = $this->_table->getPrimaryKey(); + if (is_array($pk)) { + throw new RuntimeException('Composite primary keys are not supported.'); + } $entity->set($pk, $this->obfuscate($entity->{$pk})); $entity->setDirty($pk, false); } @@ -82,7 +87,7 @@ public function afterSave(Event $event, EntityInterface $entity, ArrayObject $op /** * Callback to set the `obfuscated` finder on all associations. * - * @param \Cake\ORM\Behavior\Event $event Event. + * @param \Cake\Event\Event $event Event. * @param \Cake\ORM\Query $query Query. * @param \ArrayObject $options Options. * @param bool $primary True if this is the primary table. @@ -96,8 +101,12 @@ public function beforeFind(Event $event, Query $query, ArrayObject $options, $pr $query->traverseExpressions(function ($expression) { $pk = $this->_table->getPrimaryKey(); + if (is_array($pk)) { + throw new RuntimeException('Composite primary keys are not supported.'); + } + if ( - method_exists($expression, 'getField') + $expression instanceof Comparison && in_array($expression->getField(), [$pk, $this->_table->aliasField($pk)]) ) { $expression->setValue($this->elucidate($expression->getValue())); @@ -173,7 +182,7 @@ public function elucidate($str) /** * Get the configured strategy. * - * @return \Muffin\Obfuscate\Model\Behavior\ObfuscateStrategy\StrategyInterface + * @return \Muffin\Obfuscate\Model\Behavior\Strategy\StrategyInterface */ public function strategy() { diff --git a/src/Model/Behavior/Strategy/HashidStrategy.php b/src/Model/Behavior/Strategy/HashidStrategy.php index af9980c..aacf192 100644 --- a/src/Model/Behavior/Strategy/HashidStrategy.php +++ b/src/Model/Behavior/Strategy/HashidStrategy.php @@ -1,4 +1,6 @@ _salt = $salt; - $this->_minLength = $minLength; - $this->_alphabet = $alphabet; if ($alphabet === null) { $this->_hashid = new Hashids($salt, $minLength); diff --git a/src/Model/Behavior/Strategy/OptimusStrategy.php b/src/Model/Behavior/Strategy/OptimusStrategy.php index 9258455..7e3ecd2 100644 --- a/src/Model/Behavior/Strategy/OptimusStrategy.php +++ b/src/Model/Behavior/Strategy/OptimusStrategy.php @@ -1,10 +1,18 @@ _optimus->encode($str); + if (!is_numeric($str)) { + throw new InvalidArgumentException('Argument should be an integer'); + } + + return (string)$this->_optimus->encode((int)$str); } /** * {@inheritdoc} * * @param string $str String to elucidate. - * @return int + * @return string */ public function elucidate($str) { - return $this->_optimus->decode($str); + if (!is_numeric($str)) { + throw new InvalidArgumentException('Argument should be an integer'); + } + + return (string)$this->_optimus->decode((int)$str); } } diff --git a/src/Model/Behavior/Strategy/StrategyInterface.php b/src/Model/Behavior/Strategy/StrategyInterface.php index 431d1ba..61fd2a7 100644 --- a/src/Model/Behavior/Strategy/StrategyInterface.php +++ b/src/Model/Behavior/Strategy/StrategyInterface.php @@ -1,4 +1,6 @@ 2, 'title' => 'Second Article'], ]; - public function init() + public function init(): void { $created = $modified = date('Y-m-d H:i:s'); array_walk($this->records, function (&$record) use ($created, $modified) { diff --git a/tests/Fixture/ArticlesTagsFixture.php b/tests/Fixture/ArticlesTagsFixture.php index 2bbe140..62b94d2 100644 --- a/tests/Fixture/ArticlesTagsFixture.php +++ b/tests/Fixture/ArticlesTagsFixture.php @@ -1,4 +1,6 @@ 'Jane'], ]; - public function init() + public function init(): void { $created = $modified = date('Y-m-d H:i:s'); array_walk($this->records, function (&$record) use ($created, $modified) { diff --git a/tests/Fixture/CommentsFixture.php b/tests/Fixture/CommentsFixture.php index 8c3842b..2c35c94 100644 --- a/tests/Fixture/CommentsFixture.php +++ b/tests/Fixture/CommentsFixture.php @@ -1,4 +1,6 @@ 1, 'title' => 'Hello Universe'], ]; - public function init() + public function init(): void { $created = $modified = date('Y-m-d H:i:s'); array_walk($this->records, function (&$record) use ($created, $modified) { diff --git a/tests/Fixture/TagsFixture.php b/tests/Fixture/TagsFixture.php index 69ac6e8..d4f5a25 100644 --- a/tests/Fixture/TagsFixture.php +++ b/tests/Fixture/TagsFixture.php @@ -1,4 +1,6 @@ 'Bar'], ]; - public function init() + public function init(): void { $created = $modified = date('Y-m-d H:i:s'); array_walk($this->records, function (&$record) use ($created, $modified) { diff --git a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php index 758b7e4..52ddab9 100644 --- a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php @@ -1,6 +1,9 @@ Obfuscate = $this->Articles->behaviors()->Obfuscate; } - public function tearDown() + public function tearDown(): void { parent::tearDown(); TableRegistry::clear(); } - /** - * @expectedException \Cake\Core\Exception\Exception - */ - public function testVerifyConfig() + public function testVerifyConfig(): void { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Missing salt for Hashid strategy'); + $this->Articles->removeBehavior('Obfuscate'); $this->Articles->addBehavior('Muffin/Obfuscate.Obfuscate'); } - public function testAfterSave() + public function testAfterSave(): void { $entity = new Entity(['id' => 5, 'title' => 'foo']); $this->Articles->save($entity); @@ -83,7 +86,7 @@ public function testAfterSave() * Make sure primary keys in returned result set are obfuscated when using * the `obfuscate` custom finder. */ - public function testFindObfuscate() + public function testFindObfuscate(): void { $result = $this->Articles->find('obfuscate')->contain([ $this->Authors->getAlias(), @@ -101,7 +104,7 @@ public function testFindObfuscate() * Make sure primary keys in the returned result set are NOT obfuscated * when using default find. */ - public function testFindWithoutObfuscate() + public function testFindWithoutObfuscate(): void { $result = $this->Articles->find()->contain([ $this->Authors->getAlias(), @@ -119,7 +122,7 @@ public function testFindWithoutObfuscate() * Make sure we can search for records using obfuscated primary key when * using the `obfuscated` custom finder. */ - public function testFindObfuscated() + public function testFindObfuscated(): void { $results = $this->Articles->find('obfuscated') ->where(['id' => 'S']) @@ -131,7 +134,7 @@ public function testFindObfuscated() * Make sure we can search for records using non-obfuscated primary key * when using default find. */ - public function testFindWithoutObfuscated() + public function testFindWithoutObfuscated(): void { $results = $this->Articles->find() ->where(['id' => '1']) @@ -139,13 +142,17 @@ public function testFindWithoutObfuscated() $this->assertEquals('1', $results[0]['id']); } - public function testObfuscate() + public function testObfuscate(): void { $this->assertEquals('S', $this->Articles->obfuscate(1)); } - public function testElucidate() + public function testElucidate(): void { $this->assertEquals(1, $this->Articles->elucidate('S')); } + + public function testStrategy(): void + { + } } diff --git a/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php index 0b2dd7f..5ca8024 100644 --- a/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php @@ -1,46 +1,47 @@ strategy = new HashidStrategy('5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B'); } - public function testObfuscate() + public function testObfuscate(): void { $result = $this->assertEquals('k8', $this->strategy->obfuscate(1)); } - public function testElucidate() + public function testElucidate(): void { $this->assertEquals(1, $this->strategy->elucidate('k8')); } - public function testMinLength() + public function testMinLength(): void { $this->strategy = new HashidStrategy('5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B', 10); $this->assertEquals('qxPAk8pnOV', $this->strategy->obfuscate(1)); } - public function testCustomAlphabet() + public function testCustomAlphabet(): void { $this->strategy = new HashidStrategy('5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B', 0, 'abcdefghijklmnopqrstuvwxyz'); $this->assertEquals('vg', $this->strategy->obfuscate(1)); } - /** - * @expectedException Exception - * @expectedExceptionMessage Missing salt for Hashid strategy - */ - public function testSaltException() + public function testSaltException(): void { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Missing salt for Hashid strategy'); new HashidStrategy(); } } diff --git a/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php index aba98ec..1fc5c8e 100644 --- a/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php @@ -1,4 +1,6 @@ strategy = new OptimusStrategy(2123809381, 1885413229, 146808189); } - public function testObfuscate() + public function testObfuscate(): void { $this->assertEquals(1985404696, $this->strategy->obfuscate(1)); } - public function testElucidate() + public function testElucidate(): void { $this->assertEquals(1, $this->strategy->elucidate(1985404696)); } diff --git a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php index d539db8..882beeb 100644 --- a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php @@ -1,4 +1,6 @@ strategy = new TinyStrategy('5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B'); } - public function testObfuscate() + public function testObfuscate(): void { $this->assertEquals('S', $this->strategy->obfuscate(1)); } - public function testElucidate() + public function testElucidate(): void { $this->assertEquals(1, $this->strategy->elucidate('S')); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index c6dc570..39f2a49 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,28 +1,90 @@ 'Muffin\Obfuscate\Test\App', + 'encoding' => 'UTF-8', + 'fullBaseUrl' => 'http://localhost' +]); +Cake\Core\Configure::write('debug', true); + +$TMP = new \Cake\Filesystem\Folder(TMP); +$TMP->create(TMP . 'cache/models', 0777); +$TMP->create(TMP . 'cache/persistent', 0777); +$TMP->create(TMP . 'cache/views', 0777); + +$cache = [ + 'default' => [ + 'engine' => 'File' + ], + '_cake_core_' => [ + 'className' => 'File', + 'prefix' => 'muffin_obfuscate_myapp_cake_core_', + 'path' => CACHE . 'persistent/', + 'serialize' => true, + 'duration' => '+10 seconds' + ], + '_cake_model_' => [ + 'className' => 'File', + 'prefix' => 'muffin_obfuscate_my_app_cake_model_', + 'path' => CACHE . 'models/', + 'serialize' => 'File', + 'duration' => '+10 seconds' + ] +]; + +Cake\Cache\Cache::setConfig($cache); +Cake\Core\Configure::write('Session', [ + 'defaults' => 'php' +]); + +// Ensure default test connection is defined +if (!getenv('db_dsn')) { + putenv('db_dsn=sqlite:///:memory:'); } -require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php'; +Cake\Datasource\ConnectionManager::setConfig('test', [ + 'url' => getenv('db_dsn'), + 'timezone' => 'UTC' +]); + +Plugin::getCollection()->add(new \Muffin\Obfuscate\Plugin()); From fb647ee1278aa6771304ae927c5ed89037193a8e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 00:43:18 -0500 Subject: [PATCH 02/18] chore: update readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index bc73b1d..f965c16 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ Load the plugin by either running this console command: bin/cake plugin load Muffin/Obfuscate ``` +or by manually adding the following line to `src/Application.php`: + +```php +$this->addPlugin('Muffin/Obfuscate'); +``` + Lastly, composer install (any combination of) the obfuscation libraries you want to use in your application: From 1adf3c81e4a8ed56f9d20e8735733c350f8419db Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 00:47:33 -0500 Subject: [PATCH 03/18] fix: use correct parent class for new phpunit --- tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php | 1 + tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php | 1 + tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php | 1 + 3 files changed, 3 insertions(+) diff --git a/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php index 5ca8024..4dac979 100644 --- a/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php @@ -6,6 +6,7 @@ use Cake\TestSuite\TestCase; use Exception; use Muffin\Obfuscate\Model\Behavior\Strategy\HashidStrategy; +use PHPUnit\Framework\TestCase; class HashidStrategyTest extends TestCase { diff --git a/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php index 1fc5c8e..728283c 100644 --- a/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php @@ -5,6 +5,7 @@ use Cake\TestSuite\TestCase; use Muffin\Obfuscate\Model\Behavior\Strategy\OptimusStrategy; +use PHPUnit\Framework\TestCase; class OptimusStrategyTest extends TestCase { diff --git a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php index 882beeb..d450ae7 100644 --- a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); namespace Muffin\Obfuscate\Test\TestCase\Model\Behavior\Strategy; +use PHPUnit\Framework\TestCase; use Cake\TestSuite\TestCase; use Muffin\Obfuscate\Model\Behavior\Strategy\TinyStrategy; From c563f3ab14c45c76bdfd41780728c92205fa03d2 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 00:52:44 -0500 Subject: [PATCH 04/18] fix: drop empty test --- tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php index 52ddab9..0c71d95 100644 --- a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php @@ -151,8 +151,4 @@ public function testElucidate(): void { $this->assertEquals(1, $this->Articles->elucidate('S')); } - - public function testStrategy(): void - { - } } From 6437673866947a4a5ca0ccfec8391ca52c1d079f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 00:57:52 -0500 Subject: [PATCH 05/18] fix: correct expected exception --- tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php index 0c71d95..e04e38d 100644 --- a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php @@ -68,7 +68,7 @@ public function tearDown(): void public function testVerifyConfig(): void { $this->expectException(Exception::class); - $this->expectExceptionMessage('Missing salt for Hashid strategy'); + $this->expectExceptionMessage('Missing required obfuscation strategy'); $this->Articles->removeBehavior('Obfuscate'); $this->Articles->addBehavior('Muffin/Obfuscate.Obfuscate'); From c0fb6b71a39c8f2814e25f2cbc3c3e3d6de4423c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 01:19:54 -0500 Subject: [PATCH 06/18] fix: a ton of test updates --- .../Behavior/Strategy/HashidStrategy.php | 4 ++-- .../Behavior/Strategy/OptimusStrategy.php | 2 +- .../Behavior/Strategy/StrategyInterface.php | 2 +- src/Model/Behavior/Strategy/TinyStrategy.php | 4 ++-- .../Model/Behavior/ObfuscateBehaviorTest.php | 19 ++++++++++++++++--- .../Behavior/Strategy/HashidStrategyTest.php | 7 ++++++- .../Behavior/Strategy/OptimusStrategyTest.php | 7 ++++++- .../Behavior/Strategy/TinyStrategyTest.php | 5 +++++ 8 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/Model/Behavior/Strategy/HashidStrategy.php b/src/Model/Behavior/Strategy/HashidStrategy.php index aacf192..2c8f35e 100644 --- a/src/Model/Behavior/Strategy/HashidStrategy.php +++ b/src/Model/Behavior/Strategy/HashidStrategy.php @@ -46,12 +46,12 @@ public function __construct($salt = null, $minLength = 0, $alphabet = null) /** * {@inheritdoc} * - * @param string $str String to obfuscate. + * @param string|int $str String to obfuscate. * @return string */ public function obfuscate($str) { - return $this->_hashid->encode($str); + return $this->_hashid->encode((string)$str); } /** diff --git a/src/Model/Behavior/Strategy/OptimusStrategy.php b/src/Model/Behavior/Strategy/OptimusStrategy.php index 7e3ecd2..cde6ccc 100644 --- a/src/Model/Behavior/Strategy/OptimusStrategy.php +++ b/src/Model/Behavior/Strategy/OptimusStrategy.php @@ -30,7 +30,7 @@ public function __construct($prime, $inverse, $random) /** * {@inheritdoc} * - * @param string $str String to obfuscate. + * @param string|int $str String to obfuscate. * @return string */ public function obfuscate($str) diff --git a/src/Model/Behavior/Strategy/StrategyInterface.php b/src/Model/Behavior/Strategy/StrategyInterface.php index 61fd2a7..ed834ca 100644 --- a/src/Model/Behavior/Strategy/StrategyInterface.php +++ b/src/Model/Behavior/Strategy/StrategyInterface.php @@ -12,7 +12,7 @@ interface StrategyInterface /** * Obfuscates a given integer. * - * @param string $str String to obfuscate. + * @param string|int $str String to obfuscate. * @return string */ public function obfuscate($str); diff --git a/src/Model/Behavior/Strategy/TinyStrategy.php b/src/Model/Behavior/Strategy/TinyStrategy.php index 6fed54d..1b69231 100644 --- a/src/Model/Behavior/Strategy/TinyStrategy.php +++ b/src/Model/Behavior/Strategy/TinyStrategy.php @@ -41,11 +41,11 @@ public function __construct($set) * {@inheritdoc} * * @param string $str String to obfuscate. - * @return string + * @return string|int */ public function obfuscate($str) { - return $this->_tiny->to($str); + return $this->_tiny->to((string)$str); } /** diff --git a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php index e04e38d..b1d6029 100644 --- a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php @@ -15,8 +15,20 @@ class ObfuscateBehaviorTest extends TestCase * @var \Cake\ORM\Table; */ public $Articles; + + /** + * @var \Cake\ORM\Table; + */ public $Authors; + + /** + * @var \Cake\ORM\Table; + */ public $Comments; + + /** + * @var \Cake\ORM\Table; + */ public $Tags; /** @@ -56,7 +68,8 @@ public function setUp(): void 'through' => TableRegistry::get('Muffin/Obfuscate.ArticlesTags', ['table' => 'obfuscate_articles_tags']), ]); - $this->Obfuscate = $this->Articles->behaviors()->Obfuscate; + /** @var \Muffin\Obfuscate\Model\Behavior\ObfuscateBehavior $behavior */ + $this->Obfuscate = $this->Articles->getBehavior('Obfuscate'); } public function tearDown(): void @@ -144,11 +157,11 @@ public function testFindWithoutObfuscated(): void public function testObfuscate(): void { - $this->assertEquals('S', $this->Articles->obfuscate(1)); + $this->assertEquals('S', $this->Articles->behaviors()->call('obfuscate', [1])); } public function testElucidate(): void { - $this->assertEquals(1, $this->Articles->elucidate('S')); + $this->assertEquals(1, $this->Articles->behaviors()->call('elucidate', ['S'])); } } diff --git a/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php index 4dac979..d6689ec 100644 --- a/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php @@ -10,6 +10,11 @@ class HashidStrategyTest extends TestCase { + /** + * @var \Muffin\Obfuscate\Model\Behavior\Strategy\HashidStrategy; + */ + public $strategy; + public function setUp(): void { $this->strategy = new HashidStrategy('5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B'); @@ -17,7 +22,7 @@ public function setUp(): void public function testObfuscate(): void { - $result = $this->assertEquals('k8', $this->strategy->obfuscate(1)); + $this->assertEquals('k8', $this->strategy->obfuscate(1)); } public function testElucidate(): void diff --git a/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php index 728283c..4ee8264 100644 --- a/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php @@ -9,6 +9,11 @@ class OptimusStrategyTest extends TestCase { + /** + * @var \Muffin\Obfuscate\Model\Behavior\Strategy\OptimusStrategy; + */ + public $strategy; + public function setUp(): void { $this->strategy = new OptimusStrategy(2123809381, 1885413229, 146808189); @@ -21,6 +26,6 @@ public function testObfuscate(): void public function testElucidate(): void { - $this->assertEquals(1, $this->strategy->elucidate(1985404696)); + $this->assertEquals(1, $this->strategy->elucidate('1985404696')); } } diff --git a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php index d450ae7..5eb41c2 100644 --- a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php @@ -9,6 +9,11 @@ class TinyStrategyTest extends TestCase { + /** + * @var \Muffin\Obfuscate\Model\Behavior\Strategy\TinyStrategy; + */ + public $strategy; + public function setUp(): void { $this->strategy = new TinyStrategy('5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B'); From 3a8ba3f9bdd7748e693fbb2a2e981283319fd644 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 01:20:37 -0500 Subject: [PATCH 07/18] fix: correct phpcs issue --- tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php index 5eb41c2..1dfbc1a 100644 --- a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); namespace Muffin\Obfuscate\Test\TestCase\Model\Behavior\Strategy; -use PHPUnit\Framework\TestCase; use Cake\TestSuite\TestCase; use Muffin\Obfuscate\Model\Behavior\Strategy\TinyStrategy; +use PHPUnit\Framework\TestCase; class TinyStrategyTest extends TestCase { From 9602c2b7d12df3079ad8b2226bff9e3776f8b5a4 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 01:48:36 -0500 Subject: [PATCH 08/18] fix: correct psalm and phpstan issues --- phpstan-baseline.neon | 6 +++++- src/Model/Behavior/Strategy/HashidStrategy.php | 2 +- src/Model/Behavior/Strategy/OptimusStrategy.php | 2 +- src/Model/Behavior/Strategy/StrategyInterface.php | 2 +- src/Model/Behavior/Strategy/TinyStrategy.php | 4 ++-- tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php | 1 - 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f51e71c..f4c638b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,2 +1,6 @@ parameters: - ignoreErrors: [] + ignoreErrors: + - + message: '#^Property Muffin\\Obfuscate\\Test\\TestCase\\Model\\Behavior\\ObfuscateBehaviorTest::\$Obfuscate \(Muffin\\Obfuscate\\Model\\Behavior\\ObfuscateBehavior\) does not accept Cake\\ORM\\Behavior\.$#' + count: 1 + path: tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php diff --git a/src/Model/Behavior/Strategy/HashidStrategy.php b/src/Model/Behavior/Strategy/HashidStrategy.php index 2c8f35e..145c5a5 100644 --- a/src/Model/Behavior/Strategy/HashidStrategy.php +++ b/src/Model/Behavior/Strategy/HashidStrategy.php @@ -46,7 +46,7 @@ public function __construct($salt = null, $minLength = 0, $alphabet = null) /** * {@inheritdoc} * - * @param string|int $str String to obfuscate. + * @param int|string $str String to obfuscate. * @return string */ public function obfuscate($str) diff --git a/src/Model/Behavior/Strategy/OptimusStrategy.php b/src/Model/Behavior/Strategy/OptimusStrategy.php index cde6ccc..595eb9e 100644 --- a/src/Model/Behavior/Strategy/OptimusStrategy.php +++ b/src/Model/Behavior/Strategy/OptimusStrategy.php @@ -30,7 +30,7 @@ public function __construct($prime, $inverse, $random) /** * {@inheritdoc} * - * @param string|int $str String to obfuscate. + * @param int|string $str String to obfuscate. * @return string */ public function obfuscate($str) diff --git a/src/Model/Behavior/Strategy/StrategyInterface.php b/src/Model/Behavior/Strategy/StrategyInterface.php index ed834ca..c5770b3 100644 --- a/src/Model/Behavior/Strategy/StrategyInterface.php +++ b/src/Model/Behavior/Strategy/StrategyInterface.php @@ -12,7 +12,7 @@ interface StrategyInterface /** * Obfuscates a given integer. * - * @param string|int $str String to obfuscate. + * @param int|string $str String to obfuscate. * @return string */ public function obfuscate($str); diff --git a/src/Model/Behavior/Strategy/TinyStrategy.php b/src/Model/Behavior/Strategy/TinyStrategy.php index 1b69231..43e7b93 100644 --- a/src/Model/Behavior/Strategy/TinyStrategy.php +++ b/src/Model/Behavior/Strategy/TinyStrategy.php @@ -40,8 +40,8 @@ public function __construct($set) /** * {@inheritdoc} * - * @param string $str String to obfuscate. - * @return string|int + * @param int|string $str String to obfuscate. + * @return string */ public function obfuscate($str) { diff --git a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php index b1d6029..7fd7e1b 100644 --- a/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php @@ -68,7 +68,6 @@ public function setUp(): void 'through' => TableRegistry::get('Muffin/Obfuscate.ArticlesTags', ['table' => 'obfuscate_articles_tags']), ]); - /** @var \Muffin\Obfuscate\Model\Behavior\ObfuscateBehavior $behavior */ $this->Obfuscate = $this->Articles->getBehavior('Obfuscate'); } From 5d9667c154df5fb7c16f471526bcbf0d70a04949 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 01:53:04 -0500 Subject: [PATCH 09/18] chore: remove ignored rule --- phpstan-baseline.neon | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f4c638b..f51e71c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,6 +1,2 @@ parameters: - ignoreErrors: - - - message: '#^Property Muffin\\Obfuscate\\Test\\TestCase\\Model\\Behavior\\ObfuscateBehaviorTest::\$Obfuscate \(Muffin\\Obfuscate\\Model\\Behavior\\ObfuscateBehavior\) does not accept Cake\\ORM\\Behavior\.$#' - count: 1 - path: tests/TestCase/Model/Behavior/ObfuscateBehaviorTest.php + ignoreErrors: [] From 53f0a86287354b9c4381fbb5862765496938bfae Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 02:02:44 -0500 Subject: [PATCH 10/18] hack: do not convert errors to exceptions --- phpunit.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index be542ad..bf86143 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,6 +3,7 @@ bootstrap="./tests/bootstrap.php" colors="true" stopOnFailure="false" + convertErrorsToExceptions="false" > From 5a1632e48aaf21c1582052a0988a02c2eb9a7ef5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 02:08:01 -0500 Subject: [PATCH 11/18] hack: more falsitudes --- phpunit.xml.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bf86143..b045399 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,6 +4,8 @@ colors="true" stopOnFailure="false" convertErrorsToExceptions="false" + convertNoticesToExceptions="false" + convertWarningsToExceptions="false" > From 73fbb7f72f860cd05760042fd05f623d5a5538f4 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 02:09:54 -0500 Subject: [PATCH 12/18] hack: try this one --- phpunit.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b045399..23bbc28 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,6 +6,7 @@ convertErrorsToExceptions="false" convertNoticesToExceptions="false" convertWarningsToExceptions="false" + convertDeprecationsToExceptions="false" > From abba62f38cfea107cc9b26dbae322e43a2f70f47 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 21 Jan 2020 02:12:59 -0500 Subject: [PATCH 13/18] fix: only ignore php deprecations --- phpunit.xml.dist | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 23bbc28..f8739c3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,9 +3,6 @@ bootstrap="./tests/bootstrap.php" colors="true" stopOnFailure="false" - convertErrorsToExceptions="false" - convertNoticesToExceptions="false" - convertWarningsToExceptions="false" convertDeprecationsToExceptions="false" > From b82a107c4949c33dbcd6d9553f6b2718b3492fc5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 2 Mar 2020 22:28:30 -0500 Subject: [PATCH 14/18] fix: drop bad use call --- tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php | 1 - tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php | 1 - tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php index d6689ec..8c2b8c1 100644 --- a/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/HashidStrategyTest.php @@ -3,7 +3,6 @@ namespace Muffin\Obfuscate\Test\TestCase\Model\Behavior\Strategy; -use Cake\TestSuite\TestCase; use Exception; use Muffin\Obfuscate\Model\Behavior\Strategy\HashidStrategy; use PHPUnit\Framework\TestCase; diff --git a/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php index 4ee8264..6e7ff21 100644 --- a/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/OptimusStrategyTest.php @@ -3,7 +3,6 @@ namespace Muffin\Obfuscate\Test\TestCase\Model\Behavior\Strategy; -use Cake\TestSuite\TestCase; use Muffin\Obfuscate\Model\Behavior\Strategy\OptimusStrategy; use PHPUnit\Framework\TestCase; diff --git a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php index 1dfbc1a..11c4dd7 100644 --- a/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php +++ b/tests/TestCase/Model/Behavior/Strategy/TinyStrategyTest.php @@ -3,7 +3,6 @@ namespace Muffin\Obfuscate\Test\TestCase\Model\Behavior\Strategy; -use Cake\TestSuite\TestCase; use Muffin\Obfuscate\Model\Behavior\Strategy\TinyStrategy; use PHPUnit\Framework\TestCase; From 42351e75a384a2ac6bb3535c7d1ff94118b2fe05 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 2 Mar 2020 22:38:25 -0500 Subject: [PATCH 15/18] fix: drop extra require --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 56a360d..2ffebf6 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,6 @@ "phpstan/phpstan": "^0.12", "phpunit/phpunit": "~8.5.0", "psalm/phar": "^3.7", - "phpunit/phpunit": "^5.7.14|^6.0", "zackkitzmiller/tiny": "^1.2", "jenssegers/optimus": "^0.2", "hashids/hashids": "^1.0.5" From d6d2260dc132cde8115c914acf3c5aebdc708356 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 3 Mar 2020 11:10:12 -0500 Subject: [PATCH 16/18] fix: correct a few review comments --- CONTRIBUTING.md | 83 ------------------------ composer.json | 4 +- phpstan.neon | 2 - phpunit.xml.dist | 1 - src/Model/Behavior/ObfuscateBehavior.php | 10 +-- 5 files changed, 7 insertions(+), 93 deletions(-) delete mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 88bec4a..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,83 +0,0 @@ -# How to contribute - -Obfuscate loves to welcome your contributions. There are several ways to help out: -* Create a ticket in GitHub, if you have found a bug -* Write testcases for open bug tickets -* Write patches for open bug/feature tickets, preferably with testcases included -* Contribute to the [documentation](https://github.com/UseMuffin/Obfuscate/tree/gh-pages) - -There are a few guidelines that we need contributors to follow so that we have a -chance of keeping on top of things. - -## Getting Started - -* Make sure you have a [GitHub account](https://github.com/signup/free) -* Submit a ticket for your issue, assuming one does not already exist. - * Clearly describe the issue including steps to reproduce when it is a bug. - * Make sure you fill in the earliest version that you know has the issue. -* Fork the repository on GitHub. - -## Making Changes - -* Create a topic branch from where you want to base your work. - * This is usually the develop branch - * To quickly create a topic branch based on master; `git branch - master/my_contribution master` then checkout the new branch with `git - checkout master/my_contribution`. Better avoid working directly on the - `master` branch, to avoid conflicts if you pull in updates from origin. -* Make commits of logical units. -* Check for unnecessary whitespace with `git diff --check` before committing. -* Use descriptive commit messages and reference the #ticket number -* Core testcases should continue to pass. You can run tests locally or enable - [travis-ci](https://travis-ci.org/) for your fork, so all tests and codesniffs - will be executed. -* Your work should apply the CakePHP coding standards. - -## Which branch to base the work - -* Bugfix branches will be based on develop branch. -* New features that are backwards compatible will be based on develop branch -* New features or other non-BC changes will go in the next major release branch. - -## Submitting Changes - -* Push your changes to a topic branch in your fork of the repository. -* Submit a pull request to the repository with the correct target branch. - -## Testcases and codesniffer - -Obfuscate tests requires [PHPUnit](http://www.phpunit.de/manual/current/en/installation.html) -8.5.0 or higher. To run the testcases locally use the following command: - - phpunit - -To run the sniffs for CakePHP coding standards - - phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=vendor --ignore=docs src/ tests/ - -Check the [cakephp-codesniffer](https://github.com/cakephp/cakephp-codesniffer) -repository to setup the CakePHP standard. The README contains installation info -for the sniff and phpcs. - -## Documentation - -You can build the documentation using Docker via the following commands: - - # go to the docs dir - cd docs - - # build the docs - docker build . - - # make the html - docker run -it --rm -v $(pwd)/docs:/data UseMuffin/Obfuscate make html - - # open the generated html docs in docs/_build/html - -# Additional Resources - -* [CakePHP coding standards](https://book.cakephp.org/4/en/contributing/cakephp-coding-conventions.html) -* [Bug tracker](https://github.com/UseMuffin/Obfuscate/issues) -* [General GitHub documentation](https://help.github.com/) -* [GitHub pull request documentation](https://help.github.com/send-pull-requests/) -* #cakephp IRC channel on freenode.org diff --git a/composer.json b/composer.json index 2ffebf6..3656285 100644 --- a/composer.json +++ b/composer.json @@ -31,14 +31,14 @@ "source": "https://github.com/usemuffin/obfuscate" }, "require": { - "cakephp/orm": "~4.0" + "cakephp/orm": "^4.0" }, "require-dev": { "cakephp/cakephp": "^4.0", "cakephp/cakephp-codesniffer": "^4.0", "phpstan/phpstan": "^0.12", "phpunit/phpunit": "~8.5.0", - "psalm/phar": "^3.7", + "psalm/phar": "^3.9", "zackkitzmiller/tiny": "^1.2", "jenssegers/optimus": "^0.2", "hashids/hashids": "^1.0.5" diff --git a/phpstan.neon b/phpstan.neon index a61fda5..ea3d1a8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,5 +5,3 @@ parameters: level: 6 checkGenericClassInNonGenericObjectType: false checkMissingIterableValueType: false - excludes_analyse: - - */src/TestSuite/* diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f8739c3..56c0f03 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -26,7 +26,6 @@ ./src/ - ./src/ diff --git a/src/Model/Behavior/ObfuscateBehavior.php b/src/Model/Behavior/ObfuscateBehavior.php index 003802f..bc4ff04 100644 --- a/src/Model/Behavior/ObfuscateBehavior.php +++ b/src/Model/Behavior/ObfuscateBehavior.php @@ -7,7 +7,7 @@ use Cake\Core\Exception\Exception; use Cake\Database\Expression\Comparison; use Cake\Datasource\EntityInterface; -use Cake\Event\Event; +use Cake\Event\EventInterface; use Cake\ORM\Behavior; use Cake\ORM\Query; use Muffin\Obfuscate\Model\Behavior\Strategy\StrategyInterface; @@ -69,12 +69,12 @@ public function verifyConfig(): void /** * Callback to obfuscate the record(s)' primary key returned after a save operation. * - * @param \Cake\Event\Event $event Event. + * @param \Cake\Event\EventInterface $event EventInterface. * @param \Cake\Datasource\EntityInterface $entity Entity. * @param \ArrayObject $options Options. * @return void */ - public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) + public function afterSave(EventInterface $event, EntityInterface $entity, ArrayObject $options) { $pk = $this->_table->getPrimaryKey(); if (is_array($pk)) { @@ -87,13 +87,13 @@ public function afterSave(Event $event, EntityInterface $entity, ArrayObject $op /** * Callback to set the `obfuscated` finder on all associations. * - * @param \Cake\Event\Event $event Event. + * @param \Cake\Event\EventInterface $event EventInterface. * @param \Cake\ORM\Query $query Query. * @param \ArrayObject $options Options. * @param bool $primary True if this is the primary table. * @return void */ - public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) + public function beforeFind(EventInterface $event, Query $query, ArrayObject $options, $primary) { if (empty($options['obfuscate']) || !$primary) { return; From 9501f3310772ac82e6a44ada3a9e7ef81e42aa8d Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 3 Mar 2020 21:51:49 +0530 Subject: [PATCH 17/18] Delete .scrutinizer.yml --- .scrutinizer.yml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 27146f7..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,21 +0,0 @@ -imports: - - php - -filter: - excluded_paths: - - docs/ - - tests/ -tools: - php_mess_detector: true - php_cpd: - excluded_dirs: - - docs/ - - tests/ - php_loc: - excluded_dirs: - - docs/ - - tests/ - php_pdepend: - excluded_dirs: - 1: docs/ - 2: tests/ From 158a81e9c4e52f3aea35a28f987f108acb99e313 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 3 Mar 2020 21:53:58 +0530 Subject: [PATCH 18/18] Fix stickler config --- .sticker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.sticker.yml b/.sticker.yml index 6ace1fe..08993b0 100644 --- a/.sticker.yml +++ b/.sticker.yml @@ -1,7 +1,7 @@ linters: phpcs: - standard: CakePHP - extensions: 'php,ctp' + standard: CakePHP4 + extensions: 'php' fixer: true files: ignore: