szurubooru/tests/Services/FavoritesServiceTest.php

71 lines
2.2 KiB
PHP
Raw Normal View History

2014-09-27 21:33:31 +02:00
<?php
namespace Szurubooru\Tests\Services;
final class FavoritesServiceTest extends \Szurubooru\Tests\AbstractTestCase
{
private $favoritesDaoMock;
private $scoreDaoMock;
2014-09-27 21:33:31 +02:00
private $userDaoMock;
private $transactionManagerMock;
private $timeServiceMock;
2014-09-27 21:33:31 +02:00
public function setUp()
{
parent::setUp();
$this->favoritesDaoMock = $this->mock(\Szurubooru\Dao\FavoritesDao::class);
$this->scoreDaoMock = $this->mock(\Szurubooru\Dao\ScoreDao::class);
2014-09-27 21:33:31 +02:00
$this->userDaoMock = $this->mock(\Szurubooru\Dao\UserDao::class);
$this->transactionManagerMock = $this->mockTransactionManager();
$this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class);
2014-09-27 21:33:31 +02:00
}
public function testAdding()
{
$user = new \Szurubooru\Entities\User(1);
$post = new \Szurubooru\Entities\Post(2);
$fav = new \Szurubooru\Entities\Favorite();
$fav->setUserId($user->getId());
$fav->setPostId($post->getId());
2014-09-28 15:21:25 +02:00
$this->favoritesDaoMock->expects($this->once())->method('set')->with($user, $post);
2014-09-27 21:33:31 +02:00
$favoritesService = $this->getFavoritesService();
$favoritesService->addFavorite($user, $post);
}
public function testDeleting()
{
$user = new \Szurubooru\Entities\User();
$post = new \Szurubooru\Entities\Post();
$fav = new \Szurubooru\Entities\Favorite(3);
2014-09-28 15:21:25 +02:00
$this->favoritesDaoMock->expects($this->once())->method('delete')->with($user, $post);
2014-09-27 21:33:31 +02:00
$favoritesService = $this->getFavoritesService();
$favoritesService->deleteFavorite($user, $post);
}
public function testGettingByPost()
{
$post = new \Szurubooru\Entities\Post();
$fav1 = new \Szurubooru\Entities\Favorite();
$fav2 = new \Szurubooru\Entities\Favorite();
$fav1->setUser(new \Szurubooru\Entities\User(1));
$fav2->setUser(new \Szurubooru\Entities\User(2));
$this->favoritesDaoMock->expects($this->once())->method('findByEntity')->with($post)->willReturn([$fav1, $fav2]);
2014-09-27 21:33:31 +02:00
$this->userDaoMock->expects($this->once())->method('findByIds')->with([1, 2]);
$favoritesService = $this->getFavoritesService();
$favoritesService->getFavoriteUsers($post);
}
private function getFavoritesService()
{
return new \Szurubooru\Services\FavoritesService(
$this->favoritesDaoMock,
$this->scoreDaoMock,
2014-09-27 21:33:31 +02:00
$this->userDaoMock,
$this->transactionManagerMock,
$this->timeServiceMock);
2014-09-27 21:33:31 +02:00
}
}