2014-09-27 21:33:31 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Tests\Dao;
|
|
|
|
|
|
|
|
class FavoritesDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
|
|
|
{
|
|
|
|
private $userDaoMock;
|
|
|
|
private $postDaoMock;
|
2014-09-28 15:21:25 +02:00
|
|
|
private $timeServiceMock;
|
2014-09-27 21:33:31 +02:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->userDaoMock = $this->mock(\Szurubooru\Dao\UserDao::class);
|
|
|
|
$this->postDaoMock = $this->mock(\Szurubooru\Dao\PostDao::class);
|
2014-09-28 15:21:25 +02:00
|
|
|
$this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class);
|
2014-09-27 21:33:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaving()
|
|
|
|
{
|
|
|
|
$user = new \Szurubooru\Entities\User(1);
|
|
|
|
$user->setName('olivia');
|
|
|
|
|
|
|
|
$post = new \Szurubooru\Entities\Post(2);
|
|
|
|
$post->setName('sword');
|
|
|
|
|
|
|
|
$favorite = new \Szurubooru\Entities\Favorite();
|
|
|
|
$favorite->setUser($user);
|
|
|
|
$favorite->setPost($post);
|
2014-09-28 16:26:44 +02:00
|
|
|
$favorite->setTime(date('c'));
|
2014-09-27 21:33:31 +02:00
|
|
|
$favoritesDao = $this->getFavoritesDao();
|
|
|
|
$favoritesDao->save($favorite);
|
|
|
|
|
|
|
|
$this->userDaoMock->expects($this->once())->method('findById')->with(1)->willReturn($user);
|
|
|
|
$this->postDaoMock->expects($this->once())->method('findById')->with(2)->willReturn($post);
|
|
|
|
|
|
|
|
$savedFavorite = $favoritesDao->findById($favorite->getId());
|
|
|
|
$this->assertEquals(1, $savedFavorite->getUserId());
|
|
|
|
$this->assertEquals(2, $savedFavorite->getPostId());
|
2014-09-28 16:26:44 +02:00
|
|
|
$this->assertEquals($favorite->getTime(), $savedFavorite->getTime());
|
2014-09-27 21:33:31 +02:00
|
|
|
$this->assertEntitiesEqual($user, $savedFavorite->getUser());
|
|
|
|
$this->assertEntitiesEqual($post, $savedFavorite->getPost());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getFavoritesDao()
|
|
|
|
{
|
|
|
|
return new \Szurubooru\Dao\FavoritesDao(
|
|
|
|
$this->databaseConnection,
|
|
|
|
$this->userDaoMock,
|
2014-09-28 15:21:25 +02:00
|
|
|
$this->postDaoMock,
|
|
|
|
$this->timeServiceMock);
|
2014-09-27 21:33:31 +02:00
|
|
|
}
|
|
|
|
}
|