-
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.
First iteration of SendProposal feature
- Loading branch information
1 parent
90059a2
commit 5bb4ce2
Showing
5 changed files
with
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace App\ForSendProposals\SendProposal; | ||
|
||
|
||
final readonly class SendProposal | ||
{ | ||
public function __construct( | ||
public string $title, | ||
public string $description, | ||
public string $name, | ||
public string $email, | ||
public string $type, | ||
public bool $sponsored, | ||
public string $location | ||
) | ||
{ | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace App\ForSendProposals\SendProposal; | ||
|
||
|
||
class SendProposalHandler | ||
{ | ||
public function __invoke(SendProposal $command): SendProposalResponse | ||
{ | ||
throw new \RuntimeException('Implement __invoke() method.'); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/ForSendProposals/SendProposal/SendProposalResponse.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,16 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace App\ForSendProposals\SendProposal; | ||
|
||
|
||
final readonly class SendProposalResponse | ||
{ | ||
public function __construct( | ||
public bool $success, | ||
public string $id, | ||
public string $title) | ||
{ | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace App\Tests\ForSendProposals\SendProposal; | ||
|
||
class PayloadExample | ||
{ | ||
public static function wellFormedWithTitle(string $title): array | ||
{ | ||
return [ | ||
'title' => $title, | ||
'description' => 'A description or abstract of the proposal', | ||
'author' => 'Fran Iglesias', | ||
'email' => 'fran.iglesias@example.com', | ||
'type' => 'talk', | ||
'sponsored' => true, | ||
'location' => 'Vigo, Galicia', | ||
]; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
tests/ForSendProposals/SendProposal/SendProposalControllerTest.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,67 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace App\Tests\ForSendProposals\SendProposal; | ||
|
||
use App\ForSendProposals\SendProposal\SendProposal; | ||
use App\ForSendProposals\SendProposal\SendProposalController; | ||
use App\ForSendProposals\SendProposal\SendProposalHandler; | ||
use App\ForSendProposals\SendProposal\SendProposalResponse; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use function PHPUnit\Framework\assertEquals; | ||
use function PHPUnit\Framework\assertStringContainsString; | ||
|
||
final class SendProposalControllerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function should_accept_well_formed_proposal(): void | ||
{ | ||
$payload = PayloadExample::wellFormedWithTitle('Proposal Title'); | ||
|
||
$request = Request::create( | ||
'/api/proposals', | ||
'POST', | ||
[], | ||
[], | ||
[], | ||
['CONTENT-TYPE' => 'json/application'], | ||
json_encode($payload) | ||
); | ||
$handler = $this->createMock(SendProposalHandler::class); | ||
|
||
$command = new SendProposal( | ||
'Proposal Title', | ||
'A description or abstract of the proposal', | ||
'Fran Iglesias', | ||
'fran.iglesias@example.com', | ||
'talk', | ||
true, | ||
'Vigo, Galicia', | ||
); | ||
|
||
$expected = new SendProposalResponse( | ||
true, | ||
'proposal-id', | ||
'Proposal Title' | ||
); | ||
|
||
$handler | ||
->method('__invoke') | ||
->with($command) | ||
->willReturn($expected); | ||
|
||
$controller = new SendProposalController($handler); | ||
$response = ($controller)($request); | ||
|
||
assertEquals(202, $response->getStatusCode()); | ||
assertEquals('https://localhost/api/proposals/proposal-id', $response->headers->get("Location")); | ||
|
||
$content = json_decode($response->getContent(), true); | ||
assertStringContainsString( | ||
'Your proposal titled "Proposal Title" was registered.', | ||
$content['message'] | ||
); | ||
} | ||
} |