Skip to content

Commit

Permalink
Merge pull request #521 from FriendsOfCake/travis
Browse files Browse the repository at this point in the history
Update travis config.
  • Loading branch information
ADmad authored Jul 28, 2019
2 parents 01e0a40 + 48f184b commit b768004
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 147 deletions.
57 changes: 27 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,56 @@ language: php

php:
- 5.6
- 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://[email protected]/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://[email protected]/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
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
[![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
# 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).

See [this branch](https://github.com/FriendsOfCake/cakephp-upload/tree/2.x) for CakePHP 2.x documentation.

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/).

Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
}
],
"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",
"cakephp/chronos": "^1.1",
"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": {
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 2 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://flysystem.thephpleague.com/>` 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
------------

Expand Down
20 changes: 2 additions & 18 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,14 @@ Installation

The only officialy supported method of installing this plugin is via composer.

Using `Composer <http://getcomposer.org/>`__
--------------------------------------------

`View on
Packagist <https://packagist.org/packages/josegonzalez/cakephp-upload>`__,
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
<?php
$this->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
10 changes: 5 additions & 5 deletions tests/TestCase/File/Path/Basepath/DefaultTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/File/Writer/DefaultWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Model/Behavior/UploadBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand Down Expand Up @@ -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'],
Expand All @@ -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']);
}
}
85 changes: 16 additions & 69 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,77 +1,24 @@
<?php
// @codingStandardsIgnoreFile

$findRoot = function () {
$root = __DIR__;
for ($i = 0; $i < 3; $i++) {
/*
* Test suite bootstrap
*
* This function is used to find the location of CakePHP whether CakePHP
* has been installed as a dependency of the plugin, or the plugin is itself
* installed as a dependency of an application.
*/
$findRoot = function ($root) {
do {
$lastRoot = $root;
$root = dirname($root);
if (is_dir($root . '/vendor/cakephp/cakephp')) {
return $root;
}
}
} while ($root !== $lastRoot);
throw new Exception('Cannot find the root of the application, unable to run tests');
};

if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
define('ROOT', $findRoot());
define('APP_DIR', 'App');
define('WEBROOT_DIR', 'webroot');
define('APP', ROOT . '/tests/App/');
define('CONFIG', ROOT . '/tests/config/');
define('WWW_ROOT', ROOT . DS . WEBROOT_DIR . DS);
define('TESTS', ROOT . DS . 'tests' . DS);
define('TMP', ROOT . DS . 'tmp' . DS);
define('LOGS', TMP . 'logs' . DS);
define('CACHE', TMP . 'cache' . DS);
define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp');
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('CAKE', CORE_PATH . 'src' . DS);

require ROOT . '/vendor/autoload.php';
require CORE_PATH . 'config/bootstrap.php';

Cake\Core\Configure::write('App', ['namespace' => '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'
]);

\Cake\Core\Plugin::getCollection()->add(new \Josegonzalez\Upload\Plugin);

// Ensure default test connection is defined
if (!getenv('db_dsn')) {
putenv('db_dsn=sqlite:///:memory:');
}
$root = $findRoot(__FILE__);
unset($findRoot);
chdir($root);

Cake\Datasource\ConnectionManager::setConfig('test', [
'url' => getenv('db_dsn'),
'timezone' => 'UTC'
]);
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';

0 comments on commit b768004

Please sign in to comment.