From d898ca736cf1371555eb68082493dce466b2c662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 22 Jun 2024 00:37:47 +0200 Subject: [PATCH] Applied rector to remaining test files --- tests/API/APIDocsAvailabilityTest.php | 12 ++--- .../AbstractAdminControllerTest.php | 24 ++++------ tests/Controller/RedirectControllerTest.php | 48 +++++++++---------- tests/Controller/ScanControllerTest.php | 6 ++- .../InfoProviderSystem/DTOs/FileDTOTest.php | 23 +++++---- 5 files changed, 52 insertions(+), 61 deletions(-) diff --git a/tests/API/APIDocsAvailabilityTest.php b/tests/API/APIDocsAvailabilityTest.php index bc3b6119..d2ed7fa4 100644 --- a/tests/API/APIDocsAvailabilityTest.php +++ b/tests/API/APIDocsAvailabilityTest.php @@ -56,13 +56,11 @@ class APIDocsAvailabilityTest extends WebTestCase self::assertResponseStatusCodeSame(403); } - public static function urlProvider(): array + public static function urlProvider(): \Iterator { - return [ - ['/api'], - ['/api/docs.html'], - ['/api/docs.json'], - ['/api/docs.jsonld'], - ]; + yield ['/api']; + yield ['/api/docs.html']; + yield ['/api/docs.json']; + yield ['/api/docs.jsonld']; } } \ No newline at end of file diff --git a/tests/Controller/AdminPages/AbstractAdminControllerTest.php b/tests/Controller/AdminPages/AbstractAdminControllerTest.php index ef0195c6..af3aefee 100644 --- a/tests/Controller/AdminPages/AbstractAdminControllerTest.php +++ b/tests/Controller/AdminPages/AbstractAdminControllerTest.php @@ -34,14 +34,12 @@ abstract class AbstractAdminControllerTest extends WebTestCase protected static string $base_path = 'not_valid'; protected static string $entity_class = 'not valid'; - public function readDataProvider(): array + public function readDataProvider(): \Iterator { - return [ - ['noread', false], - ['anonymous', true], - ['user', true], - ['admin', true], - ]; + yield ['noread', false]; + yield ['anonymous', true]; + yield ['user', true]; + yield ['admin', true]; } /** @@ -98,14 +96,12 @@ abstract class AbstractAdminControllerTest extends WebTestCase $this->assertSame($read, !$client->getResponse()->isForbidden(), 'Permission Checking not working!'); } - public function deleteDataProvider(): array + public function deleteDataProvider(): \Iterator { - return [ - ['noread', false], - ['anonymous', false], - ['user', true], - ['admin', true], - ]; + yield ['noread', false]; + yield ['anonymous', false]; + yield ['user', true]; + yield ['admin', true]; } /** diff --git a/tests/Controller/RedirectControllerTest.php b/tests/Controller/RedirectControllerTest.php index d7df73cc..029c93f5 100644 --- a/tests/Controller/RedirectControllerTest.php +++ b/tests/Controller/RedirectControllerTest.php @@ -50,18 +50,16 @@ class RedirectControllerTest extends WebTestCase $this->userRepo = $this->em->getRepository(User::class); } - public function urlMatchDataProvider(): array + public function urlMatchDataProvider(): \Iterator { - return [ - ['/', true], - ['/part/2/info', true], - ['/part/de/2', true], - ['/part/en/', true], - ['/de/', false], - ['/de_DE/', false], - ['/en/', false], - ['/en_US/', false], - ]; + yield ['/', true]; + yield ['/part/2/info', true]; + yield ['/part/de/2', true]; + yield ['/part/en/', true]; + yield ['/de/', false]; + yield ['/de_DE/', false]; + yield ['/en/', false]; + yield ['/en_US/', false]; } /** @@ -81,22 +79,20 @@ class RedirectControllerTest extends WebTestCase $this->assertSame($expect_redirect, $response->isRedirect()); } - public function urlAddLocaleDataProvider(): array + public function urlAddLocaleDataProvider(): \Iterator { - return [ - //User locale, original target, redirect target - ['de', '/', '/de/'], - ['de', '/part/3', '/de/part/3'], - ['en', '/', '/en/'], - ['en', '/category/new', '/en/category/new'], - ['en_US', '/part/3', '/en_US/part/3'], - //Without an explicit set value, the user should be redirected to english version - [null, '/', '/en/'], - ['en_US', '/part/3', '/en_US/part/3'], - //Test that query parameters work - ['de', '/dialog?target_id=133&target_type=part', '/de/dialog?target_id=133&target_type=part'], - ['en', '/dialog?storelocation=1', '/en/dialog?storelocation=1'], - ]; + //User locale, original target, redirect target + yield ['de', '/', '/de/']; + yield ['de', '/part/3', '/de/part/3']; + yield ['en', '/', '/en/']; + yield ['en', '/category/new', '/en/category/new']; + yield ['en_US', '/part/3', '/en_US/part/3']; + //Without an explicit set value, the user should be redirected to english version + yield [null, '/', '/en/']; + yield ['en_US', '/part/3', '/en_US/part/3']; + //Test that query parameters work + yield ['de', '/dialog?target_id=133&target_type=part', '/de/dialog?target_id=133&target_type=part']; + yield ['en', '/dialog?storelocation=1', '/en/dialog?storelocation=1']; } /** diff --git a/tests/Controller/ScanControllerTest.php b/tests/Controller/ScanControllerTest.php index 5226e69b..98992e09 100644 --- a/tests/Controller/ScanControllerTest.php +++ b/tests/Controller/ScanControllerTest.php @@ -1,4 +1,7 @@ . */ - namespace App\Tests\Controller; use Symfony\Bundle\FrameworkBundle\KernelBrowser; @@ -49,4 +51,4 @@ class ScanControllerTest extends WebTestCase $this->client->request('GET', '/scan/part/1'); $this->assertResponseRedirects('/en/part/1'); } -} \ No newline at end of file +} diff --git a/tests/Services/InfoProviderSystem/DTOs/FileDTOTest.php b/tests/Services/InfoProviderSystem/DTOs/FileDTOTest.php index 8ec454e7..f6e145f9 100644 --- a/tests/Services/InfoProviderSystem/DTOs/FileDTOTest.php +++ b/tests/Services/InfoProviderSystem/DTOs/FileDTOTest.php @@ -1,4 +1,7 @@ . */ - namespace App\Tests\Services\InfoProviderSystem\DTOs; use App\Services\InfoProviderSystem\DTOs\FileDTO; @@ -27,18 +29,15 @@ class FileDTOTest extends TestCase { - public static function escapingDataProvider(): array + public static function escapingDataProvider(): \Iterator { - return [ - //Normal URLs must be unchanged, even if they contain special characters - ["https://localhost:8000/en/part/1335/edit#attachments", "https://localhost:8000/en/part/1335/edit#attachments"], - ["https://localhost:8000/en/part/1335/edit?test=%20%20&sfee_aswer=test-223!*()", "https://localhost:8000/en/part/1335/edit?test=%20%20&sfee_aswer=test-223!*()"], - - //Remaining URL unsafe characters must be escaped - ["test%5Ese", "test^se"], - ["test%20se", "test se"], - ["test%7Cse", "test|se"], - ]; + //Normal URLs must be unchanged, even if they contain special characters + yield ["https://localhost:8000/en/part/1335/edit#attachments", "https://localhost:8000/en/part/1335/edit#attachments"]; + yield ["https://localhost:8000/en/part/1335/edit?test=%20%20&sfee_aswer=test-223!*()", "https://localhost:8000/en/part/1335/edit?test=%20%20&sfee_aswer=test-223!*()"]; + //Remaining URL unsafe characters must be escaped + yield ["test%5Ese", "test^se"]; + yield ["test%20se", "test se"]; + yield ["test%7Cse", "test|se"]; } /**