Skip to content

Commit

Permalink
AUT-3504: code style
Browse files Browse the repository at this point in the history
  • Loading branch information
halaz-lazlo committed Oct 28, 2024
1 parent 8a90370 commit 4c14b97
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Suite/Api/AC/EndPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class EndPoints
{
private $apiBaseUrl;
private string $apiBaseUrl;

public function __construct(string $apiBaseUrl)
{
Expand Down
16 changes: 6 additions & 10 deletions src/Suite/Api/AC/Program.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,32 @@

class Program
{
/* @var Client */
private $apiClient;

/* @var EndPoints */
private $endPoints;

private Client $apiClient;
private EndPoints $endPoints;

public function __construct(Client $apiClient, EndPoints $endPoints)
{
$this->apiClient = $apiClient;
$this->endPoints = $endPoints;
}

public function programCallbackWithUserId(int $customerId, string $triggerId, int $userId)
public function programCallbackWithUserId(int $customerId, string $triggerId, int $userId): void
{
$this->sendRequest(
$this->endPoints->programCallbackDoneUrl($customerId, $triggerId),
$this->createPostData($userId, null)
);
}

public function programCallbackWithListId(int $customerId, string $triggerId, int $listId)
public function programCallbackWithListId(int $customerId, string $triggerId, int $listId): void
{
$this->sendRequest(
$this->endPoints->programCallbackDoneUrl($customerId, $triggerId),
$this->createPostData(null, $listId)
);
}

public function programCallbackCancel(int $customerId, string $triggerId)
public function programCallbackCancel(int $customerId, string $triggerId): void
{
$this->sendRequest(
$this->endPoints->programCallbackCancelUrl($customerId, $triggerId),
Expand Down Expand Up @@ -78,7 +74,7 @@ public function programBatchCallbackDone(int $customerId, array $triggers): void
);
}

private function sendRequest(string $url, $postData)
private function sendRequest(string $url, $postData): void
{
try {
$this->apiClient->post($url, $postData);
Expand Down
16 changes: 7 additions & 9 deletions test/helper/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ class TestCase extends \PHPUnit\Framework\TestCase
const API_FAILURE_TEXT = 'FAIL';
const API_FAILURE_CODE = 9999;

protected $customerId = 555;
protected $campaignId = 123;
protected Client|MockObject $apiClient;

/** @var EndPoints */
protected $endPoints;

/** @var Client|MockObject */
protected $apiClient;
protected int $customerId = 555;
protected int $campaignId = 123;

protected function expectApiFailure(string $method = 'get')
{
$this->apiClient->expects($this->once())->method($method)
->will($this->throwException(new Error()));
$this->apiClient
->expects($this->once())
->method($method)
->willThrowException(new Error());
}

protected function apiSuccess($data = [])
Expand Down
31 changes: 14 additions & 17 deletions test/unit/Suite/Api/AC/ProgramTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@

class ProgramTest extends TestCase
{
const TRIGGER_ID = 'trigger_id';
const USER_ID = 1;
const LIST_ID = 2;
private const TRIGGER_ID = 'trigger_id';
private const USER_ID = 1;
private const LIST_ID = 2;

/** @var EndPoints */
protected $endPoints;

/** @var Program */
private $program;
private EndPoints $endPoints;
private Program $program;

protected function setUp(): void
{
Expand All @@ -30,7 +27,7 @@ protected function setUp(): void
/**
* @test
*/
public function programCallbackWithUserId_Perfect_Perfect()
public function programCallbackWithUserId_CallEndpointWithCorrectParameters(): void
{
$this->expectSuccessfulDoneRequest(
[
Expand All @@ -45,7 +42,7 @@ public function programCallbackWithUserId_Perfect_Perfect()
/**
* @test
*/
public function programCallbackWithUserId_postThrowsError_ThrowsRequestFailException()
public function programCallbackWithUserId_postThrowsError_ThrowsRequestFailException(): void
{
$this->expectException(RequestFailed::class);
$this->expectApiCallFailure();
Expand All @@ -56,7 +53,7 @@ public function programCallbackWithUserId_postThrowsError_ThrowsRequestFailExcep
/**
* @test
*/
public function programCallbackWithListId_Perfect_Perfect()
public function programCallbackWithListId_CallEndpointWithCorrectParameters(): void
{
$this->expectSuccessfulDoneRequest(
[
Expand All @@ -71,7 +68,7 @@ public function programCallbackWithListId_Perfect_Perfect()
/**
* @test
*/
public function programCallbackWithListId_postThrowsError_ThrowsRequestFailException()
public function programCallbackWithListId_postThrowsError_ThrowsRequestFailException(): void
{
$this->expectException(RequestFailed::class);
$this->expectApiCallFailure();
Expand All @@ -82,7 +79,7 @@ public function programCallbackWithListId_postThrowsError_ThrowsRequestFailExcep
/**
* @test
*/
public function programBatchCallbackDone_CalledWithCorrectParameters()
public function programBatchCallbackDone_CalledWithCorrectParameters(): void
{
$postParams = [
'this' => 'is',
Expand All @@ -105,14 +102,14 @@ public function programBatchCallbackDone_CalledWithCorrectParameters()
/**
* @test
*/
public function programCallbackCancel_Perfect_Perfect()
public function programCallbackCancel_Perfect_Perfect(): void
{
$this->expectSuccessfulCancelRequest();

$this->program->programCallbackCancel($this->customerId, self::TRIGGER_ID);
}

private function expectSuccessfulDoneRequest(array $postParams)
private function expectSuccessfulDoneRequest(array $postParams): void
{
$this->apiClient
->expects($this->once())
Expand All @@ -124,7 +121,7 @@ private function expectSuccessfulDoneRequest(array $postParams)
->willReturn($this->apiSuccess());
}

private function expectSuccessfulCancelRequest()
private function expectSuccessfulCancelRequest(): void
{
$this->apiClient
->expects($this->once())
Expand All @@ -139,7 +136,7 @@ private function expectSuccessfulCancelRequest()
->willReturn($this->apiSuccess());
}

private function expectApiCallFailure()
private function expectApiCallFailure(): void
{
$this->apiClient
->expects($this->any())
Expand Down

0 comments on commit 4c14b97

Please sign in to comment.