Fixed tests coding style.

This commit is contained in:
Jan Böhmer 2020-03-15 13:57:50 +01:00
parent fd61c8d9e2
commit da09873be5
6 changed files with 37 additions and 42 deletions

View file

@ -42,7 +42,6 @@ declare(strict_types=1);
namespace App\Tests; namespace App\Tests;
use App\Entity\Parts\Manufacturer;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/** /**

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* 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).
* *
@ -20,16 +23,14 @@
namespace App\Tests; namespace App\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DatatablesAvailabilityTest extends WebTestCase class DatatablesAvailabilityTest extends WebTestCase
{ {
/** /**
* @dataProvider urlProvider * @dataProvider urlProvider
* @param string $url
*/ */
public function testDataTable(string $url) public function testDataTable(string $url): void
{ {
//We have localized routes //We have localized routes
$url = '/en'.$url; $url = '/en'.$url;
@ -63,6 +64,5 @@ class DatatablesAvailabilityTest extends WebTestCase
yield ['/log/']; yield ['/log/'];
yield ['/attachment/list']; yield ['/attachment/list'];
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* 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).
* *
@ -24,6 +27,7 @@ use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType; use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\PartAttachment; use App\Entity\Attachments\PartAttachment;
use App\Entity\Devices\Device; use App\Entity\Devices\Device;
use App\Entity\Devices\DevicePart;
use App\Entity\LogSystem\AbstractLogEntry; use App\Entity\LogSystem\AbstractLogEntry;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
@ -34,11 +38,9 @@ use App\Entity\Parts\Supplier;
use App\Entity\UserSystem\Group; use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use App\Entity\Devices\DevicePart;
class AbstractLogEntryTest extends TestCase class AbstractLogEntryTest extends TestCase
{ {
public function levelDataProvider(): array public function levelDataProvider(): array
{ {
return [ return [
@ -51,7 +53,7 @@ class AbstractLogEntryTest extends TestCase
[6, 'info'], [6, 'info'],
[7, 'debug'], [7, 'debug'],
[8, 'blabla', true], [8, 'blabla', true],
[-1, 'test', true] [-1, 'test', true],
]; ];
} }
@ -70,14 +72,14 @@ class AbstractLogEntryTest extends TestCase
[10, Part::class], [10, Part::class],
[11, Storelocation::class], [11, Storelocation::class],
[12, Supplier::class], [12, Supplier::class],
[-1, 'blablub', true] [-1, 'blablub', true],
]; ];
} }
/** /**
* @dataProvider levelDataProvider * @dataProvider levelDataProvider
*/ */
public function testLevelIntToString(int $int, string $expected_string, bool $expect_exception = false) public function testLevelIntToString(int $int, string $expected_string, bool $expect_exception = false): void
{ {
if ($expect_exception) { if ($expect_exception) {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
@ -88,7 +90,7 @@ class AbstractLogEntryTest extends TestCase
/** /**
* @dataProvider levelDataProvider * @dataProvider levelDataProvider
*/ */
public function testLevelStringToInt(int $expected_int, string $string, bool $expect_exception = false) public function testLevelStringToInt(int $expected_int, string $string, bool $expect_exception = false): void
{ {
if ($expect_exception) { if ($expect_exception) {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
@ -99,7 +101,7 @@ class AbstractLogEntryTest extends TestCase
/** /**
* @dataProvider targetTypeDataProvider * @dataProvider targetTypeDataProvider
*/ */
public function testTargetTypeIdToClass(int $int, string $expected_class, bool $expect_exception = false) public function testTargetTypeIdToClass(int $int, string $expected_class, bool $expect_exception = false): void
{ {
if ($expect_exception) { if ($expect_exception) {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
@ -110,7 +112,7 @@ class AbstractLogEntryTest extends TestCase
/** /**
* @dataProvider targetTypeDataProvider * @dataProvider targetTypeDataProvider
*/ */
public function testTypeClassToID(int $expected_id, string $class, bool $expect_exception = false) public function testTypeClassToID(int $expected_id, string $class, bool $expect_exception = false): void
{ {
if ($expect_exception) { if ($expect_exception) {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
@ -118,18 +120,19 @@ class AbstractLogEntryTest extends TestCase
$this->assertSame($expected_id, AbstractLogEntry::targetTypeClassToID($class)); $this->assertSame($expected_id, AbstractLogEntry::targetTypeClassToID($class));
} }
public function testTypeClassToIDSubclasses() public function testTypeClassToIDSubclasses(): void
{ {
//Test if class mapping works for subclasses //Test if class mapping works for subclasses
$this->assertSame(2, AbstractLogEntry::targetTypeClassToID(PartAttachment::class)); $this->assertSame(2, AbstractLogEntry::targetTypeClassToID(PartAttachment::class));
} }
public function testSetGetTarget() public function testSetGetTarget(): void
{ {
$part = $this->createMock(Part::class); $part = $this->createMock(Part::class);
$part->method('getID')->willReturn(10); $part->method('getID')->willReturn(10);
$log = new class extends AbstractLogEntry {}; $log = new class() extends AbstractLogEntry {
};
$log->setTargetElement($part); $log->setTargetElement($part);
$this->assertSame(Part::class, $log->getTargetClass()); $this->assertSame(Part::class, $log->getTargetClass());

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* 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).
* *
@ -25,7 +28,6 @@ use PHPUnit\Framework\TestCase;
class PartParameterTest extends TestCase class PartParameterTest extends TestCase
{ {
public function valueWithUnitDataProvider(): array public function valueWithUnitDataProvider(): array
{ {
return [ return [
@ -53,9 +55,6 @@ class PartParameterTest extends TestCase
/** /**
* @dataProvider valueWithUnitDataProvider * @dataProvider valueWithUnitDataProvider
* @param string $expected
* @param float $value
* @param string $unit
*/ */
public function testGetValueMinWithUnit(string $expected, float $value, string $unit): void public function testGetValueMinWithUnit(string $expected, float $value, string $unit): void
{ {
@ -67,9 +66,6 @@ class PartParameterTest extends TestCase
/** /**
* @dataProvider valueWithUnitDataProvider * @dataProvider valueWithUnitDataProvider
* @param string $expected
* @param float $value
* @param string $unit
*/ */
public function testGetValueMaxWithUnit(string $expected, float $value, string $unit): void public function testGetValueMaxWithUnit(string $expected, float $value, string $unit): void
{ {
@ -81,9 +77,6 @@ class PartParameterTest extends TestCase
/** /**
* @dataProvider valueWithUnitDataProvider * @dataProvider valueWithUnitDataProvider
* @param string $expected
* @param float $value
* @param string $unit
*/ */
public function testGetValueTypicalWithUnit(string $expected, float $value, string $unit): void public function testGetValueTypicalWithUnit(string $expected, float $value, string $unit): void
{ {
@ -95,12 +88,10 @@ class PartParameterTest extends TestCase
/** /**
* @dataProvider formattedValueDataProvider * @dataProvider formattedValueDataProvider
* @param string $expected *
* @param float $min * @param float $min
* @param float $typical * @param float $typical
* @param float $max * @param float $max
* @param string $unit
* @param string $text
*/ */
public function testGetFormattedValue(string $expected, ?float $min, ?float $typical, ?float $max, string $unit, string $text): void public function testGetFormattedValue(string $expected, ?float $min, ?float $typical, ?float $max, string $unit, string $text): void
{ {

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* 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).
* *
@ -21,8 +24,6 @@
namespace App\Tests\Services\LogSystem; namespace App\Tests\Services\LogSystem;
use App\Services\LogSystem\EventCommentHelper; use App\Services\LogSystem\EventCommentHelper;
use App\Services\LogSystem\EventLogger;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class EventCommentHelperTest extends WebTestCase class EventCommentHelperTest extends WebTestCase
@ -41,13 +42,13 @@ class EventCommentHelperTest extends WebTestCase
$this->service = self::$container->get(EventCommentHelper::class); $this->service = self::$container->get(EventCommentHelper::class);
} }
public function testInitialState() public function testInitialState(): void
{ {
$this->assertNull($this->service->getMessage()); $this->assertNull($this->service->getMessage());
$this->assertFalse($this->service->isMessageSet()); $this->assertFalse($this->service->isMessageSet());
} }
public function testClearMessage() public function testClearMessage(): void
{ {
$this->service->setMessage('Test'); $this->service->setMessage('Test');
$this->assertTrue($this->service->isMessageSet()); $this->assertTrue($this->service->isMessageSet());
@ -55,13 +56,13 @@ class EventCommentHelperTest extends WebTestCase
$this->assertFalse($this->service->isMessageSet()); $this->assertFalse($this->service->isMessageSet());
} }
public function testGetSetMessage() public function testGetSetMessage(): void
{ {
$this->service->setMessage('Test'); $this->service->setMessage('Test');
$this->assertSame('Test', $this->service->getMessage()); $this->assertSame('Test', $this->service->getMessage());
} }
public function testIsMessageSet() public function testIsMessageSet(): void
{ {
$this->service->setMessage('Test'); $this->service->setMessage('Test');
$this->assertTrue($this->service->isMessageSet()); $this->assertTrue($this->service->isMessageSet());

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* 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).
* *
@ -28,7 +31,6 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class EventLoggerTest extends WebTestCase class EventLoggerTest extends WebTestCase
{ {
/** /**
* @var EventLogger * @var EventLogger
*/ */
@ -43,13 +45,12 @@ class EventLoggerTest extends WebTestCase
$this->service = self::$container->get(EventLogger::class); $this->service = self::$container->get(EventLogger::class);
} }
public function testShouldBeAdded() public function testShouldBeAdded(): void
{ {
$event1 = new UserLoginLogEntry('127.0.0.1'); $event1 = new UserLoginLogEntry('127.0.0.1');
$event2 = new UserLogoutLogEntry('127.0.0.1'); $event2 = new UserLogoutLogEntry('127.0.0.1');
$event2->setLevel(AbstractLogEntry::LEVEL_CRITICAL); $event2->setLevel(AbstractLogEntry::LEVEL_CRITICAL);
//Test without restrictions //Test without restrictions
$this->assertTrue($this->service->shouldBeAdded($event1, 7, [], [])); $this->assertTrue($this->service->shouldBeAdded($event1, 7, [], []));