Skip to content

Commit 0ee8595

Browse files
authored
Merge pull request #28 from tattersoftware/failures
Failure Mitigation
2 parents d9dfd5f + 81944cf commit 0ee8595

13 files changed

Lines changed: 126 additions & 15 deletions

File tree

.github/workflows/analyze.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ jobs:
3939
with:
4040
php-version: ${{ matrix.php-versions }}
4141
tools: composer, pecl, phpunit
42-
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
42+
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3
43+
env:
44+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4345

4446
- name: Get composer cache directory
4547
id: composer-cache
@@ -65,7 +67,12 @@ jobs:
6567
key: ${{ runner.os }}-phpstan-${{ github.sha }}
6668
restore-keys: ${{ runner.os }}-phpstan-
6769

68-
- name: Install dependencies
70+
- name: Install dependencies (limited)
71+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
72+
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
73+
74+
- name: Install dependencies (authenticated)
75+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
6976
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
7077
env:
7178
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

.github/workflows/compare.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# When a PR is opened or a push is made, compare
2+
# code for backwards compatibility.
3+
name: RoaveBC
4+
5+
on:
6+
pull_request:
7+
branches:
8+
- develop
9+
paths:
10+
- 'src/**'
11+
push:
12+
branches:
13+
- develop
14+
paths:
15+
- 'src/**'
16+
17+
jobs:
18+
compare:
19+
name: Compare for Backwards Compatibility
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Run comparison (limited)
27+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
28+
uses: docker://nyholm/roave-bc-check-ga
29+
30+
- name: Run comparison (authenticated)
31+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
32+
uses: docker://nyholm/roave-bc-check-ga
33+
env:
34+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

.github/workflows/test.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ jobs:
3131
tools: composer, pecl, phpunit
3232
extensions: intl, json, mbstring, gd, mysqlnd, xdebug, xml, sqlite3
3333
coverage: xdebug
34+
env:
35+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3436

3537
- name: Get composer cache directory
3638
id: composer-cache
@@ -43,11 +45,19 @@ jobs:
4345
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
4446
restore-keys: ${{ runner.os }}-composer-
4547

46-
- name: Install dependencies
48+
- name: Install dependencies (limited)
49+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
50+
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
51+
52+
- name: Install dependencies (authenticated)
53+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
4754
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
4855
env:
4956
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
5057

58+
- name: Enable Tachycardia
59+
run: echo "TACHYCARDIA_MONITOR_GA=enabled" >> $GITHUB_ENV
60+
5161
- name: Test with PHPUnit
5262
run: vendor/bin/phpunit --verbose --coverage-text
5363
env:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"codeigniter4/codeigniter4": "dev-develop",
3939
"codeigniter4/codeigniter4-standard": "^1.0",
4040
"myth/auth": "dev-develop",
41-
"tatter/tools": "^1.6"
41+
"tatter/tools": "^1.8"
4242
},
4343
"autoload": {
4444
"psr-4": {

phpstan.neon.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ parameters:
1717
- '#Unsafe usage of new static\(\)*#'
1818
- '#Call to an undefined static method Config\\Services::authentication\(\)#'
1919
- '#Function Patchwork\\redefine not found#'
20+
universalObjectCratesClasses:
21+
- CodeIgniter\Entity
22+
- Faker\Generator
2023
scanDirectories:
2124
- vendor/codeigniter4/codeigniter4/system/Helpers
2225
- vendor/myth/auth/src/Helpers

phpunit.xml.dist

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
34
bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
45
backupGlobals="false"
6+
beStrictAboutCoversAnnotation="true"
7+
beStrictAboutOutputDuringTests="true"
8+
beStrictAboutTodoAnnotatedTests="true"
59
colors="true"
610
convertErrorsToExceptions="true"
711
convertNoticesToExceptions="true"
812
convertWarningsToExceptions="true"
913
executionOrder="random"
10-
stopOnError="false"
14+
failOnRisky="true"
15+
failOnWarning="true"
16+
stopOnError="true"
1117
stopOnFailure="false"
1218
stopOnIncomplete="false"
1319
stopOnSkipped="false"
14-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
20+
verbose="true">
1521

1622
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
1723
<include>
@@ -36,6 +42,30 @@
3642
</testsuite>
3743
</testsuites>
3844

45+
<extensions>
46+
<extension class="Nexus\PHPUnit\Extension\Tachycardia">
47+
<arguments>
48+
<array>
49+
<element key="timeLimit">
50+
<double>0.50</double>
51+
</element>
52+
<element key="reportable">
53+
<integer>30</integer>
54+
</element>
55+
<element key="precision">
56+
<integer>2</integer>
57+
</element>
58+
<element key="collectBare">
59+
<boolean>true</boolean>
60+
</element>
61+
<element key="tabulate">
62+
<boolean>true</boolean>
63+
</element>
64+
</array>
65+
</arguments>
66+
</extension>
67+
</extensions>
68+
3969
<logging>
4070
<testdoxHtml outputFile="build/phpunit/testdox.html"/>
4171
<testdoxText outputFile="build/phpunit/testdox.txt"/>
@@ -59,6 +89,7 @@
5989
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
6090

6191
<!-- Database configuration -->
92+
<env name="database.tests.strictOn" value="true"/>
6293
<!-- Uncomment to use alternate testing database configuration
6394
<env name="database.tests.hostname" value="localhost"/>
6495
<env name="database.tests.database" value="tests"/>

roave-bc-check.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
ignoreErrors:
3+
- '#\[BC\] SKIPPED: .+ could not be found in the located source#'

src/Controllers/Files.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php namespace Tatter\Files\Controllers;
22

33
use CodeIgniter\Controller;
4+
use CodeIgniter\Events\Events;
5+
use CodeIgniter\HTTP\Exceptions\HTTPException;
46
use CodeIgniter\HTTP\RedirectResponse;
57
use CodeIgniter\HTTP\RequestInterface;
68
use CodeIgniter\HTTP\ResponseInterface;
@@ -409,11 +411,19 @@ public function upload()
409411
$chunkDir = WRITEPATH . 'uploads/' . $uuid;
410412
if (! is_dir($chunkDir) && ! mkdir($chunkDir, 0775, true))
411413
{
412-
throw FilesException::forChunkDirFail($chunkDir);
414+
return $this->failure(400, lang('Files.chunkDirFail', [$chunkDir]));
413415
}
414416

415417
// Move the file
416-
$upload->move($chunkDir, $chunkIndex . '.' . $upload->getExtension());
418+
try
419+
{
420+
$upload->move($chunkDir, $chunkIndex . '.' . $upload->getExtension());
421+
}
422+
catch (HTTPException $e)
423+
{
424+
log_message('error', $e->getMessage());
425+
return $this->failure(400, $e->getMessage());
426+
}
417427

418428
// Check for more chunks
419429
if ($chunkIndex < $totalChunks - 1)
@@ -423,7 +433,15 @@ public function upload()
423433
}
424434

425435
// Merge the chunks
426-
$path = $this->mergeChunks($chunkDir);
436+
try
437+
{
438+
$path = $this->mergeChunks($chunkDir);
439+
}
440+
catch (FilesException $e)
441+
{
442+
log_message('error', $e->getMessage());
443+
return $this->failure(400, $e->getMessage());
444+
}
427445
}
428446

429447
// Get additional post data to pass to model
@@ -434,6 +452,9 @@ public function upload()
434452
// Accept the file
435453
$file = $this->model->createFromPath($path ?? $upload->getRealPath(), $data);
436454

455+
// Trigger the Event with the new File
456+
Events::trigger('upload', $file);
457+
437458
if ($this->request->isAJAX())
438459
{
439460
session_write_close();

src/Entities/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace Tatter\Files\Entities;
22

3-
use CodeIgniter\Entity;
3+
use CodeIgniter\Entity\Entity;
44
use CodeIgniter\Files\Exceptions\FileNotFoundException;
55
use Config\Mimes;
66
use Tatter\Files\Structures\FileObject;

tests/_support/FeatureTestCase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php namespace Tests\Support;
22

33
use CodeIgniter\Config\Factories;
4+
use CodeIgniter\Test\FeatureTestTrait;
45
use Config\Services;
6+
use Myth\Auth\Test\AuthTestTrait;
57
use Tatter\Files\Models\FileModel;
68
use Tests\Support\Models\UserModel;
79

810
class FeatureTestCase extends FilesTestCase
911
{
10-
use \CodeIgniter\Test\FeatureTestTrait;
11-
use \Myth\Auth\Test\AuthTestTrait;
12+
use AuthTestTrait, FeatureTestTrait;
1213

1314
/**
1415
* If present, will override application

0 commit comments

Comments
 (0)