Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test
name: run-tests

on:
push:
Expand All @@ -9,26 +9,36 @@ on:
- 'master'

jobs:
build:
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
test:
runs-on: ubuntu-latest

strategy:
fail-fast: true
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4' ]
laravel: [ '5.5.*', '5.6.*', '5.7.*', '5.8.*', '^6.0', '^7.0' ]
php: [ 7.3, 7.4 ]
laravel: [ '^6.10', '^7.0', '^7.8' ]
dependency-version: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- uses: actions/checkout@v2
- name: Update apt
run: sudo apt-get update --fix-missing

- name: Checkout code
uses: actions/checkout@v2

- uses: actions/cache@v1
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- uses: shivammathur/setup-php@v1
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Validate composer.json
Expand All @@ -37,7 +47,7 @@ jobs:
- name: Install dependencies
run: |
composer require "illuminate/support:${{ matrix.laravel }}" "illuminate/http:${{ matrix.laravel }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-suggest
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Run test
run: ./vendor/bin/phpunit --verbose
- name: Execute tests
run: vendor/bin/phpunit --verbose
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This package helps integrate a Laravel application with chunk uploader libraries
[DropzoneJS](https://www.dropzonejs.com/) and
[jQuery-File-Upload from blueimp](https://blueimp.github.io/jQuery-File-Upload/).

Uploading a large file in chunks can help reduce risks.
Uploading a large file in chunks can help reduce risks.

- PHP from 5.3.4 limits the number of concurrent uploads and by uploading a file in one request can limit the
availability of a service. ([max_file_uploads][php-max-file-uploads])
Expand Down Expand Up @@ -47,7 +47,7 @@ project at the moment is [tus](https://tus.io/).
- [NOP identifier](#nop-identifier)
- [Contribution](#contribution)
- [License](#license)

## Installation

You can easily install this package using Composer, by running the following command:
Expand All @@ -60,8 +60,10 @@ composer require coding-socks/laravel-upload-handler

This package has the following requirements:

- PHP 7.1 or higher
- Laravel 5.5 or higher
- PHP `^7.3`
- Laravel `^6.10 || ^7.0 || ^8.0`

[Caret Version Range (^)](https://getcomposer.org/doc/articles/versions.md#caret-version-range-)

## Usage

Expand Down Expand Up @@ -115,7 +117,7 @@ the disk and the path of the uploaded file.
[Registering Events & Listeners from Laravel](https://laravel.com/docs/5.8/events#registering-events-and-listeners)

You can also add a `Closure` as the second parameter of the `handle` method to add an inline listener. The listener
is called with the disk and the path of the uploaded file.
is called with the disk and the path of the uploaded file.

```php
$handler->handle($request, function ($disk, $path) {
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
}
],
"require": {
"php": "^7.1",
"illuminate/support": "^5.5 || ^6.0 || ^7.0",
"illuminate/http": "^5.5 || ^6.0 || ^7.0"
"php": "^7.3",
"illuminate/support": "^6.10 || ^7.0 || ^8.0",
"illuminate/http": "^6.10 || ^7.0 || ^8.0"
},
"require-dev": {
"orchestra/testbench": "^3.5 || ^4.0 || ^5.0",
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0",
"mockery/mockery": "^1.0"
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0",
"phpunit/phpunit": "^9.3",
"mockery/mockery": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
38 changes: 14 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
verbose="true">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="Laravel Upload Handler Test Suite">
<directory>./tests</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
<text outputFile="build/coverage.txt"/>
</logging>
</phpunit>
4 changes: 2 additions & 2 deletions src/IdentityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function createNopDriver()
*/
public function getDefaultDriver()
{
return $this->app['config']['upload-handler.identifier'];
return $this->container['config']['upload-handler.identifier'];
}

/**
Expand All @@ -43,6 +43,6 @@ public function getDefaultDriver()
*/
public function setDefaultDriver($name)
{
$this->app['config']['upload-handler.identifier'] = $name;
$this->container['config']['upload-handler.identifier'] = $name;
}
}
20 changes: 10 additions & 10 deletions src/UploadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ class UploadManager extends Manager
{
public function createMonolithDriver()
{
return new MonolithBaseHandler($this->app['config']['upload-handler.monolith']);
return new MonolithBaseHandler($this->container['config']['upload-handler.monolith']);
}

public function createBlueimpDriver()
{
/** @var \Illuminate\Support\Manager $identityManager */
$identityManager = $this->app['upload-handler.identity-manager'];
$identityManager = $this->container['upload-handler.identity-manager'];

return new BlueimpBaseHandler($this->app['config']['upload-handler.blueimp'], $identityManager->driver());
return new BlueimpBaseHandler($this->container['config']['upload-handler.blueimp'], $identityManager->driver());
}

public function createDropzoneDriver()
{
return new DropzoneBaseHandler($this->app['config']['upload-handler.dropzone']);
return new DropzoneBaseHandler($this->container['config']['upload-handler.dropzone']);
}

public function createFlowJsDriver()
{
return new FlowJsHandler($this->app['config']['upload-handler.resumable-js'], $this->identityManager()->driver());
return new FlowJsHandler($this->container['config']['upload-handler.resumable-js'], $this->identityManager()->driver());
}

public function createNgFileUploadDriver()
Expand All @@ -49,20 +49,20 @@ public function createPluploadDriver()

public function createResumableJsDriver()
{
return new ResumableJsBaseHandler($this->app['config']['upload-handler.resumable-js'], $this->identityManager()->driver());
return new ResumableJsBaseHandler($this->container['config']['upload-handler.resumable-js'], $this->identityManager()->driver());
}

public function createSimpleUploaderJsDriver()
{
return new SimpleUploaderJsHandler($this->app['config']['upload-handler.simple-uploader-js'], $this->identityManager()->driver());
return new SimpleUploaderJsHandler($this->container['config']['upload-handler.simple-uploader-js'], $this->identityManager()->driver());
}

/**
* @return \Illuminate\Support\Manager
*/
protected function identityManager()
{
return $this->app['upload-handler.identity-manager'];
return $this->container['upload-handler.identity-manager'];
}

/**
Expand All @@ -72,7 +72,7 @@ protected function identityManager()
*/
public function getDefaultDriver()
{
return $this->app['config']['upload-handler.handler'];
return $this->container['config']['upload-handler.handler'];
}

/**
Expand All @@ -84,6 +84,6 @@ public function getDefaultDriver()
*/
public function setDefaultDriver($name)
{
$this->app['config']['upload-handler.handler'] = $name;
$this->container['config']['upload-handler.handler'] = $name;
}
}
13 changes: 7 additions & 6 deletions tests/Driver/BlueimpUploadHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ protected function setUp(): void
{
parent::setUp();

$this->app->make('config')->set('upload-handler.identifier', 'nop');
$this->app->make('config')->set('upload-handler.handler', 'blueimp');
$this->app->make('config')->set('upload-handler.sweep', false);
$this->handler = $this->app->make(UploadHandler::class);
config()->set('upload-handler.identifier', 'nop');
config()->set('upload-handler.handler', 'blueimp');
config()->set('upload-handler.sweep', false);
$this->handler = app()->make(UploadHandler::class);

Storage::fake('local');
Event::fake();
}

public function testDriverInstance()
{
$manager = $this->app->make('upload-handler.upload-manager');
$manager = app()->make('upload-handler.upload-manager');

$this->assertInstanceOf(BlueimpBaseHandler::class, $manager->driver());
}
Expand Down Expand Up @@ -120,7 +120,8 @@ public function testUploadWhenFileParameterIsEmpty()

public function testUploadWhenFileParameterIsInvalid()
{
$file = Mockery::mock(UploadedFile::class)->makePartial();
$file = Mockery::mock(UploadedFile::class)
->makePartial();
$file->shouldReceive('isValid')
->andReturn(false);

Expand Down
8 changes: 4 additions & 4 deletions tests/Driver/DropzoneUploadHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ protected function setUp(): void
{
parent::setUp();

$this->app->make('config')->set('upload-handler.handler', 'dropzone');
$this->app->make('config')->set('upload-handler.sweep', false);
$this->handler = $this->app->make(UploadHandler::class);
config()->set('upload-handler.handler', 'dropzone');
config()->set('upload-handler.sweep', false);
$this->handler = app()->make(UploadHandler::class);

Storage::fake('local');
Event::fake();
}

public function testDriverInstance()
{
$manager = $this->app->make('upload-handler.upload-manager');
$manager = app()->make('upload-handler.upload-manager');

$this->assertInstanceOf(DropzoneBaseHandler::class, $manager->driver());
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Driver/FlowJsUploadHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ protected function setUp(): void
{
parent::setUp();

$this->app->make('config')->set('upload-handler.identifier', 'nop');
$this->app->make('config')->set('upload-handler.handler', 'flow-js');
$this->app->make('config')->set('upload-handler.sweep', false);
$this->handler = $this->app->make(UploadHandler::class);
config()->set('upload-handler.identifier', 'nop');
config()->set('upload-handler.handler', 'flow-js');
config()->set('upload-handler.sweep', false);
$this->handler = app()->make(UploadHandler::class);

Storage::fake('local');
Event::fake();
}

public function testDriverInstance()
{
$manager = $this->app->make('upload-handler.upload-manager');
$manager = app()->make('upload-handler.upload-manager');

$this->assertInstanceOf(FlowJsHandler::class, $manager->driver());
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Driver/MonolithUploadHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ protected function setUp(): void
{
parent::setUp();

$this->app->make('config')->set('upload-handler.handler', 'monolith');
$this->handler = $this->app->make(UploadHandler::class);
config()->set('upload-handler.handler', 'monolith');
$this->handler = app()->make(UploadHandler::class);

Storage::fake('local');
Event::fake();
}

public function testDriverInstance()
{
$manager = $this->app->make('upload-handler.upload-manager');
$manager = app()->make('upload-handler.upload-manager');

$this->assertInstanceOf(MonolithBaseHandler::class, $manager->driver());
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Driver/NgFileUploadHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ protected function setUp(): void
{
parent::setUp();

$this->app->make('config')->set('upload-handler.identifier', 'nop');
$this->app->make('config')->set('upload-handler.handler', 'ng-file-upload');
$this->app->make('config')->set('upload-handler.sweep', false);
$this->handler = $this->app->make(UploadHandler::class);
config()->set('upload-handler.identifier', 'nop');
config()->set('upload-handler.handler', 'ng-file-upload');
config()->set('upload-handler.sweep', false);
$this->handler = app()->make(UploadHandler::class);

Storage::fake('local');
Event::fake();
}

public function testDriverInstance()
{
$manager = $this->app->make('upload-handler.upload-manager');
$manager = app()->make('upload-handler.upload-manager');

$this->assertInstanceOf(NgFileBaseHandler::class, $manager->driver());
}
Expand Down
Loading