Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpcbf test/AppTest/Service #2430

Merged
merged 7 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Log\LoggerInterface;
use DateInterval;

class ActorCodeServiceTest extends TestCase
{
Expand All @@ -32,11 +33,11 @@ class ActorCodeServiceTest extends TestCase

public function setUp(): void
{
$this->codeValidatorProphecy = $this->prophesize(CodeValidationStrategyInterface::class);
$this->lpaServiceProphecy = $this->prophesize(LpaService::class);
$this->codeValidatorProphecy = $this->prophesize(CodeValidationStrategyInterface::class);
$this->lpaServiceProphecy = $this->prophesize(LpaService::class);
$this->userLpaActorMapInterfaceProphecy = $this->prophesize(UserLpaActorMapInterface::class);
$this->loggerProphecy = $this->prophesize(LoggerInterface::class);
$this->resolveActorProphecy = $this->prophesize(ResolveActor::class);
$this->loggerProphecy = $this->prophesize(LoggerInterface::class);
$this->resolveActorProphecy = $this->prophesize(ResolveActor::class);
}

/** @test */
Expand Down Expand Up @@ -97,13 +98,13 @@ public function confirmation_succeeds_with_valid_details_ttl_removed(): void

$mapResults = [
[
'Id' => 'token-3',
'SiriusUid' => 'test-uid',
'ActorId' => 3,
'ActivateBy' => (new DateTime('now'))->add(new \DateInterval('P1Y'))->getTimeStamp(),
'Added' => new DateTime('now'),
'ActivationCode' => 'test-code'
]
'Id' => 'token-3',
'SiriusUid' => 'test-uid',
'ActorId' => 3,
'ActivateBy' => (new DateTime('now'))->add(new DateInterval('P1Y'))->getTimeStamp(),
'Added' => new DateTime('now'),
'ActivationCode' => 'test-code',
],
];

$this->userLpaActorMapInterfaceProphecy->getByUserId('test-user')->willReturn($mapResults)->shouldBeCalled();
Expand Down Expand Up @@ -172,9 +173,9 @@ public function successful_validation(): void
/** @test */
public function validation_fails(): void
{
$testCode = 'test-code';
$testUid = 'test-uid';
$testDob = 'test-dob';
$testCode = 'test-code';
$testUid = 'test-uid';
$testDob = 'test-dob';

$this->codeValidatorProphecy->validateCode($testCode, $testUid, $testDob)
->willThrow(new ActorCodeValidationException())
Expand All @@ -199,10 +200,10 @@ private function getActorCodeService(): ActorCodeService

private function initValidParameterSet(): array
{
$testCode = 'test-code';
$testUid = 'test-uid';
$testDob = 'test-dob';
$testActorId = 1;
$testCode = 'test-code';
$testUid = 'test-uid';
$testDob = 'test-dob';
$testActorId = 1;
$this->testActorUid = '123456789012';

$mockLpa = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Log\LoggerInterface;
use DateTime;
use Exception;

class DynamoCodeValidationStrategyTest extends TestCase
{
Expand All @@ -28,9 +30,9 @@ class DynamoCodeValidationStrategyTest extends TestCase
public function initDependencies(): void
{
$this->actorCodeRepositoryProphecy = $this->prophesize(ActorCodesInterface::class);
$this->lpaServiceProphecy = $this->prophesize(LpaService::class);
$this->loggerProphecy = $this->prophesize(LoggerInterface::class);
$this->resolveActorProphecy = $this->prophesize(ResolveActor::class);
$this->lpaServiceProphecy = $this->prophesize(LpaService::class);
$this->loggerProphecy = $this->prophesize(LoggerInterface::class);
$this->resolveActorProphecy = $this->prophesize(ResolveActor::class);
}

/** @test */
Expand All @@ -44,15 +46,15 @@ public function it_will_validate_a_code(): void
[
'Active' => true,
'SiriusUid' => 'lpa-uid',
'ActorLpaId' => '123456789'
'ActorLpaId' => '123456789',
]
);

$lpa = new Lpa(
[
'uId' => 'lpa-uid'
'uId' => 'lpa-uid',
],
new \DateTime('now')
new DateTime('now')
);

$this->lpaServiceProphecy
Expand All @@ -64,8 +66,8 @@ public function it_will_validate_a_code(): void
[
'details' => [
'uId' => 123456789,
'dob' => 'actor-dob'
]
'dob' => 'actor-dob',
],
]
);

Expand Down Expand Up @@ -106,7 +108,7 @@ public function it_wont_validate_an_expired_code(): void
->get('actor-code')
->willReturn(
[
'Active' => false
'Active' => false,
]
);

Expand All @@ -132,7 +134,7 @@ public function it_wont_validate_a_mismatched_lpa_uid(): void
[
'Active' => true,
'SiriusUid' => 'different-lpa-uid',
'ActorLpaId' => 'actor-lpa-id'
'ActorLpaId' => 'actor-lpa-id',
]
);

Expand All @@ -158,7 +160,7 @@ public function it_wont_validate_a_code_when_lpa_not_found(): void
[
'Active' => true,
'SiriusUid' => 'lpa-uid',
'ActorLpaId' => 'actor-lpa-id'
'ActorLpaId' => 'actor-lpa-id',
]
);

Expand Down Expand Up @@ -188,15 +190,15 @@ public function it_wont_validate_a_code_with_a_mismatched_actor(): void
[
'Active' => true,
'SiriusUid' => 'lpa-uid',
'ActorLpaId' => '123456789'
'ActorLpaId' => '123456789',
]
);

$lpa = new Lpa(
[
'uId' => 'lpa-uid'
'uId' => 'lpa-uid',
],
new \DateTime('now')
new DateTime('now')
);

$this->lpaServiceProphecy
Expand Down Expand Up @@ -228,15 +230,15 @@ public function it_wont_validate_a_code_with_a_bad_dob(): void
[
'Active' => true,
'SiriusUid' => 'lpa-uid',
'ActorLpaId' => '123456789'
'ActorLpaId' => '123456789',
]
);

$lpa = new Lpa(
[
'uId' => 'lpa-uid'
'uId' => 'lpa-uid',
],
new \DateTime('now')
new DateTime('now')
);

$this->lpaServiceProphecy
Expand All @@ -248,8 +250,8 @@ public function it_wont_validate_a_code_with_a_bad_dob(): void
[
'details' => [
'uId' => 'actor-uid',
'dob' => 'different-dob'
]
'dob' => 'different-dob',
],
]
);

Expand Down Expand Up @@ -290,7 +292,7 @@ public function it_will_handle_an_exception_when_flagging_a_code_as_used(): void

$this->actorCodeRepositoryProphecy
->flagCodeAsUsed('actor-code')
->willThrow(new \Exception());
->willThrow(new Exception());

$strategy = new DynamoCodeValidationStrategy(
$this->actorCodeRepositoryProphecy->reveal(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Container\ContainerInterface;
use Psr\Http\Client\ClientInterface;
use Exception;

class ClientFactoryTest extends TestCase
{
Expand All @@ -25,11 +26,11 @@ public function can_create_an_instance_of_a_client(): void
->willReturn(
[
'sirius_api' => [
'endpoint' => 'test_endpoint'
'endpoint' => 'test_endpoint',
],
'aws' => [
'region' => 'test_region',
],
'aws' => [
'region' => 'test_region'
]
]
);

Expand All @@ -56,14 +57,14 @@ public function throws_exception_when_missing_sirius_api_configuration(): void
->willReturn(
[
'aws' => [
'region' => 'test_region'
]
'region' => 'test_region',
],
]
);

$factory = new ClientFactory();

$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->expectExceptionMessage('Sirius API configuration not present');
$factory($containerProphecy->reveal());
}
Expand All @@ -76,14 +77,14 @@ public function throws_exception_when_missing_aws_configuration(): void
->willReturn(
[
'sirius_api' => [
'endpoint' => 'test_endpoint'
'endpoint' => 'test_endpoint',
],
]
);

$factory = new ClientFactory();

$this->expectException(\Exception::class);
$this->expectException(Exception::class);
$this->expectExceptionMessage('AWS configuration not present');
$factory($containerProphecy->reveal());
}
Expand Down
22 changes: 12 additions & 10 deletions service-api/app/test/AppTest/Service/ApiClient/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Exception;

class ClientTest extends TestCase
{
Expand Down Expand Up @@ -314,7 +315,7 @@ public function client_throws_error_with_delete_request(): void
/** @test */
public function sets_appropriate_request_headers_for_request(): void
{
$this->apiClient->sendRequest(Argument::that(function($request) {
$this->apiClient->sendRequest(Argument::that(function ($request) {
$this->assertInstanceOf(RequestInterface::class, $request);

$headers = $request->getHeaders();
Expand Down Expand Up @@ -358,46 +359,47 @@ public function gracefully_handles_malformed_response_data(): void

try {
$data = $client->httpGet('/simple_get');
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertInstanceOf(ApiException::class, $e);
}

try {
$data = $client->httpPost('/simple_post', []);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertInstanceOf(ApiException::class, $e);
}

try {
$data = $client->httpPut('/simple_put', []);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertInstanceOf(ApiException::class, $e);
}

try {
$data = $client->httpPatch('/simple_patch', []);
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertInstanceOf(ApiException::class, $e);
}

try {
$data = $client->httpDelete('/simple_delete');
} catch (\Exception $e) {
} catch (Exception $e) {
$this->assertInstanceOf(ApiException::class, $e);
}
}

/**
* Provides expected valid response codes that we know our methods should handle.
*
* @return array
*/
public function validStatusCodes(): array
{
return [
[ StatusCodeInterface::STATUS_OK ],
[ StatusCodeInterface::STATUS_CREATED],
[ StatusCodeInterface::STATUS_ACCEPTED],
[ StatusCodeInterface::STATUS_NO_CONTENT],
[StatusCodeInterface::STATUS_OK],
[StatusCodeInterface::STATUS_CREATED],
[StatusCodeInterface::STATUS_ACCEPTED],
[StatusCodeInterface::STATUS_NO_CONTENT],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ class DynamoDbClientFactoryTest extends TestCase
use ProphecyTrait;

/** @test */
public function it_creates_a_dbclient() :void
public function it_creates_a_dbclient(): void
{
$containerProphecy = $this->prophesize(ContainerInterface::class);

// Use a real Aws\Sdk to sense check the method.
$containerProphecy->get(Sdk::class)
->willReturn(new Sdk([
'region' => 'eu-west-1',
'version' => 'latest',
'region' => 'eu-west-1',
'version' => 'latest',
]));

//---

$factory = new DynamoDbClientFactory();
$client = $factory($containerProphecy->reveal());
$client = $factory($containerProphecy->reveal());

$this->assertInstanceOf(DynamoDbClient::class, $client);
}
Expand Down
4 changes: 2 additions & 2 deletions service-api/app/test/AppTest/Service/Aws/SdkFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public function can_instantiate(): void
$containerProphecy = $this->prophesize(ContainerInterface::class);

$containerProphecy->get('config')->willReturn([
'aws' => []
'aws' => [],
]);

$factory = new SdkFactory();
$repo = $factory($containerProphecy->reveal());
$repo = $factory($containerProphecy->reveal());
$this->assertInstanceOf(Sdk::class, $repo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Container\ContainerInterface;
use InvalidArgumentException;

class PhpDiModifiableContainerTest extends TestCase
{
Expand All @@ -19,7 +20,7 @@ public function it_only_acts_on_a_phpdi_container(): void
{
$containerProphecy = $this->prophesize(ContainerInterface::class);

$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$di = new PhpDiModifiableContainer($containerProphecy->reveal());
}

Expand Down
Loading
Loading