mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-09 18:04:33 +02:00
Applied symplify rules to codebase.
This commit is contained in:
parent
2f20d90041
commit
388e847b17
136 changed files with 1370 additions and 789 deletions
|
@ -49,6 +49,7 @@ use App\Entity\Parts\Supplier;
|
|||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Entity\UserSystem\Group;
|
||||
use App\Entity\UserSystem\User;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionClass;
|
||||
|
||||
|
@ -114,7 +115,7 @@ class AttachmentTest extends TestCase
|
|||
*/
|
||||
public function testSetElementExceptionOnSubClasses(string $attachment_class, string $allowed_class): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
/** @var Attachment $attachment */
|
||||
$attachment = new $attachment_class();
|
||||
|
|
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||
namespace App\Tests\Entity\Parts;
|
||||
|
||||
use App\Entity\Parts\PartLot;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PartLotTest extends TestCase
|
||||
|
@ -34,7 +35,7 @@ class PartLotTest extends TestCase
|
|||
$lot = new PartLot();
|
||||
$this->assertNull($lot->isExpired(), 'Lot must be return null when no Expiration date is set!');
|
||||
|
||||
$datetime = new \DateTime();
|
||||
$datetime = new DateTime();
|
||||
|
||||
$lot->setExpirationDate($datetime->setTimestamp(strtotime('now +1 hour')));
|
||||
$this->assertFalse($lot->isExpired(), 'Lot with expiration date in the future must not be expired!');
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace App\Tests\Entity\Parts;
|
|||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
@ -86,7 +87,7 @@ class PartTest extends TestCase
|
|||
{
|
||||
$part = new Part();
|
||||
$measurement_unit = new MeasurementUnit();
|
||||
$datetime = new \DateTime();
|
||||
$datetime = new DateTime();
|
||||
|
||||
$this->assertSame(0.0, $part->getAmountSum());
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Tests\Entity;
|
|||
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\Parts\Category;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Yaml\Tests\A;
|
||||
|
||||
|
@ -84,7 +85,7 @@ class StructuralDBElementTest extends TestCase
|
|||
|
||||
public function testChildOfDifferentClasses(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$category = new Category();
|
||||
$this->root->isChildOf($category);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@ namespace App\Tests\Entity\UserSystem;
|
|||
|
||||
use App\Entity\UserSystem\PermissionsEmbed;
|
||||
use Doctrine\ORM\Mapping\Embedded;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionClass;
|
||||
|
||||
class PermissionsEmbedTest extends TestCase
|
||||
{
|
||||
|
@ -60,7 +62,7 @@ class PermissionsEmbedTest extends TestCase
|
|||
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::USERS, 0));
|
||||
|
||||
//Set a value for testing to the part property
|
||||
$reflection = new \ReflectionClass($embed);
|
||||
$reflection = new ReflectionClass($embed);
|
||||
$property = $reflection->getProperty('parts');
|
||||
$property->setAccessible(true);
|
||||
|
||||
|
@ -79,7 +81,7 @@ class PermissionsEmbedTest extends TestCase
|
|||
$embed = new PermissionsEmbed();
|
||||
|
||||
//Set a value for testing to the part property
|
||||
$reflection = new \ReflectionClass($embed);
|
||||
$reflection = new ReflectionClass($embed);
|
||||
$property = $reflection->getProperty('parts');
|
||||
$property->setAccessible(true);
|
||||
|
||||
|
@ -97,7 +99,7 @@ class PermissionsEmbedTest extends TestCase
|
|||
{
|
||||
$embed = new PermissionsEmbed();
|
||||
//When encoutering an unknown permission name the class must throw an exception
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$embed->getPermissionValue('invalid', 0);
|
||||
}
|
||||
|
||||
|
@ -105,7 +107,7 @@ class PermissionsEmbedTest extends TestCase
|
|||
{
|
||||
$embed = new PermissionsEmbed();
|
||||
//When encoutering an negative bit the class must throw an exception
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$embed->getPermissionValue('parts', -1);
|
||||
}
|
||||
|
||||
|
@ -113,7 +115,7 @@ class PermissionsEmbedTest extends TestCase
|
|||
{
|
||||
$embed = new PermissionsEmbed();
|
||||
//When encoutering an odd bit number it must throw an error.
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$embed->getPermissionValue('parts', 1);
|
||||
}
|
||||
|
||||
|
@ -121,7 +123,7 @@ class PermissionsEmbedTest extends TestCase
|
|||
{
|
||||
$embed = new PermissionsEmbed();
|
||||
//When encoutering an too high bit number it must throw an error.
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$embed->getPermissionValue('parts', 32);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Tests\Entity\UserSystem;
|
|||
|
||||
use App\Entity\UserSystem\U2FKey;
|
||||
use App\Entity\UserSystem\User;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class UserTest extends TestCase
|
||||
|
@ -69,7 +70,7 @@ class UserTest extends TestCase
|
|||
$codes = ['test', 'invalid', 'test'];
|
||||
$user->setBackupCodes($codes);
|
||||
// Backup Codes generation date must be changed!
|
||||
$this->assertEqualsWithDelta(new \DateTime(), $user->getBackupCodesGenerationDate(), 0.1);
|
||||
$this->assertEqualsWithDelta(new DateTime(), $user->getBackupCodesGenerationDate(), 0.1);
|
||||
$this->assertSame($codes, $user->getBackupCodes());
|
||||
|
||||
//Test what happens if we delete the backup keys
|
||||
|
|
|
@ -35,7 +35,9 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||
class NamedDBElementRepositoryTest extends WebTestCase
|
||||
{
|
||||
private $entityManager;
|
||||
/** @var StructuralDBElementRepository */
|
||||
/**
|
||||
* @var StructuralDBElementRepository
|
||||
*/
|
||||
private $repo;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
@ -35,7 +35,9 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||
class StructuralDBElementRepositoryTest extends WebTestCase
|
||||
{
|
||||
private $entityManager;
|
||||
/** @var StructuralDBElementRepository */
|
||||
/**
|
||||
* @var StructuralDBElementRepository
|
||||
*/
|
||||
private $repo;
|
||||
|
||||
protected function setUp(): void
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Tests\Services;
|
|||
|
||||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Services\AmountFormatter;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class AmountFormatterTest extends WebTestCase
|
||||
|
@ -55,7 +56,7 @@ class AmountFormatterTest extends WebTestCase
|
|||
|
||||
public function testInvalidInput(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->service->format('test');
|
||||
}
|
||||
|
||||
|
@ -83,8 +84,14 @@ class AmountFormatterTest extends WebTestCase
|
|||
|
||||
public function testFormatMoreDigits(): void
|
||||
{
|
||||
$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]));
|
||||
$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(): void
|
||||
|
|
|
@ -26,18 +26,19 @@ namespace App\Tests\Services\Attachments;
|
|||
|
||||
use App\Services\AmountFormatter;
|
||||
use App\Services\Attachments\AttachmentPathResolver;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class AttachmentPathResolverTest extends WebTestCase
|
||||
{
|
||||
public static $media_path;
|
||||
public static $footprint_path;
|
||||
protected static $projectDir_orig;
|
||||
protected static $projectDir;
|
||||
/**
|
||||
* @var AmountFormatter
|
||||
*/
|
||||
protected static $service;
|
||||
protected static $projectDir_orig;
|
||||
protected static $projectDir;
|
||||
|
||||
public function __construct($name = null, array $data = [], $dataName = '')
|
||||
{
|
||||
|
@ -68,8 +69,8 @@ class AttachmentPathResolverTest extends WebTestCase
|
|||
$this->assertSame(self::$projectDir_orig, self::$service->parameterToAbsolutePath(self::$projectDir));
|
||||
|
||||
//Relative pathes should be resolved
|
||||
$this->assertSame(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'));
|
||||
$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'));
|
||||
|
|
|
@ -29,13 +29,14 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||
|
||||
class BuiltinAttachmentsFinderTest extends WebTestCase
|
||||
{
|
||||
/** @var BuiltinAttachmentsFinder */
|
||||
protected static $service;
|
||||
|
||||
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',
|
||||
];
|
||||
/**
|
||||
* @var BuiltinAttachmentsFinder
|
||||
*/
|
||||
protected static $service;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
|
|
|
@ -28,19 +28,20 @@ use App\Entity\UserSystem\Group;
|
|||
use App\Entity\UserSystem\PermissionsEmbed;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Services\PermissionResolver;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class PermissionResolverTest extends WebTestCase
|
||||
{
|
||||
protected $user_withoutGroup;
|
||||
|
||||
protected $user;
|
||||
protected $group;
|
||||
/**
|
||||
* @var PermissionResolver
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
protected $user;
|
||||
protected $user_withoutGroup;
|
||||
protected $group;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
@ -132,7 +133,7 @@ class PermissionResolverTest extends WebTestCase
|
|||
|
||||
public function testInvalidListOperationsForPermission(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
//Must throw an exception
|
||||
$this->service->listOperationsForPermission('invalid');
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Tests\Services\TFA;
|
|||
|
||||
use App\Services\TFA\BackupCodeGenerator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
class BackupCodeGeneratorTest extends TestCase
|
||||
{
|
||||
|
@ -34,7 +35,7 @@ class BackupCodeGeneratorTest extends TestCase
|
|||
*/
|
||||
public function testLengthUpperLimit(): void
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectException(RuntimeException::class);
|
||||
new BackupCodeGenerator(33, 10);
|
||||
}
|
||||
|
||||
|
@ -43,7 +44,7 @@ class BackupCodeGeneratorTest extends TestCase
|
|||
*/
|
||||
public function testLengthLowerLimit(): void
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectException(RuntimeException::class);
|
||||
new BackupCodeGenerator(4, 10);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,11 +34,11 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||
*/
|
||||
class NodesListBuilderTest extends WebTestCase
|
||||
{
|
||||
protected $em;
|
||||
/**
|
||||
* @var NodesListBuilder
|
||||
*/
|
||||
protected $service;
|
||||
protected $em;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
|
|
@ -36,11 +36,11 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|||
*/
|
||||
class TreeViewGeneratorTest extends WebTestCase
|
||||
{
|
||||
protected $em;
|
||||
/**
|
||||
* @var TreeViewGenerator
|
||||
*/
|
||||
protected $service;
|
||||
protected $em;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue