szurubooru/tests/Dao/FavoritesDaoTest.php

50 lines
1.5 KiB
PHP
Raw Normal View History

2014-09-27 21:33:31 +02:00
<?php
namespace Szurubooru\Tests\Dao;
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
final class FavoritesDaoTest extends AbstractDatabaseTestCase
2014-09-27 21:33:31 +02:00
{
2015-11-25 09:48:03 +01:00
private $timeServiceMock;
2014-09-27 21:33:31 +02:00
2015-11-25 09:48:03 +01:00
public function setUp()
{
parent::setUp();
$this->timeServiceMock = $this->mock(TimeService::class);
}
2014-09-27 21:33:31 +02:00
2015-11-25 09:48:03 +01:00
public function testSaving()
{
$user = new User(1);
$user->setName('olivia');
2014-09-27 21:33:31 +02:00
2015-11-25 09:48:03 +01:00
$post = new Post(2);
$post->setName('sword');
2014-09-27 21:33:31 +02:00
2015-11-25 09:48:03 +01:00
$favorite = new Favorite();
$favorite->setUserId($user->getId());
$favorite->setPostId($post->getId());
$favorite->setTime(date('c'));
$favoritesDao = $this->getFavoritesDao();
$favoritesDao->save($favorite);
2014-09-27 21:33:31 +02:00
2015-11-25 09:48:03 +01:00
$savedFavorite = $favoritesDao->findById($favorite->getId());
$this->assertEquals(1, $savedFavorite->getUserId());
$this->assertEquals(2, $savedFavorite->getPostId());
$this->assertEquals($favorite->getTime(), $savedFavorite->getTime());
$this->assertEquals($user->getId(), $savedFavorite->getUserId());
$this->assertEquals($post->getId(), $savedFavorite->getPostId());
}
2014-09-27 21:33:31 +02:00
2015-11-25 09:48:03 +01:00
private function getFavoritesDao()
{
return new FavoritesDao(
$this->databaseConnection,
$this->timeServiceMock);
}
2014-09-27 21:33:31 +02:00
}