From 1af032166a26bf94a9432a3899eb2a2756471588 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 28 Jul 2019 19:11:55 +0530 Subject: [PATCH 1/8] Update travis config. --- .travis.yml | 56 ++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 78d867bf..af4cae0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,56 +5,54 @@ php: - 7.0 - 7.1 - 7.2 - -sudo: false + - 7.3 env: matrix: - - DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test' + - 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 matrix: - allow_failures: - - php: hhvm - fast_finish: true include: - - php: 5.6 + - php: 7.3 env: PHPCS=1 DEFAULT=0 - php: 5.6 - env: COVERALLS=1 DEFAULT=0 - - - php: hhvm - env: HHVM=1 DB=sqlite db_dsn='sqlite:///:memory:' - - - php: hhvm - env: HHVM=1 DB=mysql db_dsn='mysql://travis@0.0.0.0/cakephp_test' + env: PREFER_LOWEST=1 before_script: - - composer self-update - - composer install --prefer-source --no-interaction - - - sh -c "if [ '$DB' = 'mysql' ]; then if [ '$DOCKER' = '1' ]; then apt-get -qq install -qq -y mysql-server && service mysql start; fi; mysql -e 'CREATE DATABASE cakephp_test;'; fi" - - - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi" - - - sh -c "if [ '$PHPCS' = '1' ]; then composer require 'cakephp/cakephp-codesniffer:dev-master'; fi" + - if [[ $TRAVIS_PHP_VERSION != 7.3 ]]; then phpenv config-rm xdebug.ini; fi - - sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls; fi" - - sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; 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 - - command -v phpenv > /dev/null && phpenv rehash || true + - if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi + - if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi script: - - sh -c "if [ '$COVERALLS' = '1' ]; then vendor/bin/phpunit --stderr --coverage-clover build/logs/clover.xml; fi" - - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/php-coveralls -v; fi" - - sh -c "if [ '$DEFAULT' = '1' ]; then vendor/bin/phpunit --stderr; fi" - - sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi" + - | + if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.3 ]]; then + mkdir -p build/logs + vendor/bin/phpunit --coverage-clover=build/logs/clover.xml + fi + + - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.3 ]]; then vendor/bin/phpunit; fi + + - if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi + +after_success: + - | + if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.3 ]]; 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 From 2260b1a824aeb498f219b86ea7d62d4ed26e7abd Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 28 Jul 2019 19:22:47 +0530 Subject: [PATCH 2/8] Fix badge links. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 72971116..57e9f462 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Build Status](https://img.shields.io/travis/FriendsOfCake/cakephp-upload/master.svg?style=flat-square)](https://travis-ci.org/FriendsOfCake/cakephp-upload) [![Coverage Status](https://img.shields.io/coveralls/FriendsOfCake/cakephp-upload.svg?style=flat-square)](https://coveralls.io/r/FriendsOfCake/cakephp-upload?branch=master) -[![Total Downloads](https://img.shields.io/packagist/dt/FriendsOfCake/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/FriendsOfCake/cakephp-upload) -[![Latest Stable Version](https://img.shields.io/packagist/v/FriendsOfCake/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/FriendsOfCake/cakephp-upload) +[![Total Downloads](https://img.shields.io/packagist/dt/josegonzalez/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/josegonzalez/cakephp-upload) +[![Latest Stable Version](https://img.shields.io/packagist/v/josegonzalez/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/josegonzalez/cakephp-upload) [![Documentation Status](https://readthedocs.org/projects/cakephp-upload/badge/?version=latest&style=flat-square)](https://readthedocs.org/projects/cakephp-upload/?badge=latest) # Upload Plugin 4.0 From 88c67c6840705bf764f23421f5aa779f075bfacb Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 28 Jul 2019 19:32:49 +0530 Subject: [PATCH 3/8] Bump up CakePHP to ^3.5. --- composer.json | 10 ++++------ tests/bootstrap.php | 2 -- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 82242c00..bcac1de7 100644 --- a/composer.json +++ b/composer.json @@ -12,16 +12,14 @@ } ], "require": { - "cakephp/orm": "3.*", - "php": ">=5.6", + "cakephp/orm": "^3.5", "league/flysystem": "*" }, "require-dev": { - "cakephp/cakephp": "~3.4", - "phpunit/phpunit": "<6.0", + "cakephp/cakephp": "^3.5", + "phpunit/phpunit": "^5.7.14|^6.0", "league/flysystem-vfs": "*", - "cakephp/cakephp-codesniffer": "dev-master", - "satooshi/php-coveralls": "^2.0" + "cakephp/cakephp-codesniffer": "dev-master" }, "autoload": { "psr-4": { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d2749626..fec649e6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -64,8 +64,6 @@ 'defaults' => 'php' ]); -\Cake\Core\Plugin::getCollection()->add(new \Josegonzalez\Upload\Plugin); - // Ensure default test connection is defined if (!getenv('db_dsn')) { putenv('db_dsn=sqlite:///:memory:'); From 840de4075901ce5e2a708a110cb0eb6efe6d8c1c Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 28 Jul 2019 19:37:07 +0530 Subject: [PATCH 4/8] Update readme. --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 57e9f462..20edfc13 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Latest Stable Version](https://img.shields.io/packagist/v/josegonzalez/cakephp-upload.svg?style=flat-square)](https://packagist.org/packages/josegonzalez/cakephp-upload) [![Documentation Status](https://readthedocs.org/projects/cakephp-upload/badge/?version=latest&style=flat-square)](https://readthedocs.org/projects/cakephp-upload/?badge=latest) -# Upload Plugin 4.0 +# Upload Plugin The Upload Plugin is an attempt to sanely upload files using techniques garnered from packages such as [MeioUpload](http://github.com/jrbasso/MeioUpload) , [UploadPack](http://github.com/szajbus/cakephp-uploadpack) and [PHP documentation](http://php.net/manual/en/features.file-upload.php). @@ -12,11 +12,6 @@ See [this branch](https://github.com/FriendsOfCake/cakephp-upload/tree/2.x) for See [this blog post](http://josediazgonzalez.com/2015/12/05/uploading-files-and-images/) for a tutorial on using the 3.x version. -## Requirements - -* CakePHP 3.6+ -* PHP 5.6+ - ## Documentation For documentation, please see [the docs](http://cakephp-upload.readthedocs.org/en/latest/). From 1180d854745800d26978637a3bd2fff497448ce0 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 28 Jul 2019 19:43:27 +0530 Subject: [PATCH 5/8] Update phpunit method call. --- tests/TestCase/File/Path/Basepath/DefaultTraitTest.php | 10 +++++----- tests/TestCase/File/Writer/DefaultWriterTest.php | 2 +- tests/TestCase/Model/Behavior/UploadBehaviorTest.php | 6 +++--- tests/bootstrap.php | 2 ++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/TestCase/File/Path/Basepath/DefaultTraitTest.php b/tests/TestCase/File/Path/Basepath/DefaultTraitTest.php index 80938b37..1a11a651 100644 --- a/tests/TestCase/File/Path/Basepath/DefaultTraitTest.php +++ b/tests/TestCase/File/Path/Basepath/DefaultTraitTest.php @@ -52,7 +52,7 @@ public function testExistingEntityWithPrimaryKey() public function testNewEntity() { - $this->setExpectedException('LogicException', '{primaryKey} substitution not allowed for new entities'); + $this->expectException('LogicException', '{primaryKey} substitution not allowed for new entities'); $mock = $this->getMockForTrait('Josegonzalez\Upload\File\Path\Basepath\DefaultTrait'); $mock->entity = $this->getMockBuilder('Cake\ORM\Entity')->getMock(); @@ -66,7 +66,7 @@ public function testNewEntity() public function testExitingEntityWithCompositePrimaryKey() { - $this->setExpectedException('LogicException', '{primaryKey} substitution not valid for composite primary keys'); + $this->expectException('LogicException', '{primaryKey} substitution not valid for composite primary keys'); $mock = $this->getMockForTrait('Josegonzalez\Upload\File\Path\Basepath\DefaultTrait'); $mock->entity = $this->getMockBuilder('Cake\ORM\Entity')->getMock(); @@ -136,7 +136,7 @@ public function testModelFieldYearWithMonthAndDayPath() public function testFieldValueMissing() { - $this->setExpectedException('LogicException', 'Field value for substitution is missing: field'); + $this->expectException('LogicException', 'Field value for substitution is missing: field'); $mock = $this->getMockForTrait('Josegonzalez\Upload\File\Path\Basepath\DefaultTrait'); $mock->entity = $this->getMockBuilder('Cake\ORM\Entity')->getMock(); @@ -150,7 +150,7 @@ public function testFieldValueMissing() public function testFieldValueNonScalar() { - $this->setExpectedException('LogicException', 'Field value for substitution must be a integer, float, string or boolean: field'); + $this->expectException('LogicException', 'Field value for substitution must be a integer, float, string or boolean: field'); $mock = $this->getMockForTrait('Josegonzalez\Upload\File\Path\Basepath\DefaultTrait'); $mock->entity = $this->getMockBuilder('Cake\ORM\Entity')->getMock(); @@ -164,7 +164,7 @@ public function testFieldValueNonScalar() public function testFieldValueZeroLength() { - $this->setExpectedException('LogicException', 'Field value for substitution must be non-zero in length: field'); + $this->expectException('LogicException', 'Field value for substitution must be non-zero in length: field'); $mock = $this->getMockForTrait('Josegonzalez\Upload\File\Path\Basepath\DefaultTrait'); $mock->entity = $this->getMockBuilder('Cake\ORM\Entity')->getMock(); diff --git a/tests/TestCase/File/Writer/DefaultWriterTest.php b/tests/TestCase/File/Writer/DefaultWriterTest.php index 735fd3ca..2273c6a1 100644 --- a/tests/TestCase/File/Writer/DefaultWriterTest.php +++ b/tests/TestCase/File/Writer/DefaultWriterTest.php @@ -138,7 +138,7 @@ public function testGetFilesystem() public function testGetFilesystemUnexpectedValueException() { - $this->setExpectedException('UnexpectedValueException', 'Invalid Adapter for field field'); + $this->expectException('UnexpectedValueException', 'Invalid Adapter for field field'); $this->writer->getFilesystem('field', [ 'filesystem' => [ diff --git a/tests/TestCase/Model/Behavior/UploadBehaviorTest.php b/tests/TestCase/Model/Behavior/UploadBehaviorTest.php index e3aaa9aa..d3f24fc0 100644 --- a/tests/TestCase/Model/Behavior/UploadBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/UploadBehaviorTest.php @@ -615,7 +615,7 @@ public function testGetWriter() public function testGetWriterException() { - $this->setExpectedException('UnexpectedValueException', "'writer' not set to instance of WriterInterface: UnexpectedValueException"); + $this->expectException('UnexpectedValueException', "'writer' not set to instance of WriterInterface: UnexpectedValueException"); $this->behavior->getWriter($this->entity, [], 'field', ['writer' => 'UnexpectedValueException']); } @@ -693,7 +693,7 @@ public function testConstructFilesWithCallableAndBasePathEndingDS() public function testConstructFilesException() { - $this->setExpectedException('UnexpectedValueException', "'transformer' not set to instance of TransformerInterface: UnexpectedValueException"); + $this->expectException('UnexpectedValueException', "'transformer' not set to instance of TransformerInterface: UnexpectedValueException"); $this->behavior->constructFiles( $this->entity, ['tmp_name' => 'path/to/file/on/disk', 'name' => 'file.txt'], @@ -711,7 +711,7 @@ public function testGetPathProcessor() public function testGetPathProcessorException() { - $this->setExpectedException('UnexpectedValueException', "'pathProcessor' not set to instance of ProcessorInterface: UnexpectedValueException"); + $this->expectException('UnexpectedValueException', "'pathProcessor' not set to instance of ProcessorInterface: UnexpectedValueException"); $this->behavior->getPathProcessor($this->entity, [], 'field', ['pathProcessor' => 'UnexpectedValueException']); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fec649e6..dbccf10d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -73,3 +73,5 @@ 'url' => getenv('db_dsn'), 'timezone' => 'UTC' ]); + +loadPHPUnitAliases(); From 483ad6532da2fae8e6cc36741052173f2635aa5e Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 28 Jul 2019 19:48:01 +0530 Subject: [PATCH 6/8] Simplify tests bootstrap. --- composer.json | 1 + tests/bootstrap.php | 85 +++++++++------------------------------------ 2 files changed, 17 insertions(+), 69 deletions(-) diff --git a/composer.json b/composer.json index bcac1de7..2aecfd3b 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ }, "require-dev": { "cakephp/cakephp": "^3.5", + "cakephp/chronos": "^1.1", "phpunit/phpunit": "^5.7.14|^6.0", "league/flysystem-vfs": "*", "cakephp/cakephp-codesniffer": "dev-master" diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dbccf10d..b1532adc 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,77 +1,24 @@ 'App']); -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' => 'upload_myapp_cake_core_', - 'path' => CACHE . 'persistent/', - 'serialize' => true, - 'duration' => '+10 seconds' - ], - '_cake_model_' => [ - 'className' => 'File', - 'prefix' => 'upload_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:'); -} - -Cake\Datasource\ConnectionManager::setConfig('test', [ - 'url' => getenv('db_dsn'), - 'timezone' => 'UTC' -]); +$root = $findRoot(__FILE__); +unset($findRoot); +chdir($root); -loadPHPUnitAliases(); +require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php'; From 3d314cdc9a441ba4ae3397f6c449c1a2d22bbaaf Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 28 Jul 2019 19:56:47 +0530 Subject: [PATCH 7/8] Update docs --- docs/configuration.rst | 1 + docs/index.rst | 9 ++------- docs/installation.rst | 20 ++------------------ 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 9f8db097..f3f14caf 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -63,6 +63,7 @@ passed in under each field in your behavior configuration. - ``fields.dir``: (default ``dir``) Field to use for storing the directory - ``fields.type``: (default ``type``) Field to use for storing the filetype - ``fields.size``: (default ``size``) Field to use for storing the filesize + - ``fields.ext``: (default ``ext``) Field to use for storing the file extension - ``filesystem``: An array of configuration info for configuring the writer diff --git a/docs/index.rst b/docs/index.rst index 469cb09c..034f08ca 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -2,16 +2,11 @@ Introduction ************ -Upload Plugin 3.0 -================= +Upload Plugin +============= The Upload Plugin is an attempt to sanely upload files using techniques garnered from packages such as MeioUpload , UploadPack and PHP documentation. It uses the excellent `Flysystem ` library to handle file uploads, and can be easily integrated with any image library to handle thumbnail extraction to your exact specifications. -Background ----------- - -Media Plugin is too complicated, and it was a PITA to merge the latest updates into MeioUpload, so here I am, building yet another upload plugin. I'll build another in a month and call it "YAUP". - Requirements ------------ diff --git a/docs/installation.rst b/docs/installation.rst index 637587b9..4abe6459 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -3,30 +3,14 @@ Installation The only officialy supported method of installing this plugin is via composer. -Using `Composer `__ --------------------------------------------- - -`View on -Packagist `__, -and copy the json snippet for the latest version into your project's -``composer.json``. - .. code:: composer require josegonzalez/cakephp-upload Enable plugin ------------- - -You need to enable the plugin by adding the below code at ``src/Application.php`` file: - -.. code:: php - - addPlugin('Josegonzalez/Upload'); - -There is also a handy shell command to enable the plugin. Execute the following line: +Use the shell command to enable the plugin. Execute the following line: .. code:: shell - + bin/cake plugin load Josegonzalez/Upload From 48f184b16cc520585ee4c79483094d5e0f55648e Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 28 Jul 2019 20:00:40 +0530 Subject: [PATCH 8/8] Speed up CI. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index af4cae0c..3cf305e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: php php: - 5.6 - - 7.0 - 7.1 - 7.2 - 7.3