Added an PHP CS fixer config file and applied it to files.

We now use the same the same style as the symfony project, and it allows us to simply fix the style by executing php_cs_fixer fix in the project root.
This commit is contained in:
Jan Böhmer 2019-11-09 00:47:20 +01:00
parent 89258bc102
commit e557bdedd5
210 changed files with 2099 additions and 2742 deletions

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,15 +17,12 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services\Attachments;
use App\Services\AmountFormatter;
use App\Services\Attachments\AttachmentPathResolver;
use ReflectionClass;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AttachmentPathResolverTest extends WebTestCase
@ -47,8 +44,8 @@ class AttachmentPathResolverTest extends WebTestCase
self::bootKernel();
self::$projectDir_orig = realpath(self::$kernel->getProjectDir());
self::$projectDir = str_replace('\\', '/', self::$projectDir_orig);
self::$media_path = self::$projectDir . '/public/media';
self::$footprint_path = self::$projectDir . '/public/img/footprints';
self::$media_path = self::$projectDir.'/public/media';
self::$footprint_path = self::$projectDir.'/public/img/footprints';
}
public static function setUpBeforeClass()
@ -69,8 +66,8 @@ class AttachmentPathResolverTest extends WebTestCase
$this->assertEquals(self::$projectDir_orig, self::$service->parameterToAbsolutePath(self::$projectDir));
//Relative pathes should be resolved
$this->assertEquals(self::$projectDir_orig . DIRECTORY_SEPARATOR . 'src', self::$service->parameterToAbsolutePath('src'));
$this->assertEquals(self::$projectDir_orig . DIRECTORY_SEPARATOR . 'src', self::$service->parameterToAbsolutePath('./src'));
$this->assertEquals(self::$projectDir_orig.\DIRECTORY_SEPARATOR.'src', self::$service->parameterToAbsolutePath('src'));
$this->assertEquals(self::$projectDir_orig.\DIRECTORY_SEPARATOR.'src', self::$service->parameterToAbsolutePath('./src'));
//Invalid pathes should return null
$this->assertNull(self::$service->parameterToAbsolutePath('/this/path/does/not/exist'));
@ -80,9 +77,9 @@ class AttachmentPathResolverTest extends WebTestCase
public function placeholderDataProvider()
{
return [
['%FOOTPRINTS%/test/test.jpg', self::$footprint_path . '/test/test.jpg'],
['%FOOTPRINTS%/test/', self::$footprint_path . '/test/'],
['%MEDIA%/test', self::$media_path . '/test'],
['%FOOTPRINTS%/test/test.jpg', self::$footprint_path.'/test/test.jpg'],
['%FOOTPRINTS%/test/', self::$footprint_path.'/test/'],
['%MEDIA%/test', self::$media_path.'/test'],
['%MEDIA%', self::$media_path],
['%FOOTPRINTS%', self::$footprint_path],
//Footprints 3D are disabled
@ -95,24 +92,24 @@ class AttachmentPathResolverTest extends WebTestCase
['%FOOTPRINTS%/%MEDIA%', null], //No more than one placholder
['%FOOTPRINTS%/%FOOTPRINTS%', null],
['%FOOTPRINTS%/../../etc/passwd', null],
['%FOOTPRINTS%/0\..\test', null]
['%FOOTPRINTS%/0\..\test', null],
];
}
public function realPathDataProvider()
{
return [
[self::$media_path . '/test/img.jpg', '%MEDIA%/test/img.jpg'],
[self::$media_path . '/test/img.jpg', '%BASE%/data/media/test/img.jpg', true],
[self::$footprint_path . '/foo.jpg', '%FOOTPRINTS%/foo.jpg'],
[self::$footprint_path . '/foo.jpg', '%FOOTPRINTS%/foo.jpg', true],
[self::$media_path.'/test/img.jpg', '%MEDIA%/test/img.jpg'],
[self::$media_path.'/test/img.jpg', '%BASE%/data/media/test/img.jpg', true],
[self::$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg'],
[self::$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg', true],
//Every kind of absolute path, that is not based with our placeholder dirs must be invald
['/etc/passwd', null],
['C:\\not\\existing.txt', null],
//More then one placeholder is not allowed
[self::$footprint_path . '/test/' . self::$footprint_path, null],
[self::$footprint_path.'/test/'.self::$footprint_path, null],
//Path must begin with path
['/not/root' . self::$footprint_path, null]
['/not/root'.self::$footprint_path, null],
];
}
@ -131,4 +128,4 @@ class AttachmentPathResolverTest extends WebTestCase
{
$this->assertEquals($expected, self::$service->realPathToPlaceholder($param, $old_method));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,19 +17,16 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services\Attachments;
use App\Services\Attachments\AttachmentURLGenerator;
use App\Services\Attachments\BuiltinAttachmentsFinder;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AttachmentURLGeneratorTest extends WebTestCase
{
protected const PUBLIC_DIR = "/public";
protected const PUBLIC_DIR = '/public';
protected static $service;
@ -47,12 +44,13 @@ class AttachmentURLGeneratorTest extends WebTestCase
['/public/folder/test.jpg', 'folder/test.jpg'],
['/not/public/test.jpg', null],
['/public/', ''],
['not/absolute/test.jpg', null]
['not/absolute/test.jpg', null],
];
}
/**
* @dataProvider dataProvider
*
* @param $input
* @param $expected
*/
@ -60,4 +58,4 @@ class AttachmentURLGeneratorTest extends WebTestCase
{
$this->assertEquals($expected, static::$service->absolutePathToAssetPath($input, static::PUBLIC_DIR));
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services\Attachments;
@ -32,7 +31,7 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
protected static $mock_list = [
'%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/test/test.png', '%FOOTPRINTS%/123.jpg', '%FOOTPRINTS%/123.jpeg',
'%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt'
'%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt',
];
public static function setUpBeforeClass()
@ -51,11 +50,10 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
//Basic search for keyword
['test', [], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/test/test.png', '%FOOTPRINTS_3D%/test.jpg']],
['%FOOTPRINTS_3D%', [], ['%FOOTPRINTS_3D%/test.jpg', '%FOOTPRINTS_3D%/hallo.txt']],
['.txt', [], ['%FOOTPRINTS_3D%/hallo.txt'] ],
['.txt', [], ['%FOOTPRINTS_3D%/hallo.txt']],
//Filter extensions
//['test', ['allowed_extensions' => ['jpeg', 'jpg']], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS%/123.jpeg', '%FOOTPRINTS_3D%/test.jpg']],
//['test.jpg', ['allowed_extensions' => ['jpeg', 'jpg']], ['%FOOTPRINTS%/test/test.jpg', '%FOOTPRINTS_3D%/test.jpg']]
];
}
@ -69,4 +67,4 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
$this->assertEquals([], array_diff($value, $expected), 'Additional');
$this->assertEquals([], array_diff($expected, $value), 'Missing:');
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
*
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
namespace App\Tests\Services\Attachments;
@ -35,7 +34,7 @@ class FileTypeFilterToolsTest extends WebTestCase
self::$service = self::$container->get(FileTypeFilterTools::class);
}
public function validateDataProvider() : array
public function validateDataProvider(): array
{
return [
['', true], //Empty string is valid
@ -47,11 +46,11 @@ class FileTypeFilterToolsTest extends WebTestCase
['test.png', false], //No full filename
['application/*', false], //Only certain placeholders are allowed
['.png;.png,.jpg', false], //Wrong separator
['.png .jpg .gif', false]
['.png .jpg .gif', false],
];
}
public function normalizeDataProvider() : array
public function normalizeDataProvider(): array
{
return [
['', ''],
@ -67,7 +66,7 @@ class FileTypeFilterToolsTest extends WebTestCase
];
}
public function extensionAllowedDataProvider() : array
public function extensionAllowedDataProvider(): array
{
return [
['', 'txt', true],
@ -88,10 +87,9 @@ class FileTypeFilterToolsTest extends WebTestCase
}
/**
* Test the validateFilterString method
* Test the validateFilterString method.
*
* @dataProvider validateDataProvider
* @param string $filter
* @param bool $expected
*/
public function testValidateFilterString(string $filter, bool $expected)
{
@ -100,8 +98,6 @@ class FileTypeFilterToolsTest extends WebTestCase
/**
* @dataProvider normalizeDataProvider
* @param string $filter
* @param string $expected
*/
public function testNormalizeFilterString(string $filter, string $expected)
{
@ -115,4 +111,4 @@ class FileTypeFilterToolsTest extends WebTestCase
{
$this->assertEquals($expected, self::$service->isExtensionAllowed($filter, $extension), $expected);
}
}
}