Compare commits

..

No commits in common. "e2735823a0c0e326f56544de34cd4569f84539b3" and "dc253974699e405466b3e17d2fd7db5706e5e1a1" have entirely different histories.

74 changed files with 768 additions and 795 deletions

2
.gitignore vendored
View file

@ -42,7 +42,7 @@ yarn-error.log
###> phpunit/phpunit ###
/phpunit.xml
/.phpunit.cache/
.phpunit.result.cache
###< phpunit/phpunit ###
###> phpstan/phpstan ###

0
bin/phpunit Normal file → Executable file
View file

View file

@ -105,7 +105,7 @@
"phpstan/phpstan-doctrine": "^2.0.1",
"phpstan/phpstan-strict-rules": "^2.0.1",
"phpstan/phpstan-symfony": "^2.0.0",
"phpunit/phpunit": "^11.5.0",
"phpunit/phpunit": "^9.5",
"rector/rector": "^2.0.4",
"roave/security-advisories": "dev-latest",
"symfony/browser-kit": "7.3.*",

657
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,37 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
failOnDeprecation="true"
failOnNotice="true"
failOnWarning="true"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
convertDeprecationsToExceptions="false"
>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<ini name="memory_limit" value="1G"/>
<ini name="display_errors" value="1"/>
</php>
<coverage includeUncoveredFiles="true">
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5"/>
<ini name="memory_limit" value="1G"/>
<ini name="display_errors" value="1"/>
</php>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<extensions>
<bootstrap class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
<bootstrap class="Symfony\Bridge\PhpUnit\SymfonyExtension">
<parameter name="clock-mock-namespaces" value="App" />
<parameter name="dns-mock-namespaces" value="App" />
</bootstrap>
</extensions>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<extensions>
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension"/>
</extensions>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>

View file

@ -7,7 +7,6 @@ use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
@ -17,61 +16,6 @@ use Rector\Symfony\CodeQuality\Rector\MethodCall\LiteralGetToRequestClassConstan
use Rector\Symfony\Set\SymfonySetList;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
return RectorConfig::configure()
->withComposerBased(phpunit: true)
->withSymfonyContainerPhp(__DIR__ . '/tests/symfony-container.php')
->withSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml')
->withImportNames(importShortClasses: false)
->withPaths([
__DIR__ . '/config',
__DIR__ . '/public',
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSets([
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
PHPUnitSetList::PHPUNIT_90,
PHPUnitSetList::PHPUNIT_110,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
])
->withRules([
DeclareStrictTypesRector::class
])
->withSkip([
//Leave our AssertNull tests alone
AssertEmptyNullableObjectToAssertInstanceofRector::class,
CountArrayToEmptyArrayComparisonRector::class,
//Leave our !== null checks alone
FlipTypeControlToUseExclusiveTypeRector::class,
//Leave our PartList TableAction alone
ActionSuffixRemoverRector::class,
//We declare event listeners via attributes, therefore no need to migrate them to subscribers
EventListenerToEventSubscriberRector::class,
PreferPHPUnitThisCallRector::class,
//Do not replace 'GET' with class constant,
LiteralGetToRequestClassConstantRector::class,
])
//Do not apply rules to Symfony own files
->withSkip([
__DIR__ . '/public/index.php',
__DIR__ . '/src/Kernel.php',
__DIR__ . '/config/preload.php',
__DIR__ . '/config/bundles.php',
])
;
/*
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');
$rectorConfig->symfonyContainerPhp(__DIR__ . '/tests/symfony-container.php');
@ -135,4 +79,3 @@ return static function (RectorConfig $rectorConfig): void {
__DIR__ . '/config/bundles.php',
]);
};
*/

View file

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace App\Controller;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use App\Settings\AppSettings;
use Jbtronics\SettingsBundle\Form\SettingsFormFactoryInterface;
use Jbtronics\SettingsBundle\Manager\SettingsManagerInterface;
@ -50,7 +49,7 @@ class SettingsController extends AbstractController
$builder = $this->settingsFormFactory->createSettingsFormBuilder($settings);
//Add a submit button to the form
$builder->add('submit', SubmitType::class, ['label' => 'save']);
$builder->add('submit', \Symfony\Component\Form\Extension\Core\Type\SubmitType::class, ['label' => 'save']);
//Create the form
$form = $builder->getForm();

View file

@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
namespace App\Services\InfoProviderSystem;
use App\Entity\Parts\Manufacturer;
@ -76,4 +74,4 @@ final class ExistingPartFinder
return $qb->getQuery()->getResult();
}
}
}

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
*/
namespace App\Twig;
use App\Settings\SettingsIcon;
use Symfony\Component\HttpFoundation\Request;
use App\Services\LogSystem\EventCommentType;
use Jbtronics\SettingsBundle\Proxy\SettingsProxyInterface;
@ -72,7 +71,7 @@ final class MiscExtension extends AbstractExtension
$reflection = new ReflectionClass($objectOrClass);
$attribute = $reflection->getAttributes(SettingsIcon::class)[0] ?? null;
$attribute = $reflection->getAttributes(\App\Settings\SettingsIcon::class)[0] ?? null;
return $attribute?->newInstance()->icon;
}

View file

@ -29,15 +29,15 @@
"version": "1.11.99.4"
},
"dama/doctrine-test-bundle": {
"version": "8.3",
"version": "8.0",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "8.3",
"ref": "dfc51177476fb39d014ed89944cde53dc3326d23"
"version": "7.2",
"ref": "896306d79d4ee143af9eadf9b09fd34a8c391b70"
},
"files": [
"config/packages/dama_doctrine_test_bundle.yaml"
"./config/packages/dama_doctrine_test_bundle.yaml"
]
},
"doctrine/cache": {
@ -309,16 +309,15 @@
"version": "0.12.4"
},
"phpunit/phpunit": {
"version": "11.5",
"version": "9.6",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "11.1",
"ref": "c6658a60fc9d594805370eacdf542c3d6b5c0869"
"version": "9.6",
"ref": "6a9341aa97d441627f8bd424ae85dc04c944f8b4"
},
"files": [
".env.test",
"bin/phpunit",
"phpunit.xml.dist",
"tests/bootstrap.php"
]
@ -577,14 +576,19 @@
"version": "v5.3.8"
},
"symfony/phpunit-bridge": {
"version": "7.3",
"version": "6.4",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "7.3",
"ref": "dc13fec96bd527bd399c3c01f0aab915c67fd544"
"version": "6.3",
"ref": "a411a0480041243d97382cac7984f7dce7813c08"
},
"files": []
"files": [
"./.env.test",
"./bin/phpunit",
"./phpunit.xml.dist",
"./tests/bootstrap.php"
]
},
"symfony/polyfill-ctype": {
"version": "v1.14.0"

View file

@ -23,14 +23,15 @@ declare(strict_types=1);
namespace App\Tests\API;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\UserSystem\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class APIDocsAvailabilityTest extends WebTestCase
{
#[DataProvider('urlProvider')]
/**
* @dataProvider urlProvider
*/
public function testDocAvailabilityForLoggedInUser(string $url): void
{
self::ensureKernelShutdown();

View file

@ -22,19 +22,20 @@ declare(strict_types=1);
namespace App\Tests;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\DataProvider;
use Generator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* This test just ensures that different pages are available (do not throw an exception).
*
* @group DB
* @group slow
*/
#[Group('DB')]
#[Group('slow')]
class ApplicationAvailabilityFunctionalTest extends WebTestCase
{
#[DataProvider('urlProvider')]
/**
* @dataProvider urlProvider
*/
public function testPageIsSuccessful(string $url): void
{
//We have localized routes
@ -53,7 +54,7 @@ class ApplicationAvailabilityFunctionalTest extends WebTestCase
$this->assertTrue($client->getResponse()->isSuccessful(), 'Request not successful. Status code is '.$client->getResponse()->getStatusCode() . ' for URL '.$url);
}
public static function urlProvider(): ?Generator
public function urlProvider(): ?Generator
{
//Homepage
yield ['/'];

View file

@ -22,19 +22,19 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
#[Group('slow')]
#[Group('DB')]
abstract class AbstractAdminController extends WebTestCase
/**
* @group slow
* @group DB
*/
abstract class AbstractAdminControllerTest extends WebTestCase
{
protected static string $base_path = 'not_valid';
protected static string $entity_class = 'not valid';
public static function readDataProvider(): \Iterator
public function readDataProvider(): \Iterator
{
yield ['noread', false];
yield ['anonymous', true];
@ -43,10 +43,10 @@ abstract class AbstractAdminController extends WebTestCase
}
/**
* @dataProvider readDataProvider
* @group slow
* Tests if you can access the /new part which is used to list all entities. Checks if permissions are working
*/
#[DataProvider('readDataProvider')]
#[Group('slow')]
public function testListEntries(string $user, bool $read): void
{
static::ensureKernelShutdown();
@ -72,13 +72,10 @@ abstract class AbstractAdminController extends WebTestCase
}
/**
* @dataProvider readDataProvider
* @group slow
* Tests if it is possible to access a specific entity. Checks if permissions are working.
* @param string $user
* @param bool $read
* @return void
*/
#[DataProvider('readDataProvider')]
#[Group('slow')]
public function testReadEntity(string $user, bool $read): void
{
//Test read access
@ -99,7 +96,7 @@ abstract class AbstractAdminController extends WebTestCase
$this->assertSame($read, !$client->getResponse()->isForbidden(), 'Permission Checking not working!');
}
public static function deleteDataProvider(): \Iterator
public function deleteDataProvider(): \Iterator
{
yield ['noread', false];
yield ['anonymous', false];
@ -109,9 +106,10 @@ abstract class AbstractAdminController extends WebTestCase
/**
* Tests if deleting an entity is working.
*
* @group slow
* @dataProvider deleteDataProvider
*/
#[DataProvider('deleteDataProvider')]
#[Group('slow')]
public function testDeleteEntity(string $user, bool $delete): void
{
//Test read access

View file

@ -22,12 +22,13 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\Attachments\AttachmentType;
#[Group('slow')]
#[Group('DB')]
class AttachmentTypeController extends AbstractAdminController
/**
* @group slow
* @group DB
*/
class AttachmentTypeControllerTest extends AbstractAdminControllerTest
{
protected static string $base_path = '/en/attachment_type';
protected static string $entity_class = AttachmentType::class;

View file

@ -22,12 +22,13 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\Parts\Category;
#[Group('slow')]
#[Group('DB')]
class CategoryController extends AbstractAdminController
/**
* @group slow
* @group DB
*/
class CategoryControllerTest extends AbstractAdminControllerTest
{
protected static string $base_path = '/en/category';
protected static string $entity_class = Category::class;

View file

@ -22,12 +22,13 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\Parts\Footprint;
#[Group('slow')]
#[Group('DB')]
class FootprintController extends AbstractAdminController
/**
* @group slow
* @group DB
*/
class FootprintControllerTest extends AbstractAdminControllerTest
{
protected static string $base_path = '/en/footprint';
protected static string $entity_class = Footprint::class;

View file

@ -41,21 +41,20 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\LabelSystem\LabelProfile;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class LabelProfileController extends AbstractAdminController
class LabelProfileControllerTest extends AbstractAdminControllerTest
{
protected static string $base_path = '/en/label_profile';
protected static string $entity_class = LabelProfile::class;
/**
* Tests if deleting an entity is working.
*
* @group slow
* @dataProvider deleteDataProvider
*/
#[DataProvider('deleteDataProvider')]
#[Group('slow')]
public function testDeleteEntity(string $user, bool $delete): void
{
//Test read access

View file

@ -22,12 +22,13 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\Parts\Manufacturer;
#[Group('slow')]
#[Group('DB')]
class ManufacturerController extends AbstractAdminController
/**
* @group slow
* @group DB
*/
class ManufacturerControllerTest extends AbstractAdminControllerTest
{
protected static string $base_path = '/en/manufacturer';
protected static string $entity_class = Manufacturer::class;

View file

@ -22,12 +22,13 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\Parts\MeasurementUnit;
#[Group('slow')]
#[Group('DB')]
class MeasurementUnitController extends AbstractAdminController
/**
* @group slow
* @group DB
*/
class MeasurementUnitControllerTest extends AbstractAdminControllerTest
{
protected static string $base_path = '/en/measurement_unit';
protected static string $entity_class = MeasurementUnit::class;

View file

@ -23,12 +23,13 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\ProjectSystem\Project;
#[Group('slow')]
#[Group('DB')]
class ProjectController extends AbstractAdminController
/**
* @group slow
* @group DB
*/
class ProjectControllerTest extends AbstractAdminControllerTest
{
protected static string $base_path = '/en/project';
protected static string $entity_class = Project::class;

View file

@ -22,12 +22,13 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\Parts\StorageLocation;
#[Group('slow')]
#[Group('DB')]
class StorelocationController extends AbstractAdminController
/**
* @group slow
* @group DB
*/
class StorelocationControllerTest extends AbstractAdminControllerTest
{
protected static string $base_path = '/en/store_location';
protected static string $entity_class = StorageLocation::class;

View file

@ -22,12 +22,13 @@ declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\Parts\Supplier;
#[Group('slow')]
#[Group('DB')]
class SupplierController extends AbstractAdminController
/**
* @group slow
* @group DB
*/
class SupplierControllerTest extends AbstractAdminControllerTest
{
protected static string $base_path = '/en/supplier';
protected static string $entity_class = Supplier::class;

View file

@ -22,17 +22,16 @@ declare(strict_types=1);
namespace App\Tests\Controller;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use App\Entity\UserSystem\User;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
#[Group('slow')]
#[Group('DB')]
/**
* @group slow
* @group DB
*/
class RedirectControllerTest extends WebTestCase
{
protected EntityManagerInterface $em;
@ -51,7 +50,7 @@ class RedirectControllerTest extends WebTestCase
$this->userRepo = $this->em->getRepository(User::class);
}
public static function urlMatchDataProvider(): \Iterator
public function urlMatchDataProvider(): \Iterator
{
yield ['/', true];
yield ['/part/2/info', true];
@ -65,9 +64,10 @@ class RedirectControllerTest extends WebTestCase
/**
* Test if a certain request to an url will be redirected.
*
* @dataProvider urlMatchDataProvider
* @group slow
*/
#[DataProvider('urlMatchDataProvider')]
#[Group('slow')]
public function testUrlMatch($url, $expect_redirect): void
{
//$client = static::createClient();
@ -79,7 +79,7 @@ class RedirectControllerTest extends WebTestCase
$this->assertSame($expect_redirect, $response->isRedirect());
}
public static function urlAddLocaleDataProvider(): \Iterator
public function urlAddLocaleDataProvider(): \Iterator
{
//User locale, original target, redirect target
yield ['de', '/', '/de/'];
@ -97,10 +97,11 @@ class RedirectControllerTest extends WebTestCase
/**
* Test if the user is redirected to the localized version of a page, based on his settings.
*
* @dataProvider urlAddLocaleDataProvider
* @group slow
* @depends testUrlMatch
*/
#[Depends('testUrlMatch')]
#[DataProvider('urlAddLocaleDataProvider')]
#[Group('slow')]
public function testAddLocale(?string $user_locale, string $input_path, string $redirect_path): void
{
//Redirect path is absolute
@ -120,9 +121,10 @@ class RedirectControllerTest extends WebTestCase
/**
* Test if the user is redirected to the localized version of a page, based on his settings.
* We simulate the situation of a reverse proxy here, by adding a prefix to the path.
*
* @dataProvider urlAddLocaleDataProvider
* @group slow
*/
#[DataProvider('urlAddLocaleDataProvider')]
#[Group('slow')]
public function testAddLocaleReverseProxy(?string $user_locale, string $input_path, string $redirect_path): void
{
//Input path remains unchanged, as this is what the server receives from the proxy
@ -145,9 +147,10 @@ class RedirectControllerTest extends WebTestCase
/**
* Test if the user is redirected to the localized version of a page, based on his settings.
* We simulate the situation of serving Part-DB in a subfolder here.
*
* @dataProvider urlAddLocaleDataProvider
* @group slow
*/
#[DataProvider('urlAddLocaleDataProvider')]
#[Group('slow')]
public function testAddLocaleSubfolder(?string $user_locale, string $input_path, string $redirect_path): void
{
//Prefix our path with the proxy prefix

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
*/
namespace App\Tests\DataTables\Filters\Constraints;
use PHPUnit\Framework\Attributes\DataProvider;
use App\DataTables\Filters\Constraints\FilterTrait;
use PHPUnit\Framework\TestCase;
@ -41,7 +40,7 @@ class FilterTraitTest extends TestCase
$this->assertFalse($this->useHaving);
}
public static function isAggregateFunctionStringDataProvider(): iterable
public function isAggregateFunctionStringDataProvider(): iterable
{
yield [false, 'parts.test'];
yield [false, 'attachments.test'];
@ -49,10 +48,12 @@ class FilterTraitTest extends TestCase
yield [true, 'MAX(attachments.value)'];
}
#[DataProvider('isAggregateFunctionStringDataProvider')]
/**
* @dataProvider isAggregateFunctionStringDataProvider
*/
public function testIsAggregateFunctionString(bool $expected, string $input): void
{
$this->assertSame($expected, $this->isAggregateFunctionString($input));
$this->assertEquals($expected, $this->isAggregateFunctionString($input));
}
}

View file

@ -41,12 +41,13 @@ declare(strict_types=1);
namespace App\Tests;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DatatablesAvailabilityTest extends WebTestCase
{
#[DataProvider('urlProvider')]
/**
* @dataProvider urlProvider
*/
public function testDataTable(string $url, ?array $ordering = null): void
{
//We have localized routes
@ -79,7 +80,7 @@ class DatatablesAvailabilityTest extends WebTestCase
$this->assertJson($client->getResponse()->getContent());
}
public static function urlProvider(): ?\Generator
public function urlProvider(): ?\Generator
{
//Part lists
yield ['/category/1/parts'];

View file

@ -22,14 +22,13 @@ declare(strict_types=1);
*/
namespace App\Tests\Doctrine;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Doctrine\Middleware\SQLiteRegexExtensionMiddlewareDriver;
use PHPUnit\Framework\TestCase;
class SQLiteRegexMiddlewareTest extends TestCase
{
public static function regexpDataProvider(): \Generator
public function regexpDataProvider(): \Generator
{
yield [1, 'a', 'a'];
yield [0, 'a', 'b'];
@ -42,13 +41,15 @@ class SQLiteRegexMiddlewareTest extends TestCase
yield [1, '^a\d+$', 'a123'];
}
#[DataProvider('regexpDataProvider')]
/**
* @dataProvider regexpDataProvider
*/
public function testRegexp(int $expected, string $pattern, string $value): void
{
$this->assertSame($expected, SQLiteRegexExtensionMiddlewareDriver::regexp($pattern, $value));
}
public static function fieldDataProvider(): \Generator
public function fieldDataProvider(): \Generator
{
// Null cases
@ -72,13 +73,17 @@ class SQLiteRegexMiddlewareTest extends TestCase
yield [6, 'c', ['b', 'a', 'b', 'a', 'b', 'c']];
}
#[DataProvider('fieldDataProvider')]
/**
* @dataProvider fieldDataProvider
*/
public function testField(int $expected, string|int|null $value, array $array): void
{
$this->assertSame($expected, SQLiteRegexExtensionMiddlewareDriver::field($value, ...$array));
}
#[DataProvider('fieldDataProvider')]
/**
* @dataProvider fieldDataProvider
*/
public function testField2(int $expected, string|int|null $value, array $array): void
{
//Should be the same as field, but with the array comma imploded

View file

@ -22,8 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Entity\Attachments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\AttachmentTypeAttachment;
@ -75,7 +73,7 @@ class AttachmentTest extends TestCase
$this->assertEmpty($attachment->getFilename());
}
public static function subClassesDataProvider(): \Iterator
public function subClassesDataProvider(): \Iterator
{
yield [AttachmentTypeAttachment::class, AttachmentType::class];
yield [CategoryAttachment::class, Category::class];
@ -91,7 +89,9 @@ class AttachmentTest extends TestCase
yield [UserAttachment::class, User::class];
}
#[DataProvider('subClassesDataProvider')]
/**
* @dataProvider subClassesDataProvider
*/
public function testSetElement(string $attachment_class, string $allowed_class): void
{
/** @var Attachment $attachment */
@ -106,9 +106,10 @@ class AttachmentTest extends TestCase
/**
* Test that all attachment subclasses like PartAttachment or similar returns an exception, when a not allowed
* element is passed.
*
* @dataProvider subClassesDataProvider
* @depends testSetElement
*/
#[Depends('testSetElement')]
#[DataProvider('subClassesDataProvider')]
public function testSetElementExceptionOnSubClasses(string $attachment_class, string $allowed_class): void
{
$this->expectException(InvalidArgumentException::class);
@ -134,7 +135,9 @@ class AttachmentTest extends TestCase
yield [null, 'test.txt', null, null];
}
#[DataProvider('extensionDataProvider')]
/**
* @dataProvider extensionDataProvider
*/
public function testGetExtension(?string $internal_path, ?string $external_path, ?string $originalFilename, ?string $expected): void
{
$attachment = new PartAttachment();
@ -159,7 +162,9 @@ class AttachmentTest extends TestCase
yield ['%SECURE%/foo.txt/test', 'https://test.de/picture.jpeg', false];
}
#[DataProvider('pictureDataProvider')]
/**
* @dataProvider pictureDataProvider
*/
public function testIsPicture(?string $internal_path, ?string $external_path, bool $expected): void
{
$attachment = new PartAttachment();
@ -179,7 +184,9 @@ class AttachmentTest extends TestCase
yield ['%FOOTPRINTS%/foo/bar.txt', true];
}
#[DataProvider('builtinDataProvider')]
/**
* @dataProvider builtinDataProvider
*/
public function testIsBuiltIn(?string $path, $expected): void
{
$attachment = new PartAttachment();
@ -194,7 +201,9 @@ class AttachmentTest extends TestCase
yield ['https://foo.bar/test?txt=test', 'foo.bar'];
}
#[DataProvider('hostDataProvider')]
/**
* @dataProvider hostDataProvider
*/
public function testGetHost(?string $path, ?string $expected): void
{
$attachment = new PartAttachment();
@ -210,7 +219,9 @@ class AttachmentTest extends TestCase
yield [null, 'https://www.google.de/test.txt', null, null];
}
#[DataProvider('filenameProvider')]
/**
* @dataProvider filenameProvider
*/
public function testGetFilename(?string $internal_path, ?string $external_path, ?string $original_filename, ?string $expected): void
{
$attachment = new PartAttachment();
@ -231,7 +242,7 @@ class AttachmentTest extends TestCase
//Ensure that changing the external path does reset the internal one
$attachment->setInternalPath('%MEDIA%/foo/bar.txt');
$attachment->setExternalPath('https://example.de');
$this->assertNull($attachment->getInternalPath());
$this->assertSame(null, $attachment->getInternalPath());
//Ensure that setting the same value to the external path again doesn't reset the internal one
$attachment->setExternalPath('https://google.de');

View file

@ -41,13 +41,12 @@ declare(strict_types=1);
namespace App\Tests\Entity\Parameters;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Parameters\PartParameter;
use PHPUnit\Framework\TestCase;
class PartParameterTest extends TestCase
{
public static function valueWithUnitDataProvider(): \Iterator
public function valueWithUnitDataProvider(): \Iterator
{
yield ['1', 1.0, ''];
yield ['1 V', 1.0, 'V'];
@ -55,7 +54,7 @@ class PartParameterTest extends TestCase
yield ['1.23 V', 1.23, 'V'];
}
public static function formattedValueDataProvider(): \Iterator
public function formattedValueDataProvider(): \Iterator
{
yield ['Text Test', null, null, null, 'V', 'Text Test'];
yield ['10.23 V', null, 10.23, null, 'V', ''];
@ -68,7 +67,7 @@ class PartParameterTest extends TestCase
yield ['10.23 V (9 V ... 11 V) [Test]', 9, 10.23, 11, 'V', 'Test'];
}
public static function formattedValueWithLatexDataProvider(): \Iterator
public function formattedValueWithLatexDataProvider(): \Iterator
{
yield ['Text Test', null, null, null, 'V', 'Text Test'];
yield ['10.23 $\mathrm{V}$', null, 10.23, null, 'V', ''];
@ -81,7 +80,9 @@ class PartParameterTest extends TestCase
yield ['10.23 $\mathrm{V}$ (9 $\mathrm{V}$ ... 11 $\mathrm{V}$) [Test]', 9, 10.23, 11, 'V', 'Test'];
}
#[DataProvider('valueWithUnitDataProvider')]
/**
* @dataProvider valueWithUnitDataProvider
*/
public function testGetValueMinWithUnit(string $expected, float $value, string $unit): void
{
$param = new PartParameter();
@ -90,7 +91,9 @@ class PartParameterTest extends TestCase
$this->assertSame($expected, $param->getValueMinWithUnit());
}
#[DataProvider('valueWithUnitDataProvider')]
/**
* @dataProvider valueWithUnitDataProvider
*/
public function testGetValueMaxWithUnit(string $expected, float $value, string $unit): void
{
$param = new PartParameter();
@ -99,7 +102,9 @@ class PartParameterTest extends TestCase
$this->assertSame($expected, $param->getValueMaxWithUnit());
}
#[DataProvider('valueWithUnitDataProvider')]
/**
* @dataProvider valueWithUnitDataProvider
*/
public function testGetValueTypicalWithUnit(string $expected, float $value, string $unit): void
{
$param = new PartParameter();
@ -109,12 +114,12 @@ class PartParameterTest extends TestCase
}
/**
* @dataProvider formattedValueDataProvider
*
* @param float $min
* @param float $typical
* @param float $max
*/
#[DataProvider('formattedValueDataProvider')]
public function testGetFormattedValue(string $expected, ?float $min, ?float $typical, ?float $max, string $unit, string $text): void
{
$param = new PartParameter();
@ -127,12 +132,12 @@ class PartParameterTest extends TestCase
}
/**
* @dataProvider formattedValueWithLatexDataProvider
*
* @param float $min
* @param float $typical
* @param float $max
*/
#[DataProvider('formattedValueWithLatexDataProvider')]
public function testGetFormattedValueWithLatex(string $expected, ?float $min, ?float $typical, ?float $max, string $unit, string $text): void
{
$param = new PartParameter();

View file

@ -41,7 +41,7 @@ class PartTest extends TestCase
$lot = new PartLot();
$part->addPartLot($lot);
$this->assertSame($part, $lot->getPart());
$this->assertCount(1, $part->getPartLots());
$this->assertSame(1, $part->getPartLots()->count());
//Remove element
$part->removePartLot($lot);

View file

@ -38,7 +38,7 @@ class OrderdetailTest extends TestCase
$pricedetail = new Pricedetail();
$orderdetail->addPricedetail($pricedetail);
$this->assertSame($orderdetail, $pricedetail->getOrderdetail());
$this->assertCount(1, $orderdetail->getPricedetails());
$this->assertSame(1, $orderdetail->getPricedetails()->count());
//After removal of the pricedetail, the orderdetail must be empty again
$orderdetail->removePricedetail($pricedetail);

View file

@ -35,7 +35,7 @@ class ApiTokenTypeTest extends TestCase
public function testGetTypeFromToken(): void
{
$this->assertSame(ApiTokenType::PERSONAL_ACCESS_TOKEN, ApiTokenType::getTypeFromToken('tcp_123'));
$this->assertEquals(ApiTokenType::PERSONAL_ACCESS_TOKEN, ApiTokenType::getTypeFromToken('tcp_123'));
}
public function testGetTypeFromTokenInvalid(): void

View file

@ -22,8 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Entity\UserSystem;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresPhpunit;
use App\Entity\UserSystem\User;
use App\Entity\UserSystem\WebauthnKey;
use Doctrine\Common\Collections\Collection;
@ -47,14 +45,16 @@ class UserTest extends TestCase
$this->assertSame('John (@username)', $user->getFullName(true));
}
public static function googleAuthenticatorEnabledDataProvider(): \Iterator
public function googleAuthenticatorEnabledDataProvider(): \Iterator
{
yield [null, false];
yield ['', false];
yield ['SSSk38498', true];
}
#[DataProvider('googleAuthenticatorEnabledDataProvider')]
/**
* @dataProvider googleAuthenticatorEnabledDataProvider
*/
public function testIsGoogleAuthenticatorEnabled(?string $secret, bool $expected): void
{
$user = new User();
@ -62,7 +62,9 @@ class UserTest extends TestCase
$this->assertSame($expected, $user->isGoogleAuthenticatorEnabled());
}
//#[RequiresPhpunit('8')]
/**
* @requires PHPUnit 8
*/
public function testSetBackupCodes(): void
{
$user = new User();

View file

@ -1,7 +1,4 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,6 +17,7 @@ declare(strict_types=1);
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Tests\Exceptions;
use App\Exceptions\TwigModeException;

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Helpers;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Helpers\BBCodeToMarkdownConverter;
use PHPUnit\Framework\TestCase;
@ -35,7 +34,7 @@ class BBCodeToMarkdownConverterTest extends TestCase
$this->converter = new BBCodeToMarkdownConverter();
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
yield ['[b]Bold[/b]', '**Bold**'];
yield ['[i]Italic[/i]', '*Italic*'];
@ -47,11 +46,11 @@ class BBCodeToMarkdownConverterTest extends TestCase
}
/**
* @dataProvider dataProvider
*
* @param $bbcode
* @param $expected
*/
#[DataProvider('dataProvider')]
public function testConvert($bbcode, $expected): void
{
$this->assertSame($expected, $this->converter->convert($bbcode));

View file

@ -1,7 +1,4 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,16 +17,16 @@ declare(strict_types=1);
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Tests\Helpers;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Helpers\IPAnonymizer;
use PHPUnit\Framework\TestCase;
class IPAnonymizerTest extends TestCase
{
public static function anonymizeDataProvider(): \Generator
public function anonymizeDataProvider(): \Generator
{
yield ['127.0.0.0', '127.0.0.23'];
yield ['2001:db8:85a3::', '2001:0db8:85a3:0000:0000:8a2e:0370:7334'];
@ -37,7 +34,9 @@ class IPAnonymizerTest extends TestCase
yield ['fe80::', 'fe80::1fc4:15d8:78db:2319%enp4s0'];
}
#[DataProvider('anonymizeDataProvider')]
/**
* @dataProvider anonymizeDataProvider
*/
public function testAnonymize(string $expected, string $input): void
{
$this->assertSame($expected, IPAnonymizer::anonymize($input));

View file

@ -33,6 +33,9 @@ use PHPUnit\Framework\TestCase;
class ProjectBuildRequestTest extends TestCase
{
/** @var MeasurementUnit $float_unit */
private MeasurementUnit $float_unit;
/** @var Project */
private Project $project1;
/** @var ProjectBOMEntry */
@ -46,25 +49,30 @@ class ProjectBuildRequestTest extends TestCase
private PartLot $lot1b;
private PartLot $lot2;
/** @var Part */
private Part $part1;
/** @var Part */
private Part $part2;
public function setUp(): void
{
$float_unit = new MeasurementUnit();
$float_unit->setName('float');
$float_unit->setUnit('f');
$float_unit->setIsInteger(false);
$float_unit->setUseSIPrefix(true);
$this->float_unit = new MeasurementUnit();
$this->float_unit->setName('float');
$this->float_unit->setUnit('f');
$this->float_unit->setIsInteger(false);
$this->float_unit->setUseSIPrefix(true);
//Setup some example parts and part lots
$part1 = new Part();
$part1->setName('Part 1');
$this->part1 = new Part();
$this->part1->setName('Part 1');
$this->lot1a = new class extends PartLot {
public function getID(): ?int
{
return 1;
}
};
$part1->addPartLot($this->lot1a);
$this->part1->addPartLot($this->lot1a);
$this->lot1a->setAmount(10);
$this->lot1a->setDescription('Lot 1a');
@ -74,25 +82,25 @@ class ProjectBuildRequestTest extends TestCase
return 2;
}
};
$part1->addPartLot($this->lot1b);
$this->part1->addPartLot($this->lot1b);
$this->lot1b->setAmount(20);
$this->lot1b->setDescription('Lot 1b');
$part2 = new Part();
$this->part2 = new Part();
$part2->setName('Part 2');
$part2->setPartUnit($float_unit);
$this->part2->setName('Part 2');
$this->part2->setPartUnit($this->float_unit);
$this->lot2 = new PartLot();
$part2->addPartLot($this->lot2);
$this->part2->addPartLot($this->lot2);
$this->lot2->setAmount(2.5);
$this->lot2->setDescription('Lot 2');
$this->bom_entry1a = new ProjectBOMEntry();
$this->bom_entry1a->setPart($part1);
$this->bom_entry1a->setPart($this->part1);
$this->bom_entry1a->setQuantity(2);
$this->bom_entry1b = new ProjectBOMEntry();
$this->bom_entry1b->setPart($part2);
$this->bom_entry1b->setPart($this->part2);
$this->bom_entry1b->setQuantity(1.5);
$this->bom_entry1c = new ProjectBOMEntry();

View file

@ -1,7 +1,4 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,6 +17,7 @@ declare(strict_types=1);
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Tests\Repository;
use App\Entity\LogSystem\AbstractLogEntry;

View file

@ -32,6 +32,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/
class NamedDBElementRepositoryTest extends WebTestCase
{
private $entityManager;
/**
* @var StructuralDBElementRepository
*/
@ -41,11 +42,11 @@ class NamedDBElementRepositoryTest extends WebTestCase
{
$kernel = self::bootKernel();
$entityManager = $kernel->getContainer()
$this->entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
$this->repo = $entityManager->getRepository(User::class);
$this->repo = $this->entityManager->getRepository(User::class);
}
public function testGetGenericNodeTree(): void

View file

@ -32,6 +32,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/
class StructuralDBElementRepositoryTest extends WebTestCase
{
private $entityManager;
/**
* @var StructuralDBElementRepository
*/
@ -41,11 +42,11 @@ class StructuralDBElementRepositoryTest extends WebTestCase
{
$kernel = self::bootKernel();
$entityManager = $kernel->getContainer()
$this->entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
$this->repo = $entityManager->getRepository(AttachmentType::class);
$this->repo = $this->entityManager->getRepository(AttachmentType::class);
}
public function testFindRootNodes(): void

View file

@ -30,6 +30,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class UserRepositoryTest extends WebTestCase
{
private $entityManager;
/**
* @var UserRepository
*/
@ -39,11 +40,11 @@ class UserRepositoryTest extends WebTestCase
{
$kernel = self::bootKernel();
$entityManager = $kernel->getContainer()
$this->entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
$this->repo = $entityManager->getRepository(User::class);
$this->repo = $this->entityManager->getRepository(User::class);
}

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
*/
namespace App\Tests\Serializer;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\Parts\Category;
use App\Serializer\StructuralElementDenormalizer;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -54,7 +53,9 @@ class StructuralElementDenormalizerTest extends WebTestCase
$this->assertTrue($this->service->supportsDenormalization(['name' => 'Test'], Category::class, 'json', ['groups' => ['import'], 'partdb_import' => true]));
}
#[Group('DB')]
/**
* @group DB
*/
public function testDenormalize(): void
{
//Check that we retrieve DB elements via the name

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\Attachments;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Formatters\AmountFormatter;
use App\Services\Attachments\AttachmentPathResolver;
use const DIRECTORY_SEPARATOR;
@ -70,19 +69,19 @@ class AttachmentPathResolverTest extends WebTestCase
$this->assertNull($this->service->parameterToAbsolutePath('/./this/one/too'));
}
public static function placeholderDataProvider(): \Iterator
public function placeholderDataProvider(): \Iterator
{
//We need to do initialization (again), as dataprovider is called before setUp()
self::bootKernel();
$projectDir_orig = realpath(self::$kernel->getProjectDir());
$projectDir = str_replace('\\', '/', $projectDir_orig);
$media_path = $projectDir.'/public/media';
$footprint_path = $projectDir.'/public/img/footprints';
yield ['%FOOTPRINTS%/test/test.jpg', $footprint_path.'/test/test.jpg'];
yield ['%FOOTPRINTS%/test/', $footprint_path.'/test/'];
yield ['%MEDIA%/test', $media_path.'/test'];
yield ['%MEDIA%', $media_path];
yield ['%FOOTPRINTS%', $footprint_path];
$this->projectDir_orig = realpath(self::$kernel->getProjectDir());
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->media_path = $this->projectDir.'/public/media';
$this->footprint_path = $this->projectDir.'/public/img/footprints';
yield ['%FOOTPRINTS%/test/test.jpg', $this->footprint_path.'/test/test.jpg'];
yield ['%FOOTPRINTS%/test/', $this->footprint_path.'/test/'];
yield ['%MEDIA%/test', $this->media_path.'/test'];
yield ['%MEDIA%', $this->media_path];
yield ['%FOOTPRINTS%', $this->footprint_path];
//Footprints 3D are disabled
yield ['%FOOTPRINTS_3D%', null];
//Check that invalid pathes return null
@ -99,59 +98,65 @@ class AttachmentPathResolverTest extends WebTestCase
yield ['%FOOTPRINTS%/0\..\test', null];
}
public static function realPathDataProvider(): \Iterator
public function realPathDataProvider(): \Iterator
{
//We need to do initialization (again), as dataprovider is called before setUp()
self::bootKernel();
$projectDir_orig = realpath(self::$kernel->getProjectDir());
$projectDir = str_replace('\\', '/', $projectDir_orig);
$media_path = $projectDir.'/public/media';
$footprint_path = $projectDir.'/public/img/footprints';
yield [$media_path.'/test/img.jpg', '%MEDIA%/test/img.jpg'];
yield [$media_path.'/test/img.jpg', '%BASE%/data/media/test/img.jpg', true];
yield [$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg'];
yield [$footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg', true];
$this->projectDir_orig = realpath(self::$kernel->getProjectDir());
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->media_path = $this->projectDir.'/public/media';
$this->footprint_path = $this->projectDir.'/public/img/footprints';
yield [$this->media_path.'/test/img.jpg', '%MEDIA%/test/img.jpg'];
yield [$this->media_path.'/test/img.jpg', '%BASE%/data/media/test/img.jpg', true];
yield [$this->footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg'];
yield [$this->footprint_path.'/foo.jpg', '%FOOTPRINTS%/foo.jpg', true];
//Every kind of absolute path, that is not based with our placeholder dirs must be invald
yield ['/etc/passwd', null];
yield ['C:\\not\\existing.txt', null];
//More than one placeholder is not allowed
yield [$footprint_path.'/test/'.$footprint_path, null];
yield [$this->footprint_path.'/test/'.$this->footprint_path, null];
//Path must begin with path
yield ['/not/root'.$footprint_path, null];
yield ['/not/root'.$this->footprint_path, null];
}
#[DataProvider('placeholderDataProvider')]
/**
* @dataProvider placeholderDataProvider
*/
public function testPlaceholderToRealPath($param, $expected): void
{
$this->assertSame($expected, $this->service->placeholderToRealPath($param));
}
#[DataProvider('realPathDataProvider')]
/**
* @dataProvider realPathDataProvider
*/
public function testRealPathToPlaceholder($param, $expected, $old_method = false): void
{
$this->assertSame($expected, $this->service->realPathToPlaceholder($param, $old_method));
}
public static function germanFootprintPathdDataProvider(): ?\Generator
public function germanFootprintPathdDataProvider(): ?\Generator
{
self::bootKernel();
$projectDir_orig = realpath(self::$kernel->getProjectDir());
$projectDir = str_replace('\\', '/', $projectDir_orig);
$footprint_path = $projectDir.'/public/img/footprints';
$this->projectDir_orig = realpath(self::$kernel->getProjectDir());
$this->projectDir = str_replace('\\', '/', $this->projectDir_orig);
$this->footprint_path = $this->projectDir.'/public/img/footprints';
yield [$footprint_path. '/Active/Diodes/THT/DIODE_P600.png', '%FOOTPRINTS%/Aktiv/Dioden/Bedrahtet/DIODE_P600.png'];
yield [$footprint_path . '/Passive/Resistors/THT/Carbon/RESISTOR-CARBON_0207.png', '%FOOTPRINTS%/Passiv/Widerstaende/Bedrahtet/Kohleschicht/WIDERSTAND-KOHLE_0207.png'];
yield [$footprint_path . '/Optics/LEDs/THT/LED-GREEN_3MM.png', '%FOOTPRINTS%/Optik/LEDs/Bedrahtet/LED-GRUEN_3MM.png'];
yield [$footprint_path . '/Passive/Capacitors/TrimmerCapacitors/TRIMMER_CAPACITOR-RED_TZ03F.png', '%FOOTPRINTS%/Passiv/Kondensatoren/Trimmkondensatoren/TRIMMKONDENSATOR-ROT_TZ03F.png'];
yield [$footprint_path . '/Active/ICs/TO/IC_TO126.png', '%FOOTPRINTS%/Aktiv/ICs/TO/IC_TO126.png'];
yield [$footprint_path . '/Electromechanics/Switches_Buttons/RotarySwitches/ROTARY_SWITCH_DIP10.png', '%FOOTPRINTS%/Elektromechanik/Schalter_Taster/Drehschalter/DREHSCHALTER_DIP10.png'];
yield [$footprint_path . '/Electromechanics/Connectors/DINConnectors/SOCKET_DIN_MAB_4.png', '%FOOTPRINTS%/Elektromechanik/Verbinder/Rundsteckverbinder/BUCHSE_DIN_MAB_4.png'];
yield [$this->footprint_path. '/Active/Diodes/THT/DIODE_P600.png', '%FOOTPRINTS%/Aktiv/Dioden/Bedrahtet/DIODE_P600.png'];
yield [$this->footprint_path . '/Passive/Resistors/THT/Carbon/RESISTOR-CARBON_0207.png', '%FOOTPRINTS%/Passiv/Widerstaende/Bedrahtet/Kohleschicht/WIDERSTAND-KOHLE_0207.png'];
yield [$this->footprint_path . '/Optics/LEDs/THT/LED-GREEN_3MM.png', '%FOOTPRINTS%/Optik/LEDs/Bedrahtet/LED-GRUEN_3MM.png'];
yield [$this->footprint_path . '/Passive/Capacitors/TrimmerCapacitors/TRIMMER_CAPACITOR-RED_TZ03F.png', '%FOOTPRINTS%/Passiv/Kondensatoren/Trimmkondensatoren/TRIMMKONDENSATOR-ROT_TZ03F.png'];
yield [$this->footprint_path . '/Active/ICs/TO/IC_TO126.png', '%FOOTPRINTS%/Aktiv/ICs/TO/IC_TO126.png'];
yield [$this->footprint_path . '/Electromechanics/Switches_Buttons/RotarySwitches/ROTARY_SWITCH_DIP10.png', '%FOOTPRINTS%/Elektromechanik/Schalter_Taster/Drehschalter/DREHSCHALTER_DIP10.png'];
yield [$this->footprint_path . '/Electromechanics/Connectors/DINConnectors/SOCKET_DIN_MAB_4.png', '%FOOTPRINTS%/Elektromechanik/Verbinder/Rundsteckverbinder/BUCHSE_DIN_MAB_4.png'];
//Leave english pathes untouched
yield [$footprint_path . '/Passive/Capacitors/CAPACITOR_CTS_A_15MM.png', '%FOOTPRINTS%/Passive/Capacitors/CAPACITOR_CTS_A_15MM.png'];
yield [$this->footprint_path . '/Passive/Capacitors/CAPACITOR_CTS_A_15MM.png', '%FOOTPRINTS%/Passive/Capacitors/CAPACITOR_CTS_A_15MM.png'];
}
#[DataProvider('germanFootprintPathdDataProvider')]
/**
* @dataProvider germanFootprintPathdDataProvider
*/
public function testConversionOfGermanFootprintPaths(string $expected, string $input): void
{
$this->assertSame($expected, $this->service->placeholderToRealPath($input));

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\Attachments;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Attachments\AttachmentURLGenerator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -39,7 +38,7 @@ class AttachmentURLGeneratorTest extends WebTestCase
self::$service = self::getContainer()->get(AttachmentURLGenerator::class);
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
yield ['/public/test.jpg', 'test.jpg'];
yield ['/public/folder/test.jpg', 'folder/test.jpg'];
@ -49,11 +48,11 @@ class AttachmentURLGeneratorTest extends WebTestCase
}
/**
* @dataProvider dataProvider
*
* @param $input
* @param $expected
*/
#[DataProvider('dataProvider')]
public function testTestabsolutePathToAssetPath($input, $expected): void
{
$this->assertSame($expected, static::$service->absolutePathToAssetPath($input, static::PUBLIC_DIR));

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\Attachments;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Attachments\BuiltinAttachmentsFinder;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -44,7 +43,7 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
self::$service = self::getContainer()->get(BuiltinAttachmentsFinder::class);
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
//No value should return empty array
yield ['', [], []];
@ -55,7 +54,9 @@ class BuiltinAttachmentsFinderTest extends WebTestCase
yield ['.txt', [], ['%FOOTPRINTS_3D%/hallo.txt']];
}
#[DataProvider('dataProvider')]
/**
* @dataProvider dataProvider
*/
public function testFind($keyword, $options, $expected): void
{
$value = static::$service->find($keyword, $options, static::$mock_list);

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\Attachments;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Attachments\FileTypeFilterTools;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -36,7 +35,7 @@ class FileTypeFilterToolsTest extends WebTestCase
self::$service = self::getContainer()->get(FileTypeFilterTools::class);
}
public static function validateDataProvider(): \Iterator
public function validateDataProvider(): \Iterator
{
yield ['', true];
//Empty string is valid
@ -55,7 +54,7 @@ class FileTypeFilterToolsTest extends WebTestCase
yield ['.png .jpg .gif', false];
}
public static function normalizeDataProvider(): \Iterator
public function normalizeDataProvider(): \Iterator
{
yield ['', ''];
yield ['.jpeg,.png,.gif', '.jpeg,.png,.gif'];
@ -69,7 +68,7 @@ class FileTypeFilterToolsTest extends WebTestCase
yield ['png, .gif, .png,', '.png,.gif'];
}
public static function extensionAllowedDataProvider(): \Iterator
public function extensionAllowedDataProvider(): \Iterator
{
yield ['', 'txt', true];
yield ['', 'everything_should_match', true];
@ -86,20 +85,25 @@ class FileTypeFilterToolsTest extends WebTestCase
/**
* Test the validateFilterString method.
*
* @dataProvider validateDataProvider
*/
#[DataProvider('validateDataProvider')]
public function testValidateFilterString(string $filter, bool $expected): void
{
$this->assertSame($expected, self::$service->validateFilterString($filter));
}
#[DataProvider('normalizeDataProvider')]
/**
* @dataProvider normalizeDataProvider
*/
public function testNormalizeFilterString(string $filter, string $expected): void
{
$this->assertSame($expected, self::$service->normalizeFilterString($filter));
}
#[DataProvider('extensionAllowedDataProvider')]
/**
* @dataProvider extensionAllowedDataProvider
*/
public function testIsExtensionAllowed(string $filter, string $extension, bool $expected): void
{
$this->assertSame($expected, self::$service->isExtensionAllowed($filter, $extension));

View file

@ -178,9 +178,7 @@ class PartMergerTest extends KernelTestCase
//But the new lots, should be assigned to the target part and contain the same info
$clone3 = $merged->getPartLots()->get(2);
$clone4 = $merged->getPartLots()->get(3);
$this->assertInstanceOf(PartLot::class, $clone3);
$this->assertSame($merged, $clone3->getPart());
$this->assertInstanceOf(PartLot::class, $clone4);
$this->assertSame($merged, $clone4->getPart());
}

View file

@ -22,8 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\ImportExportSystem;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Attachments\AttachmentType;
use App\Entity\LabelSystem\LabelProfile;
@ -37,7 +35,9 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationListInterface;
#[Group('DB')]
/**
* @group DB
*/
class EntityImporterTest extends WebTestCase
{
/**
@ -174,7 +174,7 @@ EOT;
$this->assertSame($longName, $errors[0]['entity']->getName());
}
public static function formatDataProvider(): \Iterator
public function formatDataProvider(): \Iterator
{
yield ['csv', 'csv'];
yield ['csv', 'CSV'];
@ -184,7 +184,9 @@ EOT;
yield ['yaml', 'YAML'];
}
#[DataProvider('formatDataProvider')]
/**
* @dataProvider formatDataProvider
*/
public function testDetermineFormat(string $expected, string $extension): void
{
$this->assertSame($expected, $this->service->determineFormat($extension));

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
*/
namespace App\Tests\Services\InfoProviderSystem\DTOs;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\InfoProviderSystem\DTOs\FileDTO;
use PHPUnit\Framework\TestCase;
@ -41,7 +40,9 @@ class FileDTOTest extends TestCase
yield ["test%7Cse", "test|se"];
}
#[DataProvider('escapingDataProvider')]
/**
* @dataProvider escapingDataProvider
*/
public function testURLEscaping(string $expected, string $input): void
{
$fileDTO = new FileDTO( $input);

View file

@ -22,14 +22,13 @@ declare(strict_types=1);
*/
namespace App\Tests\Services\InfoProviderSystem\DTOs;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
use PHPUnit\Framework\TestCase;
class ParameterDTOTest extends TestCase
{
public static function parseValueFieldDataProvider(): \Generator
public function parseValueFieldDataProvider(): \Generator
{
//Text value
yield [
@ -132,7 +131,7 @@ class ParameterDTOTest extends TestCase
];
}
public static function parseValueIncludingUnitDataProvider(): \Generator
public function parseValueIncludingUnitDataProvider(): \Generator
{
//Text value
yield [
@ -235,18 +234,18 @@ class ParameterDTOTest extends TestCase
}
/**
* @dataProvider parseValueFieldDataProvider
* @return void
*/
#[DataProvider('parseValueFieldDataProvider')]
public function testParseValueField(ParameterDTO $expected, string $name, string|float $value, ?string $unit = null, ?string $symbol = null, ?string $group = null)
{
$this->assertEquals($expected, ParameterDTO::parseValueField($name, $value, $unit, $symbol, $group));
}
/**
* @dataProvider parseValueIncludingUnitDataProvider
* @return void
*/
#[DataProvider('parseValueIncludingUnitDataProvider')]
public function testParseValueIncludingUnit(ParameterDTO $expected, string $name, string|float $value, ?string $symbol = null, ?string $group = null)
{
$this->assertEquals($expected, ParameterDTO::parseValueIncludingUnit($name, $value, $symbol, $group));

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
*/
namespace App\Tests\Services\InfoProviderSystem;
use App\Entity\PriceInformations\Currency;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Parts\ManufacturingStatus;
use App\Services\InfoProviderSystem\DTOs\FileDTO;
@ -84,7 +83,6 @@ class DTOtoEntityConverterTest extends WebTestCase
//For non-base currencies, a new currency entity is created
$currency = $entity->getCurrency();
$this->assertInstanceOf(Currency::class, $currency);
$this->assertEquals($dto->currency_iso_code, $currency->getIsoCode());
}

View file

@ -41,8 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\BarcodeScanner;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\LabelSystem\LabelSupportedElement;
use App\Services\LabelSystem\BarcodeScanner\BarcodeRedirector;
use App\Services\LabelSystem\BarcodeScanner\BarcodeSourceType;
@ -68,8 +66,10 @@ final class BarcodeRedirectorTest extends KernelTestCase
yield [new LocalBarcodeScanResult(LabelSupportedElement::STORELOCATION, 1, BarcodeSourceType::INTERNAL), '/en/store_location/1/parts'];
}
#[DataProvider('urlDataProvider')]
#[Group('DB')]
/**
* @dataProvider urlDataProvider
* @group DB
*/
public function testGetRedirectURL(LocalBarcodeScanResult $scanResult, string $url): void
{
$this->assertSame($url, $this->service->getRedirectURL($scanResult));

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\BarcodeScanner;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\LabelSystem\LabelSupportedElement;
use App\Services\LabelSystem\BarcodeScanner\BarcodeScanHelper;
use App\Services\LabelSystem\BarcodeScanner\BarcodeScanResultInterface;
@ -141,13 +140,17 @@ class BarcodeScanHelperTest extends WebTestCase
yield [''];
}
#[DataProvider('dataProvider')]
/**
* @dataProvider dataProvider
*/
public function testNormalizeBarcodeContent(BarcodeScanResultInterface $expected, string $input): void
{
$this->assertEquals($expected, $this->service->scanBarcodeContent($input));
}
#[DataProvider('invalidDataProvider')]
/**
* @dataProvider invalidDataProvider
*/
public function testInvalidFormats(string $input): void
{
$this->expectException(\InvalidArgumentException::class);

View file

@ -1,7 +1,4 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,6 +17,7 @@ declare(strict_types=1);
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Tests\Services\LabelSystem\BarcodeScanner;
use App\Services\LabelSystem\BarcodeScanner\EIGP114BarcodeScanResult;
@ -53,7 +51,7 @@ class EIGP114BarcodeScanResultTest extends TestCase
'4L' => 'US',
'13Z' => 'Digi-Key',
]);
$this->assertSame('digikey', $barcode->guessBarcodeVendor());
$this->assertEquals('digikey', $barcode->guessBarcodeVendor());
//Mouser barcode:
$barcode = new EIGP114BarcodeScanResult([
@ -66,7 +64,7 @@ class EIGP114BarcodeScanResultTest extends TestCase
'1V' => 'Mouser',
]);
$this->assertSame('mouser', $barcode->guessBarcodeVendor());
$this->assertEquals('mouser', $barcode->guessBarcodeVendor());
//Farnell barcode:
$barcode = new EIGP114BarcodeScanResult([
@ -79,7 +77,7 @@ class EIGP114BarcodeScanResultTest extends TestCase
'3P' => 'Farnell',
]);
$this->assertSame('element14', $barcode->guessBarcodeVendor());
$this->assertEquals('element14', $barcode->guessBarcodeVendor());
}
public function testIsFormat06Code(): void
@ -104,7 +102,7 @@ class EIGP114BarcodeScanResultTest extends TestCase
public function testParseFormat06Code(): void
{
$barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>\x1E06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04");
$this->assertSame([
$this->assertEquals([
'P' => '596-777A1-ND',
'1P' => 'XAF4444',
'Q' => '3',
@ -125,32 +123,32 @@ class EIGP114BarcodeScanResultTest extends TestCase
'4L' => 'US',
]);
$this->assertSame('596-777A1-ND', $barcode->customerPartNumber);
$this->assertSame('XAF4444', $barcode->supplierPartNumber);
$this->assertSame(3, $barcode->quantity);
$this->assertSame('1452', $barcode->alternativeDateCode);
$this->assertSame('BF1103', $barcode->lotCode);
$this->assertSame('US', $barcode->countryOfOrigin);
$this->assertEquals('596-777A1-ND', $barcode->customerPartNumber);
$this->assertEquals('XAF4444', $barcode->supplierPartNumber);
$this->assertEquals(3, $barcode->quantity);
$this->assertEquals('1452', $barcode->alternativeDateCode);
$this->assertEquals('BF1103', $barcode->lotCode);
$this->assertEquals('US', $barcode->countryOfOrigin);
}
public function testDigikeyParsing(): void
{
$barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>\x1e06\x1dPQ1045-ND\x1d1P364019-01\x1d30PQ1045-ND\x1dK12432 TRAVIS FOSS P\x1d1K85732873\x1d10K103332956\x1d9D231013\x1d1TQJ13P\x1d11K1\x1d4LTW\x1dQ3\x1d11ZPICK\x1d12Z7360988\x1d13Z999999\x1d20Z0000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
$this->assertSame('digikey', $barcode->guessBarcodeVendor());
$this->assertEquals('digikey', $barcode->guessBarcodeVendor());
$this->assertSame('Q1045-ND', $barcode->customerPartNumber);
$this->assertSame('364019-01', $barcode->supplierPartNumber);
$this->assertSame(3, $barcode->quantity);
$this->assertSame('231013', $barcode->dateCode);
$this->assertSame('QJ13P', $barcode->lotCode);
$this->assertSame('TW', $barcode->countryOfOrigin);
$this->assertSame('Q1045-ND', $barcode->digikeyPartNumber);
$this->assertSame('85732873', $barcode->digikeySalesOrderNumber);
$this->assertSame('103332956', $barcode->digikeyInvoiceNumber);
$this->assertSame('PICK', $barcode->digikeyLabelType);
$this->assertSame('7360988', $barcode->digikeyPartID);
$this->assertSame('999999', $barcode->digikeyNA);
$this->assertSame('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000', $barcode->digikeyPadding);
$this->assertEquals('Q1045-ND', $barcode->customerPartNumber);
$this->assertEquals('364019-01', $barcode->supplierPartNumber);
$this->assertEquals(3, $barcode->quantity);
$this->assertEquals('231013', $barcode->dateCode);
$this->assertEquals('QJ13P', $barcode->lotCode);
$this->assertEquals('TW', $barcode->countryOfOrigin);
$this->assertEquals('Q1045-ND', $barcode->digikeyPartNumber);
$this->assertEquals('85732873', $barcode->digikeySalesOrderNumber);
$this->assertEquals('103332956', $barcode->digikeyInvoiceNumber);
$this->assertEquals('PICK', $barcode->digikeyLabelType);
$this->assertEquals('7360988', $barcode->digikeyPartID);
$this->assertEquals('999999', $barcode->digikeyNA);
$this->assertEquals('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000', $barcode->digikeyPadding);
}
}

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\Barcodes;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\StorageLocation;
@ -58,27 +57,31 @@ class BarcodeContentGeneratorTest extends KernelTestCase
$this->service = self::getContainer()->get(BarcodeContentGenerator::class);
}
public static function Barcode1DDataProvider(): \Iterator
public function Barcode1DDataProvider(): \Iterator
{
yield ['P0000', Part::class];
yield ['L0000', PartLot::class];
yield ['S0000', StorageLocation::class];
}
public static function Barcode2DDataProvider(): \Iterator
public function Barcode2DDataProvider(): \Iterator
{
yield ['/scan/part/0', Part::class];
yield ['/scan/lot/0', PartLot::class];
yield ['/scan/location/0', StorageLocation::class];
}
#[DataProvider('Barcode1DDataProvider')]
/**
* @dataProvider Barcode1DDataProvider
*/
public function testGet1DBarcodeContent(string $expected, string $class): void
{
$this->assertSame($expected, $this->service->get1DBarcodeContent(new $class()));
}
#[DataProvider('Barcode2DDataProvider')]
/**
* @dataProvider Barcode2DDataProvider
*/
public function testGetURLContent(string $expected, string $class): void
{
$url = $this->service->getURLContent(new $class());

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Base\AbstractDBElement;
use App\Entity\LabelSystem\LabelOptions;
use App\Entity\LabelSystem\LabelSupportedElement;
@ -71,7 +70,9 @@ class LabelGeneratorTest extends WebTestCase
yield [LabelSupportedElement::STORELOCATION, StorageLocation::class];
}
#[DataProvider('supportsDataProvider')]
/**
* @dataProvider supportsDataProvider
*/
public function testSupports(LabelSupportedElement $type, string $class): void
{
$options = new LabelOptions();

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Services\LabelSystem\LabelTextReplacer;
@ -71,7 +70,7 @@ class LabelTextReplacerTest extends WebTestCase
$this->target->setComment('P Comment');
}
public static function handlePlaceholderDataProvider(): \Iterator
public function handlePlaceholderDataProvider(): \Iterator
{
yield ['Part 1', '[[NAME]]'];
yield ['P Description', '[[DESCRIPTION]]'];
@ -83,7 +82,7 @@ class LabelTextReplacerTest extends WebTestCase
yield ['Test [[NAME]]', 'Test [[NAME]]', 'Test [[NAME]]'];
}
public static function replaceDataProvider(): \Iterator
public function replaceDataProvider(): \Iterator
{
yield ['Part 1', '[[NAME]]'];
yield ['TestPart 1', 'Test[[NAME]]'];
@ -95,13 +94,17 @@ class LabelTextReplacerTest extends WebTestCase
yield ['TEST[[ ]]TEST', 'TEST[[ ]]TEST'];
}
#[DataProvider('handlePlaceholderDataProvider')]
/**
* @dataProvider handlePlaceholderDataProvider
*/
public function testHandlePlaceholder(string $expected, string $input): void
{
$this->assertSame($expected, $this->service->handlePlaceholder($input, $this->target));
}
#[DataProvider('replaceDataProvider')]
/**
* @dataProvider replaceDataProvider
*/
public function testReplace(string $expected, string $input): void
{
$this->assertSame($expected, $this->service->replace($input, $this->target));

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Base\AbstractDBElement;
use App\Services\LabelSystem\PlaceholderProviders\AbstractDBElementProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -64,12 +63,14 @@ class AbstractElementProviderTest extends WebTestCase
};
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
yield ['123', '[[ID]]'];
}
#[DataProvider('dataProvider')]
/**
* @dataProvider dataProvider
*/
public function testReplace(string $expected, string $placeholder): void
{
$this->assertSame($expected, $this->service->replace($placeholder, $this->target));

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -62,13 +61,15 @@ class GlobalProvidersTest extends WebTestCase
$this->target = new Part();
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
yield ['Part-DB', '[[INSTALL_NAME]]'];
yield ['anonymous', '[[USERNAME]]'];
}
#[DataProvider('dataProvider')]
/**
* @dataProvider dataProvider
*/
public function testReplace(string $expected, string $placeholder): void
{
$this->assertSame($expected, $this->service->replace($placeholder, $this->target));

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Contracts\NamedElementInterface;
use App\Services\LabelSystem\PlaceholderProviders\NamedElementProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -67,12 +66,14 @@ class NamedElementProviderTest extends WebTestCase
};
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
yield ['This is my Name', '[[NAME]]'];
}
#[DataProvider('dataProvider')]
/**
* @dataProvider dataProvider
*/
public function testReplace(string $expected, string $placeholder): void
{
$this->assertSame($expected, $this->service->replace($placeholder, $this->target));

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\StorageLocation;
@ -86,7 +85,7 @@ class PartLotProviderTest extends WebTestCase
$this->target->setOwner($user);
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
yield ['unknown', '[[LOT_ID]]'];
yield ['Lot description', '[[LOT_NAME]]'];
@ -102,7 +101,9 @@ class PartLotProviderTest extends WebTestCase
yield ['user', '[[OWNER_USERNAME]]'];
}
#[DataProvider('dataProvider')]
/**
* @dataProvider dataProvider
*/
public function testReplace(string $expected, string $placeholder): void
{
$this->assertSame($expected, $this->service->replace($placeholder, $this->target));

View file

@ -41,8 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Parts\ManufacturingStatus;
use Doctrine\ORM\EntityManager;
use App\Entity\Parts\Category;
@ -52,7 +50,9 @@ use App\Services\LabelSystem\PlaceholderProviders\PartProvider;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
#[Group('DB')]
/**
* @group DB
*/
class PartProviderTest extends WebTestCase
{
/**
@ -87,7 +87,7 @@ class PartProviderTest extends WebTestCase
$this->target->setComment('<b>Bold</b> *Italic*');
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
yield ['Node 2.1', '[[CATEGORY]]'];
yield ['Node 2 → Node 2.1', '[[CATEGORY_FULL]]'];
@ -105,7 +105,9 @@ class PartProviderTest extends WebTestCase
yield ['Bold Italic', '[[COMMENT_T]]'];
}
#[DataProvider('dataProvider')]
/**
* @dataProvider dataProvider
*/
public function testReplace(string $expected, string $placeholder): void
{
$this->assertSame($expected, $this->service->replace($placeholder, $this->target));

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Contracts\TimeStampableInterface;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use App\Services\LabelSystem\PlaceholderProviders\TimestampableElementProvider;
@ -75,14 +74,16 @@ class TimestampableElementProviderTest extends WebTestCase
};
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
\Locale::setDefault('en');
yield ['1/1/00, 12:00 AM', '[[LAST_MODIFIED]]'];
yield ['1/1/00, 12:00 AM', '[[CREATION_DATE]]'];
}
#[DataProvider('dataProvider')]
/**
* @dataProvider dataProvider
*/
public function testReplace(string $expected, string $placeholder): void
{
$this->assertSame($expected, $this->service->replace($placeholder, $this->target));

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\LabelSystem;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\LabelSystem\LabelOptions;
use App\Entity\LabelSystem\LabelProcessMode;
use App\Entity\LabelSystem\LabelSupportedElement;
@ -62,7 +61,7 @@ class SandboxedTwigFactoryTest extends WebTestCase
$this->service = self::getContainer()->get(SandboxedTwigFactory::class);
}
public static function twigDataProvider(): \Iterator
public function twigDataProvider(): \Iterator
{
yield [' {% for i in range(1, 3) %}
{{ part.id }}
@ -95,7 +94,7 @@ class SandboxedTwigFactoryTest extends WebTestCase
'];
}
public static function twigNotAllowedDataProvider(): \Iterator
public function twigNotAllowedDataProvider(): \Iterator
{
yield ['{% block test %} {% endblock %}'];
yield ['{% deprecated test %}'];
@ -104,7 +103,9 @@ class SandboxedTwigFactoryTest extends WebTestCase
yield ['{{ part.setCategory(null) }}'];
}
#[DataProvider('twigDataProvider')]
/**
* @dataProvider twigDataProvider
*/
public function testTwigFeatures(string $twig): void
{
$options = new LabelOptions();
@ -122,7 +123,9 @@ class SandboxedTwigFactoryTest extends WebTestCase
$this->assertIsString($str);
}
#[DataProvider('twigNotAllowedDataProvider')]
/**
* @dataProvider twigNotAllowedDataProvider
*/
public function testTwigForbidden(string $twig): void
{
$this->expectException(SecurityError::class);

View file

@ -1,7 +1,4 @@
<?php
declare(strict_types=1);
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -20,6 +17,7 @@ declare(strict_types=1);
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Tests\Services\LogSystem;
use App\Entity\LogSystem\ElementEditedLogEntry;
@ -47,7 +45,7 @@ class TimeTravelTest extends KernelTestCase
$undeletedCategory = $this->service->undeleteEntity(Category::class, 100);
$this->assertInstanceOf(Category::class, $undeletedCategory);
$this->assertSame(100, $undeletedCategory->getId());
$this->assertEquals(100, $undeletedCategory->getId());
}
public function testApplyEntry(): void
@ -65,8 +63,8 @@ class TimeTravelTest extends KernelTestCase
$this->service->applyEntry($category, $logEntry);
$this->assertSame('Old Category', $category->getName());
$this->assertSame('Old Comment', $category->getComment());
$this->assertEquals('Old Category', $category->getName());
$this->assertEquals('Old Comment', $category->getComment());
}
public function testRevertEntityToTimestamp(): void

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\Misc;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Misc\FAIconGenerator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -42,7 +41,7 @@ class FAIconGeneratorTest extends WebTestCase
$this->service = self::getContainer()->get(FAIconGenerator::class);
}
public static function fileExtensionDataProvider(): \Iterator
public function fileExtensionDataProvider(): \Iterator
{
yield ['pdf', 'fa-file-pdf'];
yield ['jpeg','fa-file-image'];
@ -96,7 +95,9 @@ class FAIconGeneratorTest extends WebTestCase
yield ['fgd', 'fa-file'];
}
#[DataProvider('fileExtensionDataProvider')]
/**
* @dataProvider fileExtensionDataProvider
*/
public function testFileExtensionToFAType(string $ext, string $expected): void
{
$this->assertSame($expected, $this->service->fileExtensionToFAType($ext), 'Failed for extension .'.$ext);

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\Misc;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\Misc\RangeParser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -58,7 +57,7 @@ class RangeParserTest extends WebTestCase
$this->service = self::getContainer()->get(RangeParser::class);
}
public static function dataProvider(): \Iterator
public function dataProvider(): \Iterator
{
yield [[], ''];
yield [[], ' '];
@ -82,7 +81,7 @@ class RangeParserTest extends WebTestCase
yield [[], '1, 2, test', true];
}
public static function validDataProvider(): \Iterator
public function validDataProvider(): \Iterator
{
yield [true, ''];
yield [true, ' '];
@ -97,7 +96,9 @@ class RangeParserTest extends WebTestCase
yield [false, '1, 2 test'];
}
#[DataProvider('dataProvider')]
/**
* @dataProvider dataProvider
*/
public function testParse(array $expected, string $input, bool $must_throw = false): void
{
if ($must_throw) {
@ -108,7 +109,9 @@ class RangeParserTest extends WebTestCase
}
}
#[DataProvider('validDataProvider')]
/**
* @dataProvider validDataProvider
*/
public function testIsValidRange(bool $expected, string $input): void
{
$this->assertSame($expected, $this->service->isValidRange($input));

View file

@ -41,7 +41,6 @@ declare(strict_types=1);
namespace App\Tests\Services\Parameters;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Parameters\AbstractParameter;
use App\Services\Parameters\ParameterExtractor;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -57,7 +56,7 @@ class ParameterExtractorTest extends WebTestCase
$this->service = self::getContainer()->get(ParameterExtractor::class);
}
public static function emptyDataProvider(): \Iterator
public function emptyDataProvider(): \Iterator
{
yield [''];
yield [' '];
@ -70,7 +69,9 @@ class ParameterExtractorTest extends WebTestCase
yield ['A [link](https://demo.part-db.de) should not be matched'];
}
#[DataProvider('emptyDataProvider')]
/**
* @dataProvider emptyDataProvider
*/
public function testShouldReturnEmpty(string $input): void
{
$this->assertEmpty($this->service->extractParameters($input));

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\Parts;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
@ -44,7 +43,7 @@ class PricedetailHelperTest extends WebTestCase
$this->service = self::getContainer()->get(PricedetailHelper::class);
}
public static function maxDiscountAmountDataProvider(): ?\Generator
public function maxDiscountAmountDataProvider(): ?\Generator
{
$part = new Part();
yield [$part, null, 'Part without any orderdetails failed!'];
@ -82,7 +81,9 @@ class PricedetailHelperTest extends WebTestCase
yield [$part, 10.0, 'Part with multiple orderdetails failed'];
}
#[DataProvider('maxDiscountAmountDataProvider')]
/**
* @dataProvider maxDiscountAmountDataProvider
*/
public function testGetMaxDiscountAmount(Part $part, ?float $expected_result, string $message): void
{
$this->assertSame($expected_result, $this->service->getMaxDiscountAmount($part), $message);

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\Trees;
use PHPUnit\Framework\Attributes\Group;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Parts\Category;
use App\Helpers\Trees\TreeViewNode;
@ -30,7 +29,9 @@ use App\Services\Trees\TreeViewGenerator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
#[Group('DB')]
/**
* @group DB
*/
class TreeViewGeneratorTest extends WebTestCase
{
protected $em;

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\UserSystem;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\PermissionData;
use App\Entity\UserSystem\User;
@ -92,7 +91,7 @@ class PermissionManagerTest extends WebTestCase
$this->group->method('getParent')->willReturn($parent_group);
}
public static function getPermissionNames(): \Iterator
public function getPermissionNames(): \Iterator
{
//List some permission names
yield ['parts'];
@ -102,7 +101,9 @@ class PermissionManagerTest extends WebTestCase
yield ['tools'];
}
#[DataProvider('getPermissionNames')]
/**
* @dataProvider getPermissionNames
*/
public function testListOperationsForPermission($perm_name): void
{
$arr = $this->service->listOperationsForPermission($perm_name);

View file

@ -90,9 +90,9 @@ class PermissionSchemaUpdaterTest extends WebTestCase
//Do an upgrade and afterward the move, add, and withdraw permissions should be set to ALLOW
self::assertTrue($this->service->upgradeSchema($user, 1));
self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'move'));
self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'add'));
self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'withdraw'));
self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'move'));
self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'add'));
self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('parts_stock', 'withdraw'));
}
public function testUpgradeSchemaToVersion2(): void
@ -106,9 +106,9 @@ class PermissionSchemaUpdaterTest extends WebTestCase
//After the upgrade all operations should be available under the name "projects" with the same values
self::assertTrue($this->service->upgradeSchema($user, 2));
self::assertSame(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('projects', 'read'));
self::assertSame(PermissionData::INHERIT, $user->getPermissions()->getPermissionValue('projects', 'edit'));
self::assertSame(PermissionData::DISALLOW, $user->getPermissions()->getPermissionValue('projects', 'delete'));
self::assertEquals(PermissionData::ALLOW, $user->getPermissions()->getPermissionValue('projects', 'read'));
self::assertEquals(PermissionData::INHERIT, $user->getPermissions()->getPermissionValue('projects', 'edit'));
self::assertEquals(PermissionData::DISALLOW, $user->getPermissions()->getPermissionValue('projects', 'delete'));
}
public function testUpgradeSchemaToVersion3(): void

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace App\Tests\Services\UserSystem\TFA;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Services\UserSystem\TFA\BackupCodeGenerator;
use PHPUnit\Framework\TestCase;
use RuntimeException;
@ -47,7 +46,7 @@ class BackupCodeGeneratorTest extends TestCase
new BackupCodeGenerator(4, 10);
}
public static function codeLengthDataProvider(): \Iterator
public function codeLengthDataProvider(): \Iterator
{
yield [6];
yield [8];
@ -55,21 +54,25 @@ class BackupCodeGeneratorTest extends TestCase
yield [16];
}
#[DataProvider('codeLengthDataProvider')]
/**
* @dataProvider codeLengthDataProvider
*/
public function testGenerateSingleCode(int $code_length): void
{
$generator = new BackupCodeGenerator($code_length, 10);
$this->assertMatchesRegularExpression("/^([a-f0-9]){{$code_length}}\$/", $generator->generateSingleCode());
}
public static function codeCountDataProvider(): \Iterator
public function codeCountDataProvider(): \Iterator
{
yield [2];
yield [8];
yield [10];
}
#[DataProvider('codeCountDataProvider')]
/**
* @dataProvider codeCountDataProvider
*/
public function testGenerateCodeSet(int $code_count): void
{
$generator = new BackupCodeGenerator(8, $code_count);

View file

@ -22,8 +22,6 @@ declare(strict_types=1);
namespace App\Tests;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\ResettableSettingsInterface;
use InvalidArgumentException;
use ReflectionClass;
@ -43,14 +41,14 @@ class SettingsTestHelper
$reflection = new ReflectionClass($class);
//Check if it is a settings class (has a Settings attribute)
if ($reflection->getAttributes(Settings::class) === []) {
if ($reflection->getAttributes(\Jbtronics\SettingsBundle\Settings\Settings::class) === []) {
throw new InvalidArgumentException("The class $class is not a settings class!");
}
$object = $reflection->newInstanceWithoutConstructor();
//If the object has some initialization logic, then call it
if ($object instanceof ResettableSettingsInterface) {
if ($object instanceof \Jbtronics\SettingsBundle\Settings\ResettableSettingsInterface) {
$object->resetToDefaultValues();
}

View file

@ -22,7 +22,6 @@ declare(strict_types=1);
*/
namespace App\Tests\Twig;
use PHPUnit\Framework\Attributes\DataProvider;
use App\Twig\UserExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -37,7 +36,7 @@ class UserExtensionTest extends WebTestCase
$this->service = self::getContainer()->get(UserExtension::class);
}
public static function removeLocaleFromPathDataSet(): ?\Generator
public function removeLocaleFromPathDataSet(): ?\Generator
{
yield ['/', '/de/'];
yield ['/test', '/de/test'];
@ -47,7 +46,9 @@ class UserExtensionTest extends WebTestCase
yield ['/test/foo/bar?param1=val1&param2=val2', '/de_DE/test/foo/bar?param1=val1&param2=val2'];
}
#[DataProvider('removeLocaleFromPathDataSet')]
/**
* @dataProvider removeLocaleFromPathDataSet
*/
public function testRemoveLocaleFromPath(string $expected, string $input): void
{
$this->assertSame($expected, $this->service->removeLocaleFromPath($input));