introduced PostId and PostStatus and changed naming from Storage to Persistence

This commit is contained in:
Dominik Liebler
2018-06-14 18:28:40 +02:00
parent 2ab82dbfbf
commit 6c726d66b7
18 changed files with 334 additions and 743 deletions

View File

@@ -2,7 +2,9 @@
namespace DesignPatterns\More\Repository\Tests;
use DesignPatterns\More\Repository\MemoryStorage;
use DesignPatterns\More\Repository\Domain\PostId;
use DesignPatterns\More\Repository\Domain\PostStatus;
use DesignPatterns\More\Repository\InMemoryPersistence;
use DesignPatterns\More\Repository\Domain\Post;
use DesignPatterns\More\Repository\PostRepository;
use PHPUnit\Framework\TestCase;
@@ -16,12 +18,12 @@ class PostRepositoryTest extends TestCase
protected function setUp()
{
$this->repository = new PostRepository(new MemoryStorage());
$this->repository = new PostRepository(new InMemoryPersistence());
}
public function testCanGenerateId()
{
$this->assertEquals(1, $this->repository->generateId());
$this->assertEquals(1, $this->repository->generateId()->toInt());
}
/**
@@ -30,7 +32,7 @@ class PostRepositoryTest extends TestCase
*/
public function testThrowsExceptionWhenTryingToFindPostWhichDoesNotExist()
{
$this->repository->findById(42);
$this->repository->findById(PostId::fromInt(42));
}
public function testCanPersistPostDraft()
@@ -39,6 +41,9 @@ class PostRepositoryTest extends TestCase
$post = Post::draft($postId, 'Repository Pattern', 'Design Patterns PHP');
$this->repository->save($post);
$this->repository->findById($postId);
$this->assertEquals($postId, $this->repository->findById($postId)->getId());
$this->assertEquals(PostStatus::STATE_DRAFT, $post->getStatus()->toString());
}
}