From 9a76c24a33f1e936eb927f4fa619a89038e46ba9 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 13 Nov 2024 11:29:35 +0100 Subject: [PATCH] Rector --- rector.php | 2 ++ .../AppendFormFieldElementActionTest.php | 2 +- .../RetrieveFormFieldElementActionTest.php | 2 +- tests/Controller/CRUDControllerTest.php | 30 +++++++++---------- .../ConfigureCRUDControllerListenerTest.php | 4 +-- tests/Menu/Provider/GroupMenuProviderTest.php | 2 +- .../Handler/AclSecurityHandlerTest.php | 4 +-- 7 files changed, 24 insertions(+), 22 deletions(-) diff --git a/rector.php b/rector.php index b6dac16fc2..744632387a 100644 --- a/rector.php +++ b/rector.php @@ -19,6 +19,7 @@ use Rector\Config\RectorConfig; use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector; +use Rector\PHPUnit\CodeQuality\Rector\Class_\NarrowUnusedSetUpDefinedPropertyRector; use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; @@ -40,5 +41,6 @@ $rectorConfig->skip([ ExceptionHandlerTypehintRector::class, PreferPHPUnitThisCallRector::class, + NarrowUnusedSetUpDefinedPropertyRector::class, ]); }; diff --git a/tests/Action/AppendFormFieldElementActionTest.php b/tests/Action/AppendFormFieldElementActionTest.php index f43d6e443f..2e982649ed 100644 --- a/tests/Action/AppendFormFieldElementActionTest.php +++ b/tests/Action/AppendFormFieldElementActionTest.php @@ -101,7 +101,7 @@ public function testAppendFormFieldElementAction(): void $response = ($this->action)($request); static::assertInstanceOf(Response::class, $response); - static::assertSame($response->getContent(), 'block'); + static::assertSame('block', $response->getContent()); } /** diff --git a/tests/Action/RetrieveFormFieldElementActionTest.php b/tests/Action/RetrieveFormFieldElementActionTest.php index 76b191ad3c..28f7b07c0c 100644 --- a/tests/Action/RetrieveFormFieldElementActionTest.php +++ b/tests/Action/RetrieveFormFieldElementActionTest.php @@ -103,7 +103,7 @@ public function testRetrieveFormFieldElementAction(): void $response = ($this->action)($request); static::assertInstanceOf(Response::class, $response); - static::assertSame($response->getContent(), 'block'); + static::assertSame('block', $response->getContent()); } /** diff --git a/tests/Controller/CRUDControllerTest.php b/tests/Controller/CRUDControllerTest.php index 40662be6d9..b6d3191020 100644 --- a/tests/Controller/CRUDControllerTest.php +++ b/tests/Controller/CRUDControllerTest.php @@ -312,7 +312,7 @@ public function testRenderJson1(): void $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request); static::assertInstanceOf(JsonResponse::class, $response); - static::assertSame($response->headers->get('Content-Type'), 'application/json'); + static::assertSame('application/json', $response->headers->get('Content-Type')); static::assertSame(json_encode($data), $response->getContent()); } @@ -324,7 +324,7 @@ public function testRenderJson2(): void $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request); static::assertInstanceOf(JsonResponse::class, $response); - static::assertSame($response->headers->get('Content-Type'), 'application/json'); + static::assertSame('application/json', $response->headers->get('Content-Type')); static::assertSame(json_encode($data), $response->getContent()); } @@ -337,7 +337,7 @@ public function testRenderJsonAjax(): void $response = $this->protectedTestedMethods['renderJson']->invoke($this->controller, $data, 200, [], $this->request); static::assertInstanceOf(JsonResponse::class, $response); - static::assertSame($response->headers->get('Content-Type'), 'application/json'); + static::assertSame('application/json', $response->headers->get('Content-Type')); static::assertSame(json_encode($data), $response->getContent()); } @@ -535,7 +535,7 @@ public function testListActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('list')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->controller->listAction($this->request); } @@ -613,7 +613,7 @@ public function testBatchActionDeleteAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('batchDelete')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->controller->batchActionDelete($this->createMock(ProxyQueryInterface::class)); } @@ -787,7 +787,7 @@ public function testShowActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('show')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->expectException(AccessDeniedException::class); @@ -1003,7 +1003,7 @@ public function testDeleteActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('delete')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->expectException(AccessDeniedException::class); @@ -1591,7 +1591,7 @@ public function testEditActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('edit')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->expectException(AccessDeniedException::class); @@ -2328,7 +2328,7 @@ public function testEditActionWithLockException(): void $this->admin ->method('update') - ->will(static::throwException(new LockException())); + ->willThrowException(new LockException()); $this->admin ->method('toString') @@ -2355,7 +2355,7 @@ public function testCreateActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('create')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->expectException(AccessDeniedException::class); @@ -3052,7 +3052,7 @@ public function testExportActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('export')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->expectException(AccessDeniedException::class); @@ -3122,7 +3122,7 @@ public function testHistoryActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('history')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->expectException(AccessDeniedException::class); $this->controller->historyAction($this->request); @@ -3273,7 +3273,7 @@ public function testAclActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('acl'), static::equalTo($object)) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->expectException(AccessDeniedException::class); @@ -3542,7 +3542,7 @@ public function testHistoryViewRevisionActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('historyViewRevision')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->expectException(AccessDeniedException::class); @@ -3723,7 +3723,7 @@ public function testHistoryCompareRevisionsActionAccessDenied(): void $this->admin->expects(static::once()) ->method('checkAccess') ->with(static::equalTo('historyCompareRevisions')) - ->will(static::throwException(new AccessDeniedException())); + ->willThrowException(new AccessDeniedException()); $this->expectException(AccessDeniedException::class); diff --git a/tests/EventListener/ConfigureCRUDControllerListenerTest.php b/tests/EventListener/ConfigureCRUDControllerListenerTest.php index 1a1bd9df19..19083d7f20 100644 --- a/tests/EventListener/ConfigureCRUDControllerListenerTest.php +++ b/tests/EventListener/ConfigureCRUDControllerListenerTest.php @@ -74,8 +74,8 @@ public function testItConfiguresCRUDController(): void ->method('addGlobal') ->willReturnCallback(static function (string $name) use ($matcher) { match ($matcher->getInvocationCount()) { - 1 => static::assertSame($name, 'admin'), - 2 => static::assertSame($name, 'base_template'), + 1 => static::assertSame('admin', $name), + 2 => static::assertSame('base_template', $name), default => throw new \LogicException('Exactly 2 calls'), }; }); diff --git a/tests/Menu/Provider/GroupMenuProviderTest.php b/tests/Menu/Provider/GroupMenuProviderTest.php index d9d712f698..7a57622709 100644 --- a/tests/Menu/Provider/GroupMenuProviderTest.php +++ b/tests/Menu/Provider/GroupMenuProviderTest.php @@ -112,7 +112,7 @@ public function testGetMenuProviderWithCheckerGrantedGroupRoles(array $adminGrou $extras = $item->getExtras(); static::assertArrayHasKey('translation_domain', $extras); - static::assertSame($extras['translation_domain'], 'SonataAdminBundle'); + static::assertSame('SonataAdminBundle', $extras['translation_domain']); } public function unanimousGrantCheckerMock(string $role): bool diff --git a/tests/Security/Handler/AclSecurityHandlerTest.php b/tests/Security/Handler/AclSecurityHandlerTest.php index 044006ccd0..840c77bc4c 100644 --- a/tests/Security/Handler/AclSecurityHandlerTest.php +++ b/tests/Security/Handler/AclSecurityHandlerTest.php @@ -94,7 +94,7 @@ public function testWithAuthenticationCredentialsNotFoundException(): void $authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class); $authorizationChecker ->method('isGranted') - ->will(static::throwException(new AuthenticationCredentialsNotFoundException('FAIL'))); + ->willThrowException(new AuthenticationCredentialsNotFoundException('FAIL')); $aclProvider = $this->createMock(MutableAclProviderInterface::class); @@ -112,7 +112,7 @@ public function testWithNonAuthenticationCredentialsNotFoundException(): void $authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class); $authorizationChecker ->method('isGranted') - ->will(static::throwException(new \RuntimeException('FAIL'))); + ->willThrowException(new \RuntimeException('FAIL')); $aclProvider = $this->createMock(MutableAclProviderInterface::class);