mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-04 14:07:25 +02:00
introduced PostId and PostStatus and changed naming from Storage to Persistence
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user