From 60d8e51c77d5c92c184f0cd166e354a19b5b5acf Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Fri, 1 Nov 2024 14:14:18 +0330 Subject: [PATCH] simplify tests --- tests/Grant/DeviceCodeGrantTest.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Grant/DeviceCodeGrantTest.php b/tests/Grant/DeviceCodeGrantTest.php index 5c78885b4..b3331936c 100644 --- a/tests/Grant/DeviceCodeGrantTest.php +++ b/tests/Grant/DeviceCodeGrantTest.php @@ -350,19 +350,8 @@ public function testRespondToAccessTokenRequest(): void $scope = new ScopeEntity(); $scope->setIdentifier('foo'); - $deviceCodeRepositoryMock = $this->getMockBuilder(DeviceCodeRepositoryInterface::class)->getMock(); - $deviceCodeEntity = new DeviceCodeEntity(); - - $deviceCodeEntity->setUserIdentifier('baz'); - $deviceCodeEntity->setUserCode('123456'); - - $deviceCodeRepositoryMock->method('getDeviceCodeEntityByDeviceCode') - ->with('deviceCodeEntityIdentifier') - ->willReturn($deviceCodeEntity); - $accessTokenEntity = new AccessTokenEntity(); $accessTokenEntity->addScope($scope); - $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); $accessTokenRepositoryMock->method('getNewToken')->willReturn($accessTokenEntity); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); @@ -371,6 +360,17 @@ public function testRespondToAccessTokenRequest(): void $refreshTokenRepositoryMock->method('persistNewRefreshToken')->willReturnSelf(); $refreshTokenRepositoryMock->method('getNewRefreshToken')->willReturn(new RefreshTokenEntity()); + $deviceCodeRepositoryMock = $this->getMockBuilder(DeviceCodeRepositoryInterface::class)->getMock(); + $deviceCodeEntity = new DeviceCodeEntity(); + $deviceCodeEntity->setUserIdentifier('baz'); + $deviceCodeEntity->setIdentifier('deviceCodeEntityIdentifier'); + $deviceCodeEntity->setUserCode('123456'); + $deviceCodeEntity->setExpiryDateTime(new DateTimeImmutable('+1 hour')); + $deviceCodeEntity->setClient($client); + $deviceCodeRepositoryMock->method('getDeviceCodeEntityByDeviceCode') + ->with('deviceCodeEntityIdentifier') + ->willReturn($deviceCodeEntity); + $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeRepositoryMock->method('getScopeEntityByIdentifier')->willReturn($scope); $scopeRepositoryMock->method('finalizeScopes')->willReturnArgument(0);