generated from rich-id/bundle-template
-
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
Dumazeau
committed
Jul 15, 2021
1 parent
14bf9dc
commit 64faaa6
Showing
12 changed files
with
465 additions
and
5 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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RichId\TermsModuleBundle\Tests\Domain\Event; | ||
|
||
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig; | ||
use RichCongress\TestSuite\TestCase\TestCase; | ||
use RichId\TermsModuleBundle\Domain\Entity\TermsVersion; | ||
use RichId\TermsModuleBundle\Domain\Event\TermsVersionDeletedEvent; | ||
|
||
/** | ||
* @covers \RichId\TermsModuleBundle\Domain\Event\TermsVersionDeletedEvent | ||
* @TestConfig("kernel") | ||
*/ | ||
final class TermsVersionDeletedEventTest extends TestCase | ||
{ | ||
public function testEvent(): void | ||
{ | ||
$termsVersion = new TermsVersion(); | ||
$event = new TermsVersionDeletedEvent($termsVersion); | ||
|
||
$this->assertSame($termsVersion, $event->getTermsVersion()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/Domain/Exception/AlreadyEnabledTermsVersionExceptionTest.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RichId\TermsModuleBundle\Tests\Domain\Exception; | ||
|
||
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig; | ||
use RichCongress\TestSuite\TestCase\TestCase; | ||
use RichId\TermsModuleBundle\Domain\Entity\TermsVersion; | ||
use RichId\TermsModuleBundle\Domain\Exception\AlreadyEnabledTermsVersionException; | ||
use RichId\TermsModuleBundle\Domain\Exception\TermsModuleException; | ||
|
||
/** | ||
* @covers \RichId\TermsModuleBundle\Domain\Exception\AlreadyEnabledTermsVersionException | ||
* @TestConfig("fixtures") | ||
*/ | ||
final class AlreadyEnabledTermsVersionExceptionTest extends TestCase | ||
{ | ||
public function testException(): void | ||
{ | ||
$termsVersion = $this->getReference(TermsVersion::class, 'v1-terms-1'); | ||
$exception = new AlreadyEnabledTermsVersionException($termsVersion); | ||
|
||
$this->assertInstanceOf(TermsModuleException::class, $exception); | ||
$this->assertSame($termsVersion, $exception->getTermsVersion()); | ||
$this->assertSame('Version 1 of terms terms-1 is already enabled.', $exception->getMessage()); | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RichId\TermsModuleBundle\Tests\Domain\UseCase; | ||
|
||
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig; | ||
use RichCongress\TestSuite\TestCase\TestCase; | ||
use RichId\TermsModuleBundle\Domain\Entity\Terms; | ||
use RichId\TermsModuleBundle\Domain\Entity\TermsVersion; | ||
use RichId\TermsModuleBundle\Domain\Event\TermsVersionEnabledEvent; | ||
use RichId\TermsModuleBundle\Domain\Exception\AlreadyEnabledTermsVersionException; | ||
use RichId\TermsModuleBundle\Domain\UseCase\ActivateTermsVersion; | ||
use RichId\TermsModuleBundle\Tests\Resources\Stubs\EntityManagerStub; | ||
use RichId\TermsModuleBundle\Tests\Resources\Stubs\EventDispatcherStub; | ||
|
||
/** | ||
* @covers \RichId\TermsModuleBundle\Domain\UseCase\ActivateTermsVersion | ||
* @TestConfig("fixtures") | ||
*/ | ||
final class ActivateTermsVersionTest extends TestCase | ||
{ | ||
/** @var ActivateTermsVersion */ | ||
public $useCase; | ||
|
||
/** @var EntityManagerStub */ | ||
public $entityManagerStub; | ||
|
||
/** @var EventDispatcherStub */ | ||
public $eventDispatcherStub; | ||
|
||
public function testUseCaseTermsVersionAlreadyEnabled(): void | ||
{ | ||
$this->expectException(AlreadyEnabledTermsVersionException::class); | ||
$this->expectExceptionMessage('Version 42 of terms my_terms is already enabled.'); | ||
|
||
$terms = new Terms(); | ||
$terms->setSlug('my_terms'); | ||
|
||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setTerms($terms); | ||
$termsVersion->setVersion(42); | ||
$termsVersion->enable(); | ||
|
||
($this->useCase)($termsVersion); | ||
} | ||
|
||
public function testUseCase(): void | ||
{ | ||
$terms = new Terms(); | ||
$terms->setSlug('my_terms'); | ||
|
||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setTerms($terms); | ||
$termsVersion->setVersion(42); | ||
|
||
($this->useCase)($termsVersion); | ||
|
||
$this->assertTrue($termsVersion->isEnabled()); | ||
$this->assertNotNull($termsVersion->getPublicationDate()); | ||
|
||
$this->assertCount(2, $this->entityManagerStub->getPersistedEntities()); | ||
$this->assertCount(1, $this->eventDispatcherStub->getEvents()); | ||
|
||
$event = $this->eventDispatcherStub->getEvents()[0]; | ||
|
||
$this->assertInstanceOf(TermsVersionEnabledEvent::class, $event); | ||
$this->assertSame($termsVersion, $event->getTermsVersion()); | ||
} | ||
} |
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,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RichId\TermsModuleBundle\Tests\Domain\UseCase; | ||
|
||
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig; | ||
use RichCongress\TestSuite\TestCase\TestCase; | ||
use RichId\TermsModuleBundle\Domain\Entity\Terms; | ||
use RichId\TermsModuleBundle\Domain\Entity\TermsVersion; | ||
use RichId\TermsModuleBundle\Domain\Event\TermsVersionCreatedEvent; | ||
use RichId\TermsModuleBundle\Domain\Exception\CannotAddVersionToTermsException; | ||
use RichId\TermsModuleBundle\Domain\UseCase\CreateTermsVersion; | ||
use RichId\TermsModuleBundle\Tests\Resources\Stubs\EntityManagerStub; | ||
use RichId\TermsModuleBundle\Tests\Resources\Stubs\EventDispatcherStub; | ||
|
||
/** | ||
* @covers \RichId\TermsModuleBundle\Domain\UseCase\CreateTermsVersion | ||
* @TestConfig("fixtures") | ||
*/ | ||
final class CreateTermsVersionTest extends TestCase | ||
{ | ||
/** @var CreateTermsVersion */ | ||
public $useCase; | ||
|
||
/** @var EntityManagerStub */ | ||
public $entityManagerStub; | ||
|
||
/** @var EventDispatcherStub */ | ||
public $eventDispatcherStub; | ||
|
||
public function testUseCaseTermsWithoutVersion(): void | ||
{ | ||
$this->expectException(CannotAddVersionToTermsException::class); | ||
$this->expectExceptionMessage('Cannot add new version to the terms my_terms.'); | ||
|
||
$terms = new Terms(); | ||
$terms->setSlug('my_terms'); | ||
|
||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setTerms($terms); | ||
$termsVersion->setVersion(42); | ||
|
||
($this->useCase)($termsVersion); | ||
} | ||
|
||
public function testUseCaseLastVersionNotPublished(): void | ||
{ | ||
$this->expectException(CannotAddVersionToTermsException::class); | ||
$this->expectExceptionMessage('Cannot add new version to the terms my_terms.'); | ||
|
||
$terms = new Terms(); | ||
$terms->setSlug('my_terms'); | ||
|
||
$termsVersion = new TermsVersion(); | ||
$termsVersion->setVersion(42); | ||
$termsVersion->setTerms($terms); | ||
$terms->addVersion($termsVersion); | ||
|
||
($this->useCase)($termsVersion); | ||
} | ||
|
||
public function testUseCase(): void | ||
{ | ||
$terms = $this->getReference(Terms::class, '2'); | ||
|
||
$termsVersion1 = new TermsVersion(); | ||
$termsVersion1->setTitle('Title 1'); | ||
$termsVersion1->setContent('Content 1'); | ||
$termsVersion1->setPublicationDate(new \DateTime('today - 2 days')); | ||
$termsVersion1->setVersion(42); | ||
$termsVersion1->enable(); | ||
$termsVersion1->setTerms($terms); | ||
$terms->addVersion($termsVersion1); | ||
|
||
$termsVersion2 = new TermsVersion(); | ||
$termsVersion2->setTitle('Title 2'); | ||
$termsVersion2->setContent('Content 2'); | ||
$termsVersion2->setPublicationDate(new \DateTime('today - 1 days')); | ||
$termsVersion2->setVersion(43); | ||
$termsVersion2->enable(); | ||
$termsVersion2->setTerms($terms); | ||
$terms->addVersion($termsVersion2); | ||
|
||
$this->getManager()->persist($termsVersion1); | ||
$this->getManager()->persist($termsVersion2); | ||
|
||
($this->useCase)($termsVersion1); | ||
|
||
$this->assertCount(1, $this->entityManagerStub->getPersistedEntities()); | ||
$this->assertCount(1, $this->eventDispatcherStub->getEvents()); | ||
|
||
$event = $this->eventDispatcherStub->getEvents()[0]; | ||
|
||
$this->assertInstanceOf(TermsVersionCreatedEvent::class, $event); | ||
|
||
$newTermsVersion = $event->getTermsVersion(); | ||
|
||
$this->assertInstanceOf(TermsVersion::class, $event->getTermsVersion()); | ||
$this->assertNotNull($newTermsVersion->getId()); | ||
$this->assertSame('Title 1', $newTermsVersion->getTitle()); | ||
$this->assertSame('Content 1', $newTermsVersion->getCOntent()); | ||
$this->assertSame(44, $newTermsVersion->getVersion()); | ||
$this->assertSame($terms, $newTermsVersion->getTerms()); | ||
$this->assertNull($newTermsVersion->getPublicationDate()); | ||
$this->assertFalse($newTermsVersion->isEnabled()); | ||
} | ||
} |
Oops, something went wrong.