Skip to content

Commit be26b5a

Browse files
author
May
authored
Merge pull request #5 from MayMeow/development/implement-static-tesintg
Implementing static app testin
2 parents 81a7fb7 + 8a9d0ce commit be26b5a

File tree

11 files changed

+101
-12
lines changed

11 files changed

+101
-12
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, development/* ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
cs-check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Composer run action PHPC_CS
15+
uses: MayMeowHQ/composer-run-action@v3
16+
with:
17+
composer_script: 'cs-check'
18+
19+
stan:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Composer run action PHPStan
24+
uses: MayMeowHQ/composer-run-action@v3
25+
with:
26+
composer_script: 'stan'
27+
memory_limit: '1024M'

composer.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"cakephp/cakephp": "~4.1.0"
99
},
1010
"require-dev": {
11-
"phpunit/phpunit": "^8.0"
11+
"cakephp/cakephp-codesniffer": "^4.5",
12+
"phpstan/phpstan": "^0.12.99",
13+
"phpunit/phpunit": "^9.5"
1214
},
1315
"autoload": {
1416
"psr-4": {
@@ -18,7 +20,14 @@
1820
"autoload-dev": {
1921
"psr-4": {
2022
"FileUpload\\Test\\": "tests/",
21-
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
23+
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
24+
"App\\": "tests/test_app/src/"
2225
}
26+
},
27+
28+
"scripts": {
29+
"cs-check": "phpcs --colors -p src/ tests/",
30+
"cs-fix": "phpcbf --colors -p src/ tests/",
31+
"stan": "phpstan analyse"
2332
}
2433
}

docker-compose-dev.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "3"
2+
3+
services:
4+
app:
5+
build:
6+
args:
7+
user: vscode
8+
uid: 1000
9+
context: ./
10+
dockerfile: docker/devcontainer/Dockerfile
11+
working_dir: /app
12+
volumes:
13+
- "./:/app"

docker/devcontainer/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM ghcr.io/maymeow/php-ci-cd/php-ci-cd:7.4.16-cs-1
2+
3+
# arguments in docker-compose file
4+
ARG user=vscode
5+
ARG uid=1000
6+
7+
# Create system user to run Composer and Artisan Commands
8+
RUN useradd -G www-data,root -u $uid -d /home/$user $user
9+
RUN mkdir -p /home/$user/.composer && \
10+
chown -R $user:$user /home/$user
11+
12+
USER $user

phpcs.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="App">
3+
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer"/>
4+
5+
<rule ref="CakePHP"/>
6+
</ruleset>

phpstan.neon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
parameters:
2+
level: 7
3+
checkMissingIterableValueType: false
4+
treatPhpDocTypesAsCertain: false
5+
paths:
6+
- src
7+
bootstrapFiles:
8+
- tests/bootstrap.php
9+

src/Controller/Component/UploadComponent.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace FileUpload\Controller\Component;
55

66
use Cake\Controller\Component;
7-
use Cake\Controller\ComponentRegistry;
87
use Cake\Http\Exception\HttpException;
98
use Cake\Http\ServerRequest;
109
use Psr\Http\Message\UploadedFileInterface;
@@ -22,15 +21,16 @@ class UploadComponent extends Component
2221
protected $_defaultConfig = [
2322
'fieldName' => 'uploaded_file',
2423
'storagePath' => ROOT . DS . 'storage' . DS,
25-
'allowedFileTypes' => '*'
24+
'allowedFileTypes' => '*',
2625
];
2726

2827
/**
29-
* Move uploaded file to storage
28+
* @param \Cake\Http\ServerRequest $serverRequest Server Request
29+
* @return \Psr\Http\Message\UploadedFileInterface
3030
*/
31-
public function getFile(ServerRequest $serverRequest) : UploadedFileInterface
31+
public function getFile(ServerRequest $serverRequest): UploadedFileInterface
3232
{
33-
/** @var UploadedFileInterface */
33+
/** @var \Psr\Http\Message\UploadedFileInterface $fileObject */
3434
$fileObject = $serverRequest->getData($this->getConfig('fieldName'));
3535

3636
if ($this->_isAllowedFileType($fileObject->getClientMediaType())) {
@@ -43,11 +43,14 @@ public function getFile(ServerRequest $serverRequest) : UploadedFileInterface
4343
}
4444

4545
/**
46-
* Check if file type is allowd
46+
* @param string $fileType Type of the file
47+
* @return bool
4748
*/
48-
private function _isAllowedFileType(string $fileType) : bool
49+
private function _isAllowedFileType(string $fileType): bool
4950
{
50-
if ($this->getConfig('allowedFileTypes') == "*") return true;
51+
if ($this->getConfig('allowedFileTypes') == '*') {
52+
return true;
53+
}
5154

5255
if (is_array($this->getConfig('allowedFileTypes'))) {
5356
if (in_array($fileType, $this->getConfig('allowedFileTypes'))) {

src/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function (RouteBuilder $builder) {
5252
/**
5353
* Add middleware for the plugin.
5454
*
55-
* @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to update.
55+
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
5656
* @return \Cake\Http\MiddlewareQueue
5757
*/
5858
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
} while ($root !== $lastRoot);
1919

20-
throw new Exception("Cannot find the root of the application, unable to run tests");
20+
throw new Exception('Cannot find the root of the application, unable to run tests');
2121
};
2222
$root = $findRoot(__FILE__);
2323
unset($findRoot);

tests/phpstan-bootstrap.php

Whitespace-only changes.

0 commit comments

Comments
 (0)