mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-04 02:05:16 +02:00
Applied code style to tests/
This commit is contained in:
parent
f861de791f
commit
fe0f69f762
44 changed files with 427 additions and 306 deletions
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -32,7 +35,7 @@ class AmountFormatterTest extends WebTestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
|
@ -41,56 +44,56 @@ class AmountFormatterTest extends WebTestCase
|
|||
$this->service = self::$container->get(AmountFormatter::class);
|
||||
}
|
||||
|
||||
public function testFormatWithoutUnit()
|
||||
public function testFormatWithoutUnit(): void
|
||||
{
|
||||
$this->assertEquals('2', $this->service->format(2.321));
|
||||
$this->assertEquals('1002', $this->service->format(1002.356));
|
||||
$this->assertEquals('1000454', $this->service->format(1000454.0));
|
||||
$this->assertEquals('0', $this->service->format(0.01));
|
||||
$this->assertEquals('0', $this->service->format(0));
|
||||
$this->assertSame('2', $this->service->format(2.321));
|
||||
$this->assertSame('1002', $this->service->format(1002.356));
|
||||
$this->assertSame('1000454', $this->service->format(1000454.0));
|
||||
$this->assertSame('0', $this->service->format(0.01));
|
||||
$this->assertSame('0', $this->service->format(0));
|
||||
}
|
||||
|
||||
public function testInvalidInput()
|
||||
public function testInvalidInput(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->service->format('test');
|
||||
}
|
||||
|
||||
public function testFormatUnitWithoutSI()
|
||||
public function testFormatUnitWithoutSI(): void
|
||||
{
|
||||
$meters = new MeasurementUnit();
|
||||
$meters->setIsInteger(false)->setUseSIPrefix(false)->setUnit('m');
|
||||
|
||||
$this->assertEquals('0.32 m', $this->service->format(0.3245, $meters));
|
||||
$this->assertEquals('10003.56 m', $this->service->format(10003.556, $meters));
|
||||
$this->assertEquals('0.00 m', $this->service->format(0.0004, $meters));
|
||||
$this->assertSame('0.32 m', $this->service->format(0.3245, $meters));
|
||||
$this->assertSame('10003.56 m', $this->service->format(10003.556, $meters));
|
||||
$this->assertSame('0.00 m', $this->service->format(0.0004, $meters));
|
||||
}
|
||||
|
||||
public function testFormatUnitWithSI()
|
||||
public function testFormatUnitWithSI(): void
|
||||
{
|
||||
$meters = new MeasurementUnit();
|
||||
$meters->setIsInteger(false)->setUseSIPrefix(true)->setUnit('m');
|
||||
|
||||
$this->assertEquals('0.32 m', $this->service->format(0.3245, $meters));
|
||||
$this->assertEquals('12.32 m', $this->service->format(12.323, $meters));
|
||||
$this->assertEquals('120.32 km', $this->service->format(120320.45, $meters));
|
||||
$this->assertSame('0.32 m', $this->service->format(0.3245, $meters));
|
||||
$this->assertSame('12.32 m', $this->service->format(12.323, $meters));
|
||||
$this->assertSame('120.32 km', $this->service->format(120320.45, $meters));
|
||||
|
||||
$this->assertEquals('0.32 mm', $this->service->format(0.00032, $meters));
|
||||
$this->assertSame('0.32 mm', $this->service->format(0.00032, $meters));
|
||||
}
|
||||
|
||||
public function testFormatMoreDigits()
|
||||
public function testFormatMoreDigits(): void
|
||||
{
|
||||
$this->assertEquals('12.12345', $this->service->format(12.1234532, null, ['is_integer' => false, 'decimals' => 5]));
|
||||
$this->assertEquals('12.1', $this->service->format(12.1234532, null, ['is_integer' => false, 'decimals' => 1]));
|
||||
$this->assertSame('12.12345', $this->service->format(12.1234532, null, ['is_integer' => false, 'decimals' => 5]));
|
||||
$this->assertSame('12.1', $this->service->format(12.1234532, null, ['is_integer' => false, 'decimals' => 1]));
|
||||
}
|
||||
|
||||
public function testFormatOptionsOverride()
|
||||
public function testFormatOptionsOverride(): void
|
||||
{
|
||||
$meters = new MeasurementUnit();
|
||||
$meters->setIsInteger(false)->setUseSIPrefix(true)->setUnit('m');
|
||||
|
||||
$this->assertEquals('12.32', $this->service->format(12.323, $meters, ['unit' => '']));
|
||||
$this->assertEquals('12002.32 m', $this->service->format(12002.32, $meters, ['show_prefix' => false]));
|
||||
$this->assertEquals('123 m', $this->service->format(123.234, $meters, ['is_integer' => true]));
|
||||
$this->assertSame('12.32', $this->service->format(12.323, $meters, ['unit' => '']));
|
||||
$this->assertSame('12002.32 m', $this->service->format(12002.32, $meters, ['show_prefix' => false]));
|
||||
$this->assertSame('123 m', $this->service->format(123.234, $meters, ['is_integer' => true]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -27,6 +30,8 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||
|
||||
class AttachmentPathResolverTest extends WebTestCase
|
||||
{
|
||||
public static $media_path;
|
||||
public static $footprint_path;
|
||||
/**
|
||||
* @var AmountFormatter
|
||||
*/
|
||||
|
@ -34,9 +39,6 @@ class AttachmentPathResolverTest extends WebTestCase
|
|||
protected static $projectDir_orig;
|
||||
protected static $projectDir;
|
||||
|
||||
public static $media_path;
|
||||
public static $footprint_path;
|
||||
|
||||
public function __construct($name = null, array $data = [], $dataName = '')
|
||||
{
|
||||
parent::__construct($name, $data, $dataName);
|
||||
|
@ -57,17 +59,17 @@ class AttachmentPathResolverTest extends WebTestCase
|
|||
self::$service = self::$container->get(AttachmentPathResolver::class);
|
||||
}
|
||||
|
||||
public function testParameterToAbsolutePath()
|
||||
public function testParameterToAbsolutePath(): void
|
||||
{
|
||||
//If null is passed, null must be returned
|
||||
$this->assertNull(self::$service->parameterToAbsolutePath(null));
|
||||
|
||||
//Absolute path should be returned like they are (we use projectDir here, because we know that this dir exists)
|
||||
$this->assertEquals(self::$projectDir_orig, self::$service->parameterToAbsolutePath(self::$projectDir));
|
||||
$this->assertSame(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->assertSame(self::$projectDir_orig.\DIRECTORY_SEPARATOR.'src', self::$service->parameterToAbsolutePath('src'));
|
||||
$this->assertSame(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'));
|
||||
|
@ -116,16 +118,16 @@ class AttachmentPathResolverTest extends WebTestCase
|
|||
/**
|
||||
* @dataProvider placeholderDataProvider
|
||||
*/
|
||||
public function testPlaceholderToRealPath($param, $expected)
|
||||
public function testPlaceholderToRealPath($param, $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, self::$service->placeholderToRealPath($param));
|
||||
$this->assertSame($expected, self::$service->placeholderToRealPath($param));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider realPathDataProvider
|
||||
*/
|
||||
public function testRealPathToPlaceholder($param, $expected, $old_method = false)
|
||||
public function testRealPathToPlaceholder($param, $expected, $old_method = false): void
|
||||
{
|
||||
$this->assertEquals($expected, self::$service->realPathToPlaceholder($param, $old_method));
|
||||
$this->assertSame($expected, self::$service->realPathToPlaceholder($param, $old_method));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -54,8 +57,8 @@ class AttachmentURLGeneratorTest extends WebTestCase
|
|||
* @param $input
|
||||
* @param $expected
|
||||
*/
|
||||
public function testabsolutePathToAssetPath($input, $expected)
|
||||
public function testTestabsolutePathToAssetPath($input, $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, static::$service->absolutePathToAssetPath($input, static::PUBLIC_DIR));
|
||||
$this->assertSame($expected, static::$service->absolutePathToAssetPath($input, static::PUBLIC_DIR));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -60,11 +63,11 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
|
|||
/**
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
public function testFind($keyword, $options, $expected)
|
||||
public function testFind($keyword, $options, $expected): void
|
||||
{
|
||||
$value = static::$service->find($keyword, $options, static::$mock_list);
|
||||
//$this->assertEquals($expected, static::$service->find($keyword, $options, static::$mock_list));
|
||||
$this->assertEquals([], array_diff($value, $expected), 'Additional');
|
||||
$this->assertEquals([], array_diff($expected, $value), 'Missing:');
|
||||
$this->assertSame([], array_diff($value, $expected), 'Additional');
|
||||
$this->assertSame([], array_diff($expected, $value), 'Missing:');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -91,24 +94,24 @@ class FileTypeFilterToolsTest extends WebTestCase
|
|||
*
|
||||
* @dataProvider validateDataProvider
|
||||
*/
|
||||
public function testValidateFilterString(string $filter, bool $expected)
|
||||
public function testValidateFilterString(string $filter, bool $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, self::$service->validateFilterString($filter));
|
||||
$this->assertSame($expected, self::$service->validateFilterString($filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider normalizeDataProvider
|
||||
*/
|
||||
public function testNormalizeFilterString(string $filter, string $expected)
|
||||
public function testNormalizeFilterString(string $filter, string $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, self::$service->normalizeFilterString($filter));
|
||||
$this->assertSame($expected, self::$service->normalizeFilterString($filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider extensionAllowedDataProvider
|
||||
*/
|
||||
public function testIsExtensionAllowed(string $filter, string $extension, bool $expected)
|
||||
public function testIsExtensionAllowed(string $filter, string $extension, bool $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, self::$service->isExtensionAllowed($filter, $extension), $expected);
|
||||
$this->assertSame($expected, self::$service->isExtensionAllowed($filter, $extension));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -38,7 +41,7 @@ class ElementTypeNameGeneratorTest extends WebTestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -47,14 +50,14 @@ class ElementTypeNameGeneratorTest extends WebTestCase
|
|||
$this->service = self::$container->get(ElementTypeNameGenerator::class);
|
||||
}
|
||||
|
||||
public function testGetLocalizedTypeNameCombination()
|
||||
public function testGetLocalizedTypeNameCombination(): void
|
||||
{
|
||||
//We only test in english
|
||||
$this->assertEquals('Part', $this->service->getLocalizedTypeLabel(new Part()));
|
||||
$this->assertEquals('Category', $this->service->getLocalizedTypeLabel(new Category()));
|
||||
$this->assertSame('Part', $this->service->getLocalizedTypeLabel(new Part()));
|
||||
$this->assertSame('Category', $this->service->getLocalizedTypeLabel(new Category()));
|
||||
|
||||
//Test inheritance
|
||||
$this->assertEquals('Attachment', $this->service->getLocalizedTypeLabel(new PartAttachment()));
|
||||
$this->assertSame('Attachment', $this->service->getLocalizedTypeLabel(new PartAttachment()));
|
||||
|
||||
//Test exception for unknpwn type
|
||||
$this->expectException(EntityNotSupportedException::class);
|
||||
|
@ -66,14 +69,14 @@ class ElementTypeNameGeneratorTest extends WebTestCase
|
|||
});
|
||||
}
|
||||
|
||||
public function testGetTypeNameCombination()
|
||||
public function testGetTypeNameCombination(): void
|
||||
{
|
||||
$part = new Part();
|
||||
$part->setName('Test<Part');
|
||||
//When the text version is used, dont escape the name
|
||||
$this->assertEquals('Part: Test<Part', $this->service->getTypeNameCombination($part, false));
|
||||
$this->assertSame('Part: Test<Part', $this->service->getTypeNameCombination($part, false));
|
||||
|
||||
$this->assertEquals('<i>Part:</i> Test<Part', $this->service->getTypeNameCombination($part, true));
|
||||
$this->assertSame('<i>Part:</i> Test<Part', $this->service->getTypeNameCombination($part, true));
|
||||
|
||||
//Test exception
|
||||
$this->expectException(EntityNotSupportedException::class);
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -36,7 +39,7 @@ class EntityImporterTest extends WebTestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -45,7 +48,7 @@ class EntityImporterTest extends WebTestCase
|
|||
$this->service = self::$container->get(EntityImporter::class);
|
||||
}
|
||||
|
||||
public function testMassCreationResults()
|
||||
public function testMassCreationResults(): void
|
||||
{
|
||||
$errors = [];
|
||||
$results = $this->service->massCreation('', AttachmentType::class, null, $errors);
|
||||
|
@ -60,26 +63,26 @@ class EntityImporterTest extends WebTestCase
|
|||
//Check type
|
||||
$this->assertInstanceOf(AttachmentType::class, $results[0]);
|
||||
//Check names
|
||||
$this->assertEquals('Test 1', $results[0]->getName());
|
||||
$this->assertEquals('Test 2', $results[1]->getName());
|
||||
$this->assertSame('Test 1', $results[0]->getName());
|
||||
$this->assertSame('Test 2', $results[1]->getName());
|
||||
//Check parent
|
||||
$this->assertNull($results[0]->getMasterPictureAttachment());
|
||||
|
||||
$parent = new AttachmentType();
|
||||
$results = $this->service->massCreation($lines, AttachmentType::class, $parent, $errors);
|
||||
$this->assertCount(3, $results);
|
||||
$this->assertEquals($parent, $results[0]->getParent());
|
||||
$this->assertSame($parent, $results[0]->getParent());
|
||||
}
|
||||
|
||||
public function testMassCreationErrors()
|
||||
public function testMassCreationErrors(): void
|
||||
{
|
||||
$errors = [];
|
||||
//Node 1 and Node 2 are created in datafixtures, so their attemp to create them again must fail.
|
||||
$lines = "Test 1 \n Node 1 \n Node 2";
|
||||
$results = $this->service->massCreation($lines, AttachmentType::class, null, $errors);
|
||||
$this->assertCount(1, $results);
|
||||
$this->assertEquals('Test 1', $results[0]->getName());
|
||||
$this->assertSame('Test 1', $results[0]->getName());
|
||||
$this->assertCount(2, $errors);
|
||||
$this->assertEquals('Node 1', $errors[0]['entity']->getName());
|
||||
$this->assertSame('Node 1', $errors[0]['entity']->getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -31,7 +34,7 @@ class FAIconGeneratorTest extends WebTestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
|
@ -57,15 +60,15 @@ class FAIconGeneratorTest extends WebTestCase
|
|||
/**
|
||||
* @dataProvider fileExtensionDataProvider
|
||||
*/
|
||||
public function testFileExtensionToFAType(string $ext, string $expected)
|
||||
public function testFileExtensionToFAType(string $ext, string $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, $this->service->fileExtensionToFAType($ext));
|
||||
$this->assertSame($expected, $this->service->fileExtensionToFAType($ext));
|
||||
}
|
||||
|
||||
public function testGenerateIconHTML()
|
||||
public function testGenerateIconHTML(): void
|
||||
{
|
||||
$this->assertEquals('<i class="fas fa-file "></i>', $this->service->generateIconHTML('fa-file'));
|
||||
$this->assertEquals('<i class="far fa-file "></i>', $this->service->generateIconHTML('fa-file', 'far'));
|
||||
$this->assertEquals('<i class="far fa-file fa-2x"></i>', $this->service->generateIconHTML('fa-file', 'far', 'fa-2x'));
|
||||
$this->assertSame('<i class="fas fa-file "></i>', $this->service->generateIconHTML('fa-file'));
|
||||
$this->assertSame('<i class="far fa-file "></i>', $this->service->generateIconHTML('fa-file', 'far'));
|
||||
$this->assertSame('<i class="far fa-file fa-2x"></i>', $this->service->generateIconHTML('fa-file', 'far', 'fa-2x'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -38,7 +41,7 @@ class PermissionResolverTest extends WebTestCase
|
|||
protected $user_withoutGroup;
|
||||
protected $group;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
|
@ -119,7 +122,7 @@ class PermissionResolverTest extends WebTestCase
|
|||
/**
|
||||
* @dataProvider getPermissionNames
|
||||
*/
|
||||
public function testListOperationsForPermission($perm_name)
|
||||
public function testListOperationsForPermission($perm_name): void
|
||||
{
|
||||
$arr = $this->service->listOperationsForPermission($perm_name);
|
||||
|
||||
|
@ -127,20 +130,20 @@ class PermissionResolverTest extends WebTestCase
|
|||
$this->assertNotEmpty($arr);
|
||||
}
|
||||
|
||||
public function testInvalidListOperationsForPermission()
|
||||
public function testInvalidListOperationsForPermission(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
//Must throw an exception
|
||||
$this->service->listOperationsForPermission('invalid');
|
||||
}
|
||||
|
||||
public function testisValidPermission()
|
||||
public function testisValidPermission(): void
|
||||
{
|
||||
$this->assertTrue($this->service->isValidPermission('parts'));
|
||||
$this->assertFalse($this->service->isValidPermission('invalid'));
|
||||
}
|
||||
|
||||
public function testIsValidOperation()
|
||||
public function testIsValidOperation(): void
|
||||
{
|
||||
$this->assertTrue($this->service->isValidOperation('parts', 'read'));
|
||||
|
||||
|
@ -150,7 +153,7 @@ class PermissionResolverTest extends WebTestCase
|
|||
$this->assertFalse($this->service->isValidOperation('invalid', 'invalid'));
|
||||
}
|
||||
|
||||
public function testDontInherit()
|
||||
public function testDontInherit(): void
|
||||
{
|
||||
//Check with faked object
|
||||
$this->assertTrue($this->service->dontInherit($this->user, 'parts', 'read'));
|
||||
|
@ -167,7 +170,7 @@ class PermissionResolverTest extends WebTestCase
|
|||
$this->assertNull($this->service->dontInherit($this->user_withoutGroup, 'parts', 'delete'));
|
||||
}
|
||||
|
||||
public function testInherit()
|
||||
public function testInherit(): void
|
||||
{
|
||||
//Not inherited values should be same as dont inherit:
|
||||
$this->assertTrue($this->service->inherit($this->user, 'parts', 'read'));
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -35,7 +38,7 @@ class PricedetailHelperTest extends WebTestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
//Get an service instance.
|
||||
|
@ -84,8 +87,8 @@ class PricedetailHelperTest extends WebTestCase
|
|||
/**
|
||||
* @dataProvider maxDiscountAmountDataProvider
|
||||
*/
|
||||
public function testGetMaxDiscountAmount(Part $part, ?float $expected_result, string $message)
|
||||
public function testGetMaxDiscountAmount(Part $part, ?float $expected_result, string $message): void
|
||||
{
|
||||
$this->assertEquals($expected_result, $this->service->getMaxDiscountAmount($part), $message);
|
||||
$this->assertSame($expected_result, $this->service->getMaxDiscountAmount($part), $message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -31,7 +34,7 @@ class SIFormatterTest extends WebTestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
//Get an service instance.
|
||||
self::bootKernel();
|
||||
|
@ -40,7 +43,7 @@ class SIFormatterTest extends WebTestCase
|
|||
$this->service = new SIFormatter();
|
||||
}
|
||||
|
||||
public function testGetMagnitude()
|
||||
public function testGetMagnitude(): void
|
||||
{
|
||||
//Get an service instance.
|
||||
$this->assertSame(0, $this->service->getMagnitude(7.0));
|
||||
|
@ -61,7 +64,7 @@ class SIFormatterTest extends WebTestCase
|
|||
$this->assertSame(12, $this->service->getMagnitude(9.99e12));
|
||||
}
|
||||
|
||||
public function testgetPrefixByMagnitude()
|
||||
public function testgetPrefixByMagnitude(): void
|
||||
{
|
||||
$this->assertSame([1, ''], $this->service->getPrefixByMagnitude(2));
|
||||
|
||||
|
@ -74,10 +77,10 @@ class SIFormatterTest extends WebTestCase
|
|||
$this->assertSame([0.001, 'm'], $this->service->getPrefixByMagnitude(-4));
|
||||
}
|
||||
|
||||
public function testFormat()
|
||||
public function testFormat(): void
|
||||
{
|
||||
$this->assertSame('2.32 km', $this->service->format(2321, 'm'));
|
||||
$this->assertEquals('230.45 km', $this->service->format(230450.3, 'm'));
|
||||
$this->assertSame('230.45 km', $this->service->format(230450.3, 'm'));
|
||||
$this->assertSame('-98.20 mg', $this->service->format(-0.0982, 'g'));
|
||||
$this->assertSame('-0.23 g', $this->service->format(-0.23, 'g'));
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -29,7 +32,7 @@ class BackupCodeGeneratorTest extends TestCase
|
|||
/**
|
||||
* Test if an exception is thrown if you are using a too high code length.
|
||||
*/
|
||||
public function testLengthUpperLimit()
|
||||
public function testLengthUpperLimit(): void
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
new BackupCodeGenerator(33, 10);
|
||||
|
@ -38,7 +41,7 @@ class BackupCodeGeneratorTest extends TestCase
|
|||
/**
|
||||
* Test if an exception is thrown if you are using a too high code length.
|
||||
*/
|
||||
public function testLengthLowerLimit()
|
||||
public function testLengthLowerLimit(): void
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
new BackupCodeGenerator(4, 10);
|
||||
|
@ -52,7 +55,7 @@ class BackupCodeGeneratorTest extends TestCase
|
|||
/**
|
||||
* @dataProvider codeLengthDataProvider
|
||||
*/
|
||||
public function testGenerateSingleCode(int $code_length)
|
||||
public function testGenerateSingleCode(int $code_length): void
|
||||
{
|
||||
$generator = new BackupCodeGenerator($code_length, 10);
|
||||
$this->assertRegExp("/^([a-f0-9]){{$code_length}}\$/", $generator->generateSingleCode());
|
||||
|
@ -66,7 +69,7 @@ class BackupCodeGeneratorTest extends TestCase
|
|||
/**
|
||||
* @dataProvider codeCountDataProvider
|
||||
*/
|
||||
public function testGenerateCodeSet(int $code_count)
|
||||
public function testGenerateCodeSet(int $code_count): void
|
||||
{
|
||||
$generator = new BackupCodeGenerator(8, $code_count);
|
||||
$this->assertCount($code_count, $generator->generateCodeSet());
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -32,22 +35,22 @@ class BackupCodeManagerTest extends WebTestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->service = self::$container->get(BackupCodeManager::class);
|
||||
}
|
||||
|
||||
public function testRegenerateBackupCodes()
|
||||
public function testRegenerateBackupCodes(): void
|
||||
{
|
||||
$user = new User();
|
||||
$old_codes = ['aaaa', 'bbbb'];
|
||||
$user->setBackupCodes($old_codes);
|
||||
$this->service->regenerateBackupCodes($user);
|
||||
$this->assertNotEquals($old_codes, $user->getBackupCodes());
|
||||
$this->assertNotSame($old_codes, $user->getBackupCodes());
|
||||
}
|
||||
|
||||
public function testEnableBackupCodes()
|
||||
public function testEnableBackupCodes(): void
|
||||
{
|
||||
$user = new User();
|
||||
//Check that nothing is changed, if there are already backup codes
|
||||
|
@ -55,7 +58,7 @@ class BackupCodeManagerTest extends WebTestCase
|
|||
$old_codes = ['aaaa', 'bbbb'];
|
||||
$user->setBackupCodes($old_codes);
|
||||
$this->service->enableBackupCodes($user);
|
||||
$this->assertEquals($old_codes, $user->getBackupCodes());
|
||||
$this->assertSame($old_codes, $user->getBackupCodes());
|
||||
|
||||
//When no old codes are existing, it should generate a set
|
||||
$user->setBackupCodes([]);
|
||||
|
@ -63,7 +66,7 @@ class BackupCodeManagerTest extends WebTestCase
|
|||
$this->assertNotEmpty($user->getBackupCodes());
|
||||
}
|
||||
|
||||
public function testDisableBackupCodesIfUnused()
|
||||
public function testDisableBackupCodesIfUnused(): void
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
|
@ -77,6 +80,6 @@ class BackupCodeManagerTest extends WebTestCase
|
|||
|
||||
$user->setGoogleAuthenticatorSecret('jskf');
|
||||
$this->service->disableBackupCodesIfUnused($user);
|
||||
$this->assertEquals($codes, $user->getBackupCodes());
|
||||
$this->assertSame($codes, $user->getBackupCodes());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -37,7 +40,7 @@ class NodesListBuilderTest extends WebTestCase
|
|||
protected $service;
|
||||
protected $em;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->service = self::$container->get(NodesListBuilder::class);
|
||||
|
@ -54,13 +57,13 @@ class NodesListBuilderTest extends WebTestCase
|
|||
|
||||
$this->assertCount(7, $nodes);
|
||||
$this->assertContainsOnlyInstancesOf(AttachmentType::class, $nodes);
|
||||
$this->assertEquals('Node 1', $nodes[0]->getName());
|
||||
$this->assertEquals('Node 1.1', $nodes[1]->getName());
|
||||
$this->assertEquals('Node 1.1.1', $nodes[2]->getName());
|
||||
$this->assertEquals('Node 1.2', $nodes[3]->getName());
|
||||
$this->assertEquals('Node 2', $nodes[4]->getName());
|
||||
$this->assertEquals('Node 2.1', $nodes[5]->getName());
|
||||
$this->assertEquals('Node 3', $nodes[6]->getName());
|
||||
$this->assertSame('Node 1', $nodes[0]->getName());
|
||||
$this->assertSame('Node 1.1', $nodes[1]->getName());
|
||||
$this->assertSame('Node 1.1.1', $nodes[2]->getName());
|
||||
$this->assertSame('Node 1.2', $nodes[3]->getName());
|
||||
$this->assertSame('Node 2', $nodes[4]->getName());
|
||||
$this->assertSame('Node 2.1', $nodes[5]->getName());
|
||||
$this->assertSame('Node 3', $nodes[6]->getName());
|
||||
}
|
||||
|
||||
public function testTypeToNodesListElement(): void
|
||||
|
@ -71,8 +74,8 @@ class NodesListBuilderTest extends WebTestCase
|
|||
|
||||
$this->assertCount(3, $nodes);
|
||||
$this->assertContainsOnlyInstancesOf(AttachmentType::class, $nodes);
|
||||
$this->assertEquals('Node 1.1', $nodes[0]->getName());
|
||||
$this->assertEquals('Node 1.1.1', $nodes[1]->getName());
|
||||
$this->assertEquals('Node 1.2', $nodes[2]->getName());
|
||||
$this->assertSame('Node 1.1', $nodes[0]->getName());
|
||||
$this->assertSame('Node 1.1.1', $nodes[1]->getName());
|
||||
$this->assertSame('Node 1.2', $nodes[2]->getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -39,7 +42,7 @@ class TreeViewGeneratorTest extends WebTestCase
|
|||
protected $service;
|
||||
protected $em;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
|
@ -49,7 +52,7 @@ class TreeViewGeneratorTest extends WebTestCase
|
|||
$this->em = self::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
public function testGetGenericTree()
|
||||
public function testGetGenericTree(): void
|
||||
{
|
||||
$tree = $this->service->getGenericTree(AttachmentType::class, null);
|
||||
|
||||
|
@ -63,19 +66,19 @@ class TreeViewGeneratorTest extends WebTestCase
|
|||
$this->assertEmpty($tree[1]->getNodes()[0]->getNodes());
|
||||
|
||||
//Check text
|
||||
$this->assertEquals('Node 1', $tree[0]->getText());
|
||||
$this->assertEquals('Node 2', $tree[1]->getText());
|
||||
$this->assertEquals('Node 3', $tree[2]->getText());
|
||||
$this->assertEquals('Node 1.1', $tree[0]->getNodes()[0]->getText());
|
||||
$this->assertEquals('Node 1.1.1', $tree[0]->getNodes()[0]->getNodes()[0]->getText());
|
||||
$this->assertSame('Node 1', $tree[0]->getText());
|
||||
$this->assertSame('Node 2', $tree[1]->getText());
|
||||
$this->assertSame('Node 3', $tree[2]->getText());
|
||||
$this->assertSame('Node 1.1', $tree[0]->getNodes()[0]->getText());
|
||||
$this->assertSame('Node 1.1.1', $tree[0]->getNodes()[0]->getNodes()[0]->getText());
|
||||
|
||||
//Check that IDs were set correctly
|
||||
$this->assertEquals(1, $tree[0]->getId());
|
||||
$this->assertEquals(2, $tree[1]->getId());
|
||||
$this->assertEquals(7, $tree[0]->getNodes()[0]->getNodes()[0]->getId());
|
||||
$this->assertSame(1, $tree[0]->getId());
|
||||
$this->assertSame(2, $tree[1]->getId());
|
||||
$this->assertSame(7, $tree[0]->getNodes()[0]->getNodes()[0]->getId());
|
||||
}
|
||||
|
||||
public function testGetTreeViewBasic()
|
||||
public function testGetTreeViewBasic(): void
|
||||
{
|
||||
$tree = $this->service->getTreeView(Category::class);
|
||||
$this->assertIsArray($tree);
|
||||
|
@ -86,30 +89,30 @@ class TreeViewGeneratorTest extends WebTestCase
|
|||
$this->assertCount(1, $tree[0]->getNodes()[0]->getNodes());
|
||||
|
||||
//Assert that the nodes contain the correct links
|
||||
$this->assertEquals('/en/category/1/parts', $tree[0]->getHref());
|
||||
$this->assertEquals('/en/category/2/parts', $tree[1]->getHref());
|
||||
$this->assertEquals('/en/category/7/parts', $tree[0]->getNodes()[0]->getNodes()[0]->getHref());
|
||||
$this->assertSame('/en/category/1/parts', $tree[0]->getHref());
|
||||
$this->assertSame('/en/category/2/parts', $tree[1]->getHref());
|
||||
$this->assertSame('/en/category/7/parts', $tree[0]->getNodes()[0]->getNodes()[0]->getHref());
|
||||
}
|
||||
|
||||
public function testGetTreeViewNewEdit()
|
||||
public function testGetTreeViewNewEdit(): void
|
||||
{
|
||||
$tree = $this->service->getTreeView(Category::class, null, 'newEdit');
|
||||
|
||||
//First element should link to new category
|
||||
$this->assertStringContainsStringIgnoringCase('New', $tree[0]->getText());
|
||||
$this->assertEquals('/en/category/new', $tree[0]->getHref());
|
||||
$this->assertSame('/en/category/new', $tree[0]->getHref());
|
||||
//By default the new element node is selected
|
||||
$this->assertTrue($tree[0]->getState()->getSelected());
|
||||
|
||||
//Next element is spacing
|
||||
$this->assertEquals('', $tree[1]->getText());
|
||||
$this->assertSame('', $tree[1]->getText());
|
||||
$this->assertTrue($tree[1]->getState()->getDisabled());
|
||||
|
||||
//All other elements should be normal
|
||||
$this->assertCount(5, $tree);
|
||||
}
|
||||
|
||||
public function testGetTreeViewSelectedNode()
|
||||
public function testGetTreeViewSelectedNode(): void
|
||||
{
|
||||
$selected = $this->em->find(Category::class, 2);
|
||||
$tree = $this->service->getTreeView(Category::class, null, 'edit', $selected);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue