Skip to content

Commit

Permalink
Fix whoopsies
Browse files Browse the repository at this point in the history
  • Loading branch information
Allypost committed Dec 5, 2019
1 parent 4d06370 commit 08058f5
Showing 1 changed file with 68 additions and 80 deletions.
148 changes: 68 additions & 80 deletions Tests/Acceptance/DoctrineClientManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}

0 comments on commit 08058f5

Please sign in to comment.