-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNewsServiceTest.php
48 lines (38 loc) · 1.36 KB
/
NewsServiceTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php declare(strict_types=1);
namespace App\Tests\Unit\Service;
use App\Entity\News;
use App\Repository\NewsRepositoryInterface;
use App\Service\NewsService;
use App\Tests\Shared\Unit\TestCase;
class NewsServiceTest extends TestCase
{
private $newsRepository;
private $newsService;
protected function setUp(): void
{
$this->newsRepository = $this->prophesize(NewsRepositoryInterface::class);
$this->newsService = new NewsService($this->newsRepository->reveal());
}
public function testCollection()
{
// Arrange
$expectedCollection = [];
$this->newsRepository->findAllPublished()->willReturn($expectedCollection);
// Act
$collection = $this->newsService->collection();
// Assert
$this->newsRepository->findAllPublished()->shouldHaveBeenCalledTimes(1);
$this->assertSame($expectedCollection, $collection);
}
public function testItem()
{
// Arrange
$expectedItem = $this->prophesize(News::class)->reveal();
$this->newsRepository->findOnePublishedBySlug('__SLUG__')->willReturn($expectedItem);
// Act
$item = $this->newsService->item('__SLUG__');
// Assert
$this->newsRepository->findOnePublishedBySlug('__SLUG__')->shouldHaveBeenCalledTimes(1);
$this->assertSame($expectedItem, $item);
}
}