From 08058f54d04e0f145dc2afd28b42bc310c0e53cd Mon Sep 17 00:00:00 2001 From: Josip Igrec Date: Tue, 3 Dec 2019 15:36:02 +0100 Subject: [PATCH] Fix whoopsies --- .../Acceptance/DoctrineClientManagerTest.php | 148 ++++++++---------- 1 file changed, 68 insertions(+), 80 deletions(-) diff --git a/Tests/Acceptance/DoctrineClientManagerTest.php b/Tests/Acceptance/DoctrineClientManagerTest.php index 5c23f4f3..c6d181fe 100644 --- a/Tests/Acceptance/DoctrineClientManagerTest.php +++ b/Tests/Acceptance/DoctrineClientManagerTest.php @@ -17,13 +17,13 @@ public function testSimpleDelete(): void { /** @var $em EntityManagerInterface */ $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); - $doctrineAccessTokenManager = new DoctrineClientManager($em); + $doctrineClientManager = new DoctrineClientManager($em); $client = new Client('client', 'secret'); $em->persist($client); $em->flush(); - $doctrineAccessTokenManager->remove($client); + $doctrineClientManager->remove($client); $this->assertNull( $em @@ -40,103 +40,91 @@ public function testClientDeleteCascadesToAccessTokens(): void { /** @var $em EntityManagerInterface */ $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); - $doctrineAccessTokenManager = new DoctrineClientManager($em); + $doctrineClientManager = new DoctrineClientManager($em); $client = new Client('client', 'secret'); $em->persist($client); $em->flush(); - timecop_freeze(new DateTime()); - - try { - $accessToken = new AccessToken('access token', (new DateTime())->modify('+1 day'), $client, $client->getIdentifier(), []); - $em->persist($accessToken); - $em->flush(); - - $doctrineAccessTokenManager->remove($client); - - $this->assertNull( - $em - ->getRepository(Client::class) - ->findOneBy( - [ - 'identifier' => $client->getIdentifier(), - ] - ) - ); - - $this->assertNull( - $em - ->getRepository(AccessToken::class) - ->findOneBy( - [ - 'identifier' => $accessToken->getIdentifier(), - ] - ) - ); - } finally { - timecop_return(); - } + $accessToken = new AccessToken('access token', (new DateTime())->modify('+1 day'), $client, $client->getIdentifier(), []); + $em->persist($accessToken); + $em->flush(); + + $doctrineClientManager->remove($client); + + $this->assertNull( + $em + ->getRepository(Client::class) + ->findOneBy( + [ + 'identifier' => $client->getIdentifier(), + ] + ) + ); + + $this->assertNull( + $em + ->getRepository(AccessToken::class) + ->findOneBy( + [ + 'identifier' => $accessToken->getIdentifier(), + ] + ) + ); } public function testClientDeleteCascadesToAccessTokensAndRefreshTokens(): void { /** @var $em EntityManagerInterface */ $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); - $doctrineAccessTokenManager = new DoctrineClientManager($em); + $doctrineClientManager = new DoctrineClientManager($em); $client = new Client('client', 'secret'); $em->persist($client); $em->flush(); - timecop_freeze(new DateTime()); - - try { - $accessToken = new AccessToken('access token', (new DateTime())->modify('+1 day'), $client, $client->getIdentifier(), []); - $em->persist($accessToken); - $em->flush(); - - $refreshToken = new RefreshToken('refresh token', (new DateTime())->modify('+1 day'), $accessToken); - $em->persist($refreshToken); - $em->flush(); - - $doctrineAccessTokenManager->remove($client); - - $this->assertNull( - $em - ->getRepository(Client::class) - ->findOneBy( - [ - 'identifier' => $client->getIdentifier(), - ] - ) - ); - - $this->assertNull( - $em - ->getRepository(AccessToken::class) - ->findOneBy( - [ - 'identifier' => $accessToken->getIdentifier(), - ] - ) - ); - - $em->clear(); - - /** @var $refreshToken RefreshToken */ - $refreshToken = $em - ->getRepository(RefreshToken::class) + $accessToken = new AccessToken('access token', (new DateTime())->modify('+1 day'), $client, $client->getIdentifier(), []); + $em->persist($accessToken); + $em->flush(); + + $refreshToken = new RefreshToken('refresh token', (new DateTime())->modify('+1 day'), $accessToken); + $em->persist($refreshToken); + $em->flush(); + + $doctrineClientManager->remove($client); + + $this->assertNull( + $em + ->getRepository(Client::class) ->findOneBy( [ - 'identifier' => $refreshToken->getIdentifier(), + 'identifier' => $client->getIdentifier(), ] ) - ; - $this->assertNotNull($refreshToken); - $this->assertNull($refreshToken->getAccessToken()); - } finally { - timecop_return(); - } + ); + + $this->assertNull( + $em + ->getRepository(AccessToken::class) + ->findOneBy( + [ + 'identifier' => $accessToken->getIdentifier(), + ] + ) + ); + + $em->clear(); + + /** @var $refreshToken RefreshToken */ + $refreshToken = $em + ->getRepository(RefreshToken::class) + ->findOneBy( + [ + 'identifier' => $refreshToken->getIdentifier(), + ] + ) + ; + $this->assertNotNull($refreshToken); + $this->assertNull($refreshToken->getAccessToken()); } }