-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from he4rt/v2/test/meeting-domain-tests
daniel, não apaga as parada que tão certa denovo!! kkkj
- Loading branch information
Showing
8 changed files
with
311 additions
and
1 deletion.
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,53 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Meeting\Domain\Actions; | ||
|
||
use Heart\Meeting\Domain\Actions\CreateMeeting; | ||
use Heart\Meeting\Domain\DTO\NewMeetingDTO; | ||
use Heart\Meeting\Domain\Entities\MeetingEntity; | ||
use Heart\Meeting\Domain\Repositories\MeetingRepository; | ||
use Mockery as m; | ||
use Mockery\MockInterface; | ||
use Tests\TestCase; | ||
use Tests\Unit\Meeting\MeetingProviderTrait; | ||
|
||
class CreateMeetingTest extends TestCase | ||
{ | ||
use MeetingProviderTrait; | ||
private MockInterface $meetingTypeRepositoryStub; | ||
|
||
private MeetingEntity $meetingEntity; | ||
|
||
private NewMeetingDTO $payloadDTO; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->meetingTypeRepositoryStub = m::mock(MeetingRepository::class); | ||
$this->meetingEntity = $this->validMeetingEntity(); | ||
$this->payloadDTO = NewMeetingDTO::make( | ||
'discord', | ||
'canhassi', | ||
$this->meetingEntity->meetingTypeId | ||
); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
m::close(); | ||
} | ||
|
||
public function testCreateMeeting(): void | ||
{ | ||
$this->meetingTypeRepositoryStub | ||
->shouldReceive('create') | ||
->with($this->payloadDTO, $this->meetingEntity->adminId) | ||
->once() | ||
->andReturn($this->meetingEntity); | ||
|
||
$test = new CreateMeeting($this->meetingTypeRepositoryStub); | ||
|
||
$test->handle($this->payloadDTO, $this->meetingEntity->adminId); | ||
} | ||
} |
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,64 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Meeting\Domain\Actions; | ||
|
||
use Heart\Meeting\Domain\Actions\FindMeetingType; | ||
use Heart\Meeting\Domain\Entities\MeetingTypeEntity; | ||
use Heart\Meeting\Domain\Exceptions\MeetingException; | ||
use Heart\Meeting\Domain\Repositories\MeetingTypeRepository; | ||
use Mockery as m; | ||
use Mockery\MockInterface; | ||
use Tests\TestCase; | ||
use Tests\Unit\Meeting\MeetingTypeProviderTrait; | ||
|
||
class FindMeetingTypeTest extends TestCase | ||
{ | ||
use MeetingTypeProviderTrait; | ||
private MockInterface $meetingTypeRepositoryStub; | ||
|
||
private MeetingTypeEntity $meetingTypeEntity; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->meetingTypeRepositoryStub = m::mock(MeetingTypeRepository::class); | ||
$this->meetingEntity = $this->validMeetingTypeEntity(); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
m::close(); | ||
} | ||
|
||
public function testMeetingTypeIsNotFound(): void | ||
{ | ||
$this->expectException(MeetingException::class); | ||
|
||
$this->meetingTypeRepositoryStub | ||
->shouldReceive('findById') | ||
->with(12) | ||
->once() | ||
->andReturn(null); | ||
|
||
$test = new FindMeetingType($this->meetingTypeRepositoryStub); | ||
|
||
$test->handle(12); | ||
} | ||
|
||
/** | ||
* @throws MeetingException | ||
*/ | ||
public function testFindMeetingTypeSuccess(): void | ||
{ | ||
$this->meetingTypeRepositoryStub | ||
->shouldReceive('findById') | ||
->with(2) | ||
->once() | ||
->andReturn($this->meetingEntity); | ||
|
||
$test = new FindMeetingType($this->meetingTypeRepositoryStub); | ||
|
||
$test->handle(2); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Meeting\Domain\Actions; | ||
|
||
use Heart\Meeting\Domain\Actions\FinishMeeting; | ||
use Heart\Meeting\Domain\Entities\MeetingEntity; | ||
use Heart\Meeting\Domain\Repositories\MeetingRepository; | ||
use Mockery as m; | ||
use Mockery\MockInterface; | ||
use Tests\TestCase; | ||
use Tests\Unit\Meeting\MeetingProviderTrait; | ||
|
||
class FinishMeetingTest extends TestCase | ||
{ | ||
use MeetingProviderTrait; | ||
private MockInterface $meetingRepositoryStub; | ||
|
||
private MeetingEntity $meetingEntity; | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->meetingRepositoryStub = m::mock(MeetingRepository::class); | ||
$this->meetingEntity = $this->validMeetingEntity(); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
m::close(); | ||
} | ||
|
||
public function testFinishMeeting(): void | ||
{ | ||
$this->meetingRepositoryStub | ||
->shouldReceive('endMeeting') | ||
->with($this->meetingEntity->id) | ||
->once() | ||
->andReturn($this->meetingEntity); | ||
|
||
$test = new FinishMeeting($this->meetingRepositoryStub); | ||
|
||
$test->handle($this->meetingEntity->id); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/Unit/Meeting/Domain/Actions/PaginateMeetingsTest.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,50 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Meeting\Domain\Actions; | ||
|
||
use Heart\Meeting\Domain\Actions\PaginateMeetings; | ||
use Heart\Meeting\Domain\Entities\MeetingEntity; | ||
use Heart\Meeting\Domain\Repositories\MeetingRepository; | ||
use Heart\Provider\Domain\Enums\ProviderEnum; | ||
use Heart\Shared\Domain\Paginator; | ||
use Mockery\MockInterface; | ||
use Mockery as m; | ||
use Tests\TestCase; | ||
use Tests\Unit\Meeting\MeetingProviderTrait; | ||
|
||
class PaginateMeetingsTest extends TestCase | ||
{ | ||
use MeetingProviderTrait; | ||
private MockInterface $meetingRepositoryStub; | ||
|
||
private MeetingEntity $meetingEntity; | ||
|
||
private Paginator $paginatorStub; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->meetingRepositoryStub = m::mock(MeetingRepository::class); | ||
$this->meetingEntity = $this->validMeetingEntity(); | ||
$this->paginatorStub = m::mock(Paginator::class); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
m::close(); | ||
} | ||
|
||
public function testPaginateMeetings(): void | ||
{ | ||
$this->meetingRepositoryStub | ||
->shouldReceive('paginate') | ||
->with(['meetingType']) | ||
->once() | ||
->andReturn($this->paginatorStub); | ||
|
||
$test = new PaginateMeetings($this->meetingRepositoryStub); | ||
|
||
$test->handle(ProviderEnum::Discord); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
tests/Unit/Meeting/Domain/Actions/PersistAttendMeetingTest.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,47 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Meeting\Domain\Actions; | ||
|
||
use Heart\Meeting\Domain\Actions\PersistAttendMeeting; | ||
use Heart\Meeting\Domain\DTO\NewMeetingDTO; | ||
use Heart\Meeting\Domain\Entities\MeetingEntity; | ||
use Heart\Meeting\Domain\Repositories\MeetingRepository; | ||
use Mockery\MockInterface; | ||
use Mockery as m; | ||
use Tests\TestCase; | ||
use Tests\Unit\Meeting\MeetingProviderTrait; | ||
|
||
class PersistAttendMeetingTest extends TestCase | ||
{ | ||
use MeetingProviderTrait; | ||
private MockInterface $meetingTypeRepositoryStub; | ||
|
||
private MeetingEntity $meetingEntity; | ||
|
||
private NewMeetingDTO $payloadDTO; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->meetingTypeRepositoryStub = m::mock(MeetingRepository::class); | ||
$this->meetingEntity = $this->validMeetingEntity(); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
m::close(); | ||
} | ||
|
||
public function testPersistAttendMeeting(): void | ||
{ | ||
$this->meetingTypeRepositoryStub | ||
->shouldReceive('attendMeeting') | ||
->with($this->meetingEntity->id, 12) | ||
->once(); | ||
|
||
$test = new PersistAttendMeeting($this->meetingTypeRepositoryStub); | ||
|
||
$test->handle($this->meetingEntity->id, 12); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Meeting; | ||
|
||
use Carbon\Carbon; | ||
use Heart\Meeting\Domain\Entities\MeetingEntity; | ||
|
||
trait MeetingProviderTrait | ||
{ | ||
public function validMeetingPayload(array $fields = []): array | ||
{ | ||
return [ | ||
'id' => 12, | ||
'content' => null, | ||
'meeting_type_id' => 12, | ||
'admin_id' => "12", | ||
'starts_at' => $time = Carbon::now(), | ||
'ends_at' => $time->addMinutes(12), | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now() | ||
]; | ||
} | ||
|
||
public function validMeetingEntity(): MeetingEntity | ||
{ | ||
return MeetingEntity::make($this->validMeetingPayload()); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Meeting; | ||
|
||
use Carbon\Carbon; | ||
use Heart\Meeting\Domain\Entities\MeetingTypeEntity; | ||
|
||
trait MeetingTypeProviderTrait | ||
{ | ||
public function validMeetingPayload(array $fields = []): array | ||
{ | ||
return [ | ||
'id' => 12, | ||
'name' => 'canhassi', | ||
'week_day' => 1, | ||
'start_at' => Carbon::now() | ||
]; | ||
} | ||
|
||
public function validMeetingTypeEntity(): MeetingTypeEntity | ||
{ | ||
return MeetingTypeEntity::make($this->validMeetingPayload()); | ||
} | ||
} |