2014-09-27 21:33:31 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Tests\Dao;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Dao\FavoritesDao;
|
|
|
|
use Szurubooru\Entities\Favorite;
|
|
|
|
use Szurubooru\Entities\Post;
|
|
|
|
use Szurubooru\Entities\User;
|
|
|
|
use Szurubooru\Services\TimeService;
|
|
|
|
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
2014-09-27 21:33:31 +02:00
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
final class FavoritesDaoTest extends AbstractDatabaseTestCase
|
2014-09-27 21:33:31 +02:00
|
|
|
{
|
2014-09-28 15:21:25 +02:00
|
|
|
private $timeServiceMock;
|
2014-09-27 21:33:31 +02:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2014-10-08 14:47:47 +02:00
|
|
|
$this->timeServiceMock = $this->mock(TimeService::class);
|
2014-09-27 21:33:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaving()
|
|
|
|
{
|
2014-10-08 14:47:47 +02:00
|
|
|
$user = new User(1);
|
2014-09-27 21:33:31 +02:00
|
|
|
$user->setName('olivia');
|
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
$post = new Post(2);
|
2014-09-27 21:33:31 +02:00
|
|
|
$post->setName('sword');
|
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
$favorite = new Favorite();
|
2014-10-05 15:15:03 +02:00
|
|
|
$favorite->setUserId($user->getId());
|
|
|
|
$favorite->setPostId($post->getId());
|
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);
|
|
|
|
|
|
|
|
$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-10-05 15:15:03 +02:00
|
|
|
$this->assertEquals($user->getId(), $savedFavorite->getUserId());
|
|
|
|
$this->assertEquals($post->getId(), $savedFavorite->getPostId());
|
2014-09-27 21:33:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getFavoritesDao()
|
|
|
|
{
|
2014-10-08 14:47:47 +02:00
|
|
|
return new FavoritesDao(
|
2014-09-27 21:33:31 +02:00
|
|
|
$this->databaseConnection,
|
2014-09-28 15:21:25 +02:00
|
|
|
$this->timeServiceMock);
|
2014-09-27 21:33:31 +02:00
|
|
|
}
|
|
|
|
}
|