Fixed coding style.

This commit is contained in:
Jan Böhmer 2020-05-10 21:39:31 +02:00
parent e9493e52ec
commit f5d685dfd4
71 changed files with 619 additions and 531 deletions

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -23,16 +26,16 @@ namespace App\Tests\Services\LabelSystem;
use App\Entity\LabelSystem\LabelOptions;
use App\Entity\Parts\Part;
use App\Services\LabelSystem\BarcodeGenerator;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
final class BarcodeGeneratorTest extends WebTestCase
{
/** @var BarcodeGenerator */
/**
* @var BarcodeGenerator
*/
protected $services;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->services = self::$container->get(BarcodeGenerator::class);
@ -50,7 +53,7 @@ final class BarcodeGeneratorTest extends WebTestCase
$content = $this->services->generateSVG($options, $part);
//When type is none, service must return null.
if ($type === 'none') {
if ('none' === $type) {
$this->assertNull($content);
} else {
$this->assertIsString($content);
@ -70,10 +73,10 @@ final class BarcodeGeneratorTest extends WebTestCase
$svg = $this->services->generateSVG($options, $part);
//When type is none, service must return null.
if ($type === "none") {
if ('none' === $type) {
$this->assertNull($svg);
} else {
$this->assertStringContainsStringIgnoringCase("SVG", $svg);
$this->assertStringContainsStringIgnoringCase('SVG', $svg);
}
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -24,21 +27,21 @@ use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class BarcodeContentGeneratorTest extends KernelTestCase
{
/** @var BarcodeContentGenerator */
/**
* @var BarcodeContentGenerator
*/
private $service;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(BarcodeContentGenerator::class);
}
public function Barcode1DDataProvider(): array
{
return [
@ -53,7 +56,7 @@ class BarcodeContentGeneratorTest extends KernelTestCase
return [
['/scan/part/0', Part::class],
['/scan/lot/0', PartLot::class],
['/scan/location/0', Storelocation::class]
['/scan/location/0', Storelocation::class],
];
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -21,16 +24,16 @@
namespace App\Tests\Services\LabelSystem\Barcodes;
use App\Services\LabelSystem\Barcodes\BarcodeNormalizer;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BarcodeNormalizerTest extends WebTestCase
{
/** @var BarcodeNormalizer */
/**
* @var BarcodeNormalizer
*/
protected $service;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(BarcodeNormalizer::class);
@ -80,7 +83,7 @@ class BarcodeNormalizerTest extends WebTestCase
/**
* @dataProvider dataProvider
*/
public function testNormalizeBarcodeContent(array $expected, string $input)
public function testNormalizeBarcodeContent(array $expected, string $input): void
{
$this->assertSame($expected, $this->service->normalizeBarcodeContent($input));
}
@ -88,7 +91,7 @@ class BarcodeNormalizerTest extends WebTestCase
/**
* @dataProvider invalidDataProvider
*/
public function testInvalidFormats(string $input)
public function testInvalidFormats(string $input): void
{
$this->expectException(\InvalidArgumentException::class);
$this->service->normalizeBarcodeContent($input);

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -22,15 +25,16 @@ namespace App\Tests\Services\LabelSystem\Barcodes;
use App\Services\LabelSystem\Barcodes\BarcodeRedirector;
use Doctrine\ORM\EntityNotFoundException;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class BarcodeRedirectorTest extends KernelTestCase
{
/** @var BarcodeRedirector */
/**
* @var BarcodeRedirector
*/
private $service;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(BarcodeRedirector::class);
@ -42,7 +46,7 @@ class BarcodeRedirectorTest extends KernelTestCase
['part', '/en/part/1'],
//Part lot redirects to Part info page (Part lot 1 is associated with part 3
['lot', '/en/part/3'],
['location', '/en/store_location/1/parts']
['location', '/en/store_location/1/parts'],
];
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -26,15 +29,16 @@ use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Services\LabelSystem\LabelGenerator;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class LabelGeneratorTest extends WebTestCase
{
/** @var LabelGenerator */
/**
* @var LabelGenerator
*/
protected $service;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(LabelGenerator::class);
@ -45,14 +49,14 @@ class LabelGeneratorTest extends WebTestCase
return [
['part', Part::class],
['part_lot', PartLot::class],
['storelocation', Storelocation::class]
['storelocation', Storelocation::class],
];
}
/**
* @dataProvider supportsDataProvider
*/
public function testSupports(string $type, string $class)
public function testSupports(string $type, string $class): void
{
$options = new LabelOptions();
$options->setSupportedElement($type);
@ -61,18 +65,17 @@ class LabelGeneratorTest extends WebTestCase
$this->assertTrue($this->service->supports($options, new $class()));
//Ensure that another class is not supported
$not_supported = new class extends AbstractDBElement {
$not_supported = new class() extends AbstractDBElement {
public function getIDString(): string
{
return "not_important";
return 'not_important';
}
};
$this->assertFalse($this->service->supports($options, $not_supported));
}
public function testMmToPointsArray()
public function testMmToPointsArray(): void
{
$this->assertSame(
[0.0, 0.0, 141.7325, 85.0395],
@ -80,7 +83,7 @@ class LabelGeneratorTest extends WebTestCase
);
}
public function testGenerateLabel()
public function testGenerateLabel(): void
{
$part = new Part();
$options = new LabelOptions();

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -22,20 +25,19 @@ namespace App\Tests\Services\LabelSystem;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Services\AmountFormatter;
use App\Services\LabelSystem\LabelTextReplacer;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class LabelTextReplacerTest extends WebTestCase
{
/**
* @var LabelTextReplacer
*/
protected $service;
/** @var Part */
/**
* @var Part
*/
protected $target;
protected function setUp(): void
@ -76,7 +78,7 @@ class LabelTextReplacerTest extends WebTestCase
['[[UNKNOWN]] Test', '[[UNKNOWN]] Test'],
["[[NAME\n]] [[NAME ]]", "[[NAME\n]] [[NAME ]]"],
['[[]]', '[[]]'],
['TEST[[ ]]TEST', 'TEST[[ ]]TEST']
['TEST[[ ]]TEST', 'TEST[[ ]]TEST'],
];
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -21,29 +24,25 @@
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\AbstractDBElementProvider;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AbstractElementProviderTest extends WebTestCase
{
/** @var AbstractDBElementProvider */
/**
* @var AbstractDBElementProvider
*/
protected $service;
protected $target;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(AbstractDBElementProvider::class);
$this->target = new class extends AbstractDBElement {
$this->target = new class() extends AbstractDBElement {
protected $id = 123;
/**
* @inheritDoc
*/
public function getIDString(): string
{
return 'ignore';

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -22,17 +25,18 @@ namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class GlobalProvidersTest extends WebTestCase
{
/** @var GlobalProviders */
/**
* @var GlobalProviders
*/
protected $service;
protected $target;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(GlobalProviders::class);

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -21,28 +24,23 @@
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use App\Services\LabelSystem\PlaceholderProviders\NamedElementProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class NamedElementProviderTest extends WebTestCase
{
/** @var NamedElementProvider */
/**
* @var NamedElementProvider
*/
protected $service;
protected $target;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(NamedElementProvider::class);
$this->target = new class implements NamedElementInterface {
/**
* @inheritDoc
*/
$this->target = new class() implements NamedElementInterface {
public function getName(): string
{
return 'This is my Name';
@ -53,7 +51,7 @@ class NamedElementProviderTest extends WebTestCase
public function dataProvider(): array
{
return [
['This is my Name', '[[NAME]]']
['This is my Name', '[[NAME]]'],
];
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,22 +23,22 @@
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Services\LabelSystem\PlaceholderProviders\NamedElementProvider;
use App\Services\LabelSystem\PlaceholderProviders\PartLotProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PartLotProviderTest extends WebTestCase
{
/** @var PartLotProvider */
/**
* @var PartLotProvider
*/
protected $service;
protected $target;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
\Locale::setDefault('en');

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,14 +23,10 @@
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use App\Services\LabelSystem\PlaceholderProviders\PartProvider;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -36,15 +35,19 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/
class PartProviderTest extends WebTestCase
{
/** @var PartProvider */
/**
* @var PartProvider
*/
protected $service;
protected $target;
/** @var \Doctrine\ORM\EntityManager */
/**
* @var \Doctrine\ORM\EntityManager
*/
protected $em;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(PartProvider::class);

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -28,29 +31,24 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class TimestampableElementProviderTest extends WebTestCase
{
/** @var GlobalProviders */
/**
* @var GlobalProviders
*/
protected $service;
protected $target;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
\Locale::setDefault('en');
$this->service = self::$container->get(TimestampableElementProvider::class);
$this->target = new class implements TimeStampableInterface {
/**
* @inheritDoc
*/
$this->target = new class() implements TimeStampableInterface {
public function getLastModified(): ?DateTime
{
return new \DateTime('2000-01-01');
}
/**
* @inheritDoc
*/
public function getAddedDate(): ?DateTime
{
return new \DateTime('2000-01-01');

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -24,18 +27,18 @@ use App\Entity\LabelSystem\LabelOptions;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Services\LabelSystem\Barcodes\BarcodeExampleElementsGenerator;
use App\Services\LabelSystem\SandboxedTwigProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Twig\Sandbox\SecurityError;
class SandboxedTwigProviderTest extends WebTestCase
{
/** @var SandboxedTwigProvider */
/**
* @var SandboxedTwigProvider
*/
private $service;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(SandboxedTwigProvider::class);
@ -65,26 +68,25 @@ class SandboxedTwigProviderTest extends WebTestCase
'],
['
{{ part.reviewNeeded }} {{ part.tags }} {{ part.mass }}
']
'],
];
}
public function twigNotAllowedDataProvider(): array
{
return [
["{% block test %} {% endblock %}"],
["{% deprecated test %}"],
["{% flush %}"],
['{% block test %} {% endblock %}'],
['{% deprecated test %}'],
['{% flush %}'],
["{{ part.setName('test') }}"],
["{{ part.setCategory(null) }}"]
['{{ part.setCategory(null) }}'],
];
}
/**
* @dataProvider twigDataProvider
*/
public function testTwigFeatures(string $twig)
public function testTwigFeatures(string $twig): void
{
$options = new LabelOptions();
$options->setSupportedElement('part');
@ -104,7 +106,7 @@ class SandboxedTwigProviderTest extends WebTestCase
/**
* @dataProvider twigNotAllowedDataProvider
*/
public function testTwigForbidden(string $twig)
public function testTwigForbidden(string $twig): void
{
$this->expectException(SecurityError::class);

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -30,7 +33,7 @@ class RangeParserTest extends WebTestCase
*/
protected $service;
public function setUp(): void
protected function setUp(): void
{
self::bootKernel();
$this->service = self::$container->get(RangeParser::class);
@ -42,19 +45,19 @@ class RangeParserTest extends WebTestCase
[[], ''],
[[], ' '],
[[], "\t"],
[[1], "1"],
[[1, 2, 3], "1,2, 3"],
[[1, 2, 3], "1-3"],
[[1, 2, 3, 4], "1- 3, 4"],
[[1, 2, 3, 4], "1, 2,3 - 4"],
[[1, 2, 3], " 1; 2, 3"],
[[-1, 0, 1, 2], "-1; 0; 1, 2"],
[[4,3, 1, 2], "4,3, 1;2"],
[[1, 2, 3, 4], "2-1, 3-4"],
[[1], "1-1"],
[[-3, -2, -1], "-3--1"],
[[1, 2, 3], "1,,2;;,,3"],
[[100, 1000, 1], "100, 1000, 1"],
[[1], '1'],
[[1, 2, 3], '1,2, 3'],
[[1, 2, 3], '1-3'],
[[1, 2, 3, 4], '1- 3, 4'],
[[1, 2, 3, 4], '1, 2,3 - 4'],
[[1, 2, 3], ' 1; 2, 3'],
[[-1, 0, 1, 2], '-1; 0; 1, 2'],
[[4, 3, 1, 2], '4,3, 1;2'],
[[1, 2, 3, 4], '2-1, 3-4'],
[[1], '1-1'],
[[-3, -2, -1], '-3--1'],
[[1, 2, 3], '1,,2;;,,3'],
[[100, 1000, 1], '100, 1000, 1'],
[[], 'test', true],
[[], '1-2-3-4,5', true],
[[], '1 2 3, 455, 23', true],