-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
205d236
commit 0d8047e
Showing
7 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Application\Actions\Application; | ||
|
||
use App\Application\Actions\Action; | ||
use App\Domain\Deployment\DeploymentRepository; | ||
use Psr\Log\LoggerInterface; | ||
|
||
abstract class ApplicationAction extends Action | ||
{ | ||
protected DeploymentRepository $deploymentRepository; | ||
|
||
public function __construct(LoggerInterface $logger, DeploymentRepository $deploymentRepository) | ||
{ | ||
parent::__construct($logger); | ||
$this->deploymentRepository = $deploymentRepository; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Application/Actions/Application/ListApplicationAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Application\Actions\Application; | ||
|
||
use App\Application\Actions\Application\ApplicationAction; | ||
use Psr\Http\Message\ResponseInterface as Response; | ||
|
||
class ListApplicationAction extends ApplicationAction | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function action(): Response | ||
{ | ||
$deployments = $this->deploymentRepository->findApplications(); | ||
$this->logger->info("Applications list was viewed."); | ||
return $this->respondWithData($deployments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/Application/Actions/Application/ListApplicationActionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Tests\Application\Actions\Application; | ||
|
||
use App\Application\Actions\ActionPayload; | ||
use App\Domain\Deployment\Deployment; | ||
use App\Domain\Deployment\DeploymentRepository; | ||
use DI\Container; | ||
use Tests\TestCase; | ||
|
||
class ListApplicationActionTest extends TestCase | ||
{ | ||
public function testAction() | ||
{ | ||
//Given | ||
$app = $this->getAppInstance(); | ||
|
||
/** @var Container $container */ | ||
$container = $app->getContainer(); | ||
$deployment = new Deployment(1, 'bill.gates', 'Frontend', '1.0.0', 'prod', 1); | ||
|
||
$deploymentRepositoryProphecy = $this->prophesize(DeploymentRepository::class); | ||
$deploymentRepositoryProphecy | ||
->findApplications() | ||
->willReturn([$deployment->getApplication()]) | ||
->shouldBeCalledOnce(); | ||
|
||
$container->set(DeploymentRepository::class, $deploymentRepositoryProphecy->reveal()); | ||
|
||
//When | ||
$request = $this->createRequest('GET', '/applications'); | ||
$response = $app->handle($request); | ||
|
||
$payload = (string)$response->getBody(); | ||
$expectedPayload = new ActionPayload(200, [$deployment->getApplication()]); | ||
$serializedPayload = json_encode($expectedPayload, JSON_PRETTY_PRINT); | ||
|
||
//Then | ||
$this->assertEquals($serializedPayload, $payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters