Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance #579

Merged
merged 3 commits into from
Dec 16, 2021
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
20 changes: 8 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.2', '7.4']
db-type: [sqlite, mysql, pgsql]
php-version: ['7.4', '8.0', '8.1']
db-type: [mysql, pgsql]
prefer-lowest: ['']
include:
- php-version: '7.2'
Expand All @@ -25,9 +25,7 @@ jobs:
POSTGRES_PASSWORD: postgres

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/checkout@v2

- name: Setup Service
if: matrix.db-type == 'mysql'
Expand Down Expand Up @@ -56,32 +54,30 @@ jobs:
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi

if [[ ${{ matrix.php-version }} == '7.4' && ${{ matrix.db-type }} == 'sqlite' ]]; then
if [[ ${{ matrix.php-version }} == '7.4' && ${{ matrix.db-type }} == 'mysql' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi

- name: Code Coverage Report
if: success() && matrix.php-version == '7.4' && matrix.db-type == 'sqlite'
uses: codecov/codecov-action@v1
if: success() && matrix.php-version == '7.4' && matrix.db-type == 'mysql'
uses: codecov/codecov-action@v2

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, intl
coverage: none
tools: cs2pr, phpstan:0.12
tools: cs2pr, phpstan:1.2

- name: Composer Install
run: composer install
Expand Down
15 changes: 15 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ parameters:
message: "#^Constant ROOT not found\\.$#"
count: 1
path: src/File/Writer/DefaultWriter.php

-
message: "#^Parameter \\#1 \\$key of method Cake\\\\ORM\\\\Behavior\\:\\:setConfig\\(\\) expects array\\<string, mixed\\>\\|string, array\\<int\\|string, mixed\\> given\\.$#"
count: 1
path: src/Model/Behavior/UploadBehavior.php

-
message: "#^Cannot use array destructuring on array\\|false\\.$#"
count: 4
path: src/Validation/DefaultValidation.php

-
message: "#^Cannot use array destructuring on array\\|false\\.$#"
count: 4
path: src/Validation/ImageValidation.php
2 changes: 2 additions & 0 deletions src/Model/Behavior/UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function afterDelete(EventInterface $event, EntityInterface $entity, Arra
*/
public function getPathProcessor(EntityInterface $entity, $data, string $field, array $settings): ProcessorInterface
{
/** @var class-string<\Josegonzalez\Upload\File\Path\ProcessorInterface> $processorClass */
$processorClass = Hash::get($settings, 'pathProcessor', DefaultProcessor::class);

return new $processorClass($this->_table, $entity, $data, $field, $settings);
Expand All @@ -213,6 +214,7 @@ public function getWriter(
string $field,
array $settings
): WriterInterface {
/** @var class-string<\Josegonzalez\Upload\File\Writer\WriterInterface> $writerClass */
$writerClass = Hash::get($settings, 'writer', DefaultWriter::class);

return new $writerClass($this->_table, $entity, $data, $field, $settings);
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 @@ -71,7 +71,7 @@ public function testDelete()
$filesystem->expects($this->at(0))->method('delete');
$filesystem->expects($this->at(1))->method('delete')->will($this->throwException(new UnableToDeleteFile()));
$writer = $this->getMockBuilder('Josegonzalez\Upload\File\Writer\DefaultWriter')
->setMethods(['getFilesystem'])
->onlyMethods(['getFilesystem'])
->setConstructorArgs([$this->table, $this->entity, $this->data, $this->field, $this->settings])
->getMock();
$writer->expects($this->any())->method('getFilesystem')->will($this->returnValue($filesystem));
Expand Down
53 changes: 25 additions & 28 deletions tests/TestCase/Model/Behavior/UploadBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use ArrayObject;
use Cake\Event\Event;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Josegonzalez\Upload\File\Transformer\SlugTransformer;
use Josegonzalez\Upload\Model\Behavior\UploadBehavior;
Expand All @@ -16,7 +15,7 @@

class UploadBehaviorTest extends TestCase
{
public $fixtures = [
protected $fixtures = [
'plugin.Josegonzalez/Upload.Files',
];

Expand Down Expand Up @@ -56,11 +55,9 @@ public function setUp(): void

$this->behavior = new UploadBehavior($this->table, []);
$this->processor = $this->getMockBuilder('Josegonzalez\Upload\File\Path\DefaultProcessor')
->setMethods([])
->setConstructorArgs([$this->table, $this->entity, $this->dataOk[$this->field], $this->field, $this->settings])
->getMock();
$this->writer = $this->getMockBuilder('Josegonzalez\Upload\File\Writer\DefaultWriter')
->setMethods([])
->setConstructorArgs([$this->table, $this->entity, $this->dataOk[$this->field], $this->field, $this->settings])
->getMock();
$this->behaviorMethods = get_class_methods('Josegonzalez\Upload\Model\Behavior\UploadBehavior');
Expand All @@ -70,7 +67,7 @@ public function testInitialize()
{
$table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
$schema = $this->getMockBuilder('Cake\Database\Schema\TableSchema')
->setMethods(['setColumnType', 'getSchema', 'setSchema'])
->onlyMethods(['setColumnType'])
->disableOriginalConstructor()
->getMock();
$schema->expects($this->once())
Expand All @@ -85,7 +82,7 @@ public function testInitialize()

$methods = array_diff($this->behaviorMethods, ['initialize']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->disableOriginalConstructor()
->getMock();
$reflection = new ReflectionClass($behavior);
Expand All @@ -102,7 +99,7 @@ public function testInitialize()

public function testInheritedConfig()
{
$table = TableRegistry::get('Josegonzales/Upload.Files');
$table = $this->getTableLocator()->get('Josegonzales/Upload.Files');
$behavior = new ChildBehavior($table, []);

$result = $behavior->getConfig();
Expand All @@ -115,7 +112,7 @@ public function testInitializeIndexedConfig()
$settings = ['field'];
$table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
$schema = $this->getMockBuilder('Cake\Database\Schema\TableSchema')
->setMethods(['setColumnType', 'getSchema', 'setSchema'])
->onlyMethods(['setColumnType'])
->disableOriginalConstructor()
->getMock();
$schema->expects($this->once())
Expand All @@ -130,7 +127,7 @@ public function testInitializeIndexedConfig()

$methods = array_diff($this->behaviorMethods, ['initialize', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->disableOriginalConstructor()
->getMock();
$reflection = new ReflectionClass($behavior);
Expand All @@ -150,7 +147,7 @@ public function testInitializeAddBehaviorOptionsInterfaceConfig()
];
$table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
$schema = $this->getMockBuilder('Cake\Database\Schema\TableSchema')
->setMethods(['setColumnType', 'getSchema', 'setSchema'])
->onlyMethods(['setColumnType'])
->disableOriginalConstructor()
->getMock();
$schema->expects($this->once())
Expand All @@ -166,7 +163,7 @@ public function testInitializeAddBehaviorOptionsInterfaceConfig()
$methods = array_diff($this->behaviorMethods, ['initialize', 'setConfig', 'getConfig']);
//$behavior = $this->getMock('Josegonzalez\Upload\Model\Behavior\UploadBehavior', $methods, [$table, $settings], '', false);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->disableOriginalConstructor()
->getMock();

Expand All @@ -193,7 +190,7 @@ public function testBeforeMarshalOk()

$methods = array_diff($this->behaviorMethods, ['beforeMarshal']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$table, $this->settings])
->getMock();
$behavior->expects($this->any())
Expand Down Expand Up @@ -223,7 +220,7 @@ public function testBeforeMarshalError()

$methods = array_diff($this->behaviorMethods, ['beforeMarshal']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$table, $this->settings])
->getMock();
$behavior->expects($this->any())
Expand All @@ -249,7 +246,7 @@ public function testBeforeMarshalEmptyAllowed()

$methods = array_diff($this->behaviorMethods, ['beforeMarshal']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$table, $this->settings])
->getMock();
$behavior->expects($this->any())
Expand All @@ -267,7 +264,7 @@ public function testBeforeSaveNoUpload()

$methods = array_diff($this->behaviorMethods, ['beforeSave', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->settings])
->getMock();
$behavior->setConfig($this->settings);
Expand Down Expand Up @@ -296,7 +293,7 @@ public function testBeforeSaveNoWrite()
{
$methods = array_diff($this->behaviorMethods, ['beforeSave', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->settings])
->getMock();
$behavior->setConfig($this->settings);
Expand Down Expand Up @@ -324,7 +321,7 @@ public function testBeforeSaveOk()
{
$methods = array_diff($this->behaviorMethods, ['beforeSave', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->settings])
->getMock();
$behavior->setConfig($this->settings);
Expand Down Expand Up @@ -358,7 +355,7 @@ public function testBeforeSaveDoesNotRestoreOriginalValue()

$methods = array_diff($this->behaviorMethods, ['beforeSave', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->settings])
->getMock();
$behavior->setConfig($settings);
Expand All @@ -375,7 +372,7 @@ public function testBeforeSaveWithProtectedFieldName()

$methods = array_diff($this->behaviorMethods, ['beforeSave', 'config', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->settings])
->getMock();
$behavior->setConfig($settings);
Expand Down Expand Up @@ -408,7 +405,7 @@ public function testAfterDeleteOk()
{
$methods = array_diff($this->behaviorMethods, ['afterDelete', 'config', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->dataOk])
->getMock();
$behavior->setConfig($this->configOk);
Expand All @@ -430,7 +427,7 @@ public function testAfterDeleteFail()
{
$methods = array_diff($this->behaviorMethods, ['afterDelete', 'config', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->dataOk])
->getMock();
$behavior->setConfig($this->configOk);
Expand All @@ -452,7 +449,7 @@ public function testAfterDeleteSkip()
{
$methods = array_diff($this->behaviorMethods, ['afterDelete', 'config', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->dataError])
->getMock();
$behavior->setConfig($this->configError);
Expand All @@ -474,7 +471,7 @@ public function testAfterDeleteUsesPathProcessorToDetectPathToTheFile()

$methods = array_diff($this->behaviorMethods, ['afterDelete', 'config', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->dataOk])
->getMock();
$behavior->setConfig($this->configOk);
Expand Down Expand Up @@ -522,7 +519,7 @@ public function testAfterDeletePrefersStoredPathOverPathProcessor()

$methods = array_diff($this->behaviorMethods, ['afterDelete', 'config', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->dataOk])
->getMock();
$behavior->setConfig($this->configOk);
Expand Down Expand Up @@ -560,7 +557,7 @@ public function testAfterDeleteNoDeleteCallback()
$path = rand(1000, 9999) . DIRECTORY_SEPARATOR;
$methods = array_diff($this->behaviorMethods, ['afterDelete', 'config', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->dataOk])
->getMock();

Expand Down Expand Up @@ -591,7 +588,7 @@ public function testAfterDeleteUsesDeleteCallback()
$path = rand(1000, 9999) . DIRECTORY_SEPARATOR;
$methods = array_diff($this->behaviorMethods, ['afterDelete', 'config', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $this->dataOk])
->getMock();

Expand Down Expand Up @@ -631,7 +628,7 @@ public function testAfterDeleteWithProtectedFieldName()

$methods = array_diff($this->behaviorMethods, ['afterDelete', 'config', 'setConfig', 'getConfig']);
$behavior = $this->getMockBuilder('Josegonzalez\Upload\Model\Behavior\UploadBehavior')
->setMethods($methods)
->onlyMethods($methods)
->setConstructorArgs([$this->table, $settings])
->getMock();

Expand Down Expand Up @@ -743,7 +740,7 @@ public function testGetPathProcessor()

public function testNameCallback()
{
$table = TableRegistry::getTableLocator()->get('Files');
$table = $this->getTableLocator()->get('Files');
$behavior = new ChildBehavior($table, [
'filename' => [
'nameCallback' => function ($table, $entity, $data, $field, $settings) {
Expand Down
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
declare(strict_types=1);

use Cake\Core\Configure;

/*
* Test suite bootstrap
*
Expand All @@ -24,3 +26,5 @@
chdir($root);

require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';

Configure::write('Error.ignoredDeprecationPaths', ['src/TestSuite/Fixture/FixtureInjector.php']);