Completed
Push — master ( 37876c...34238f )
by Marko
9s
created

DailyPostArchiveActionTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 47
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testInvoke() 0 44 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\Tests\Action;
15
16
use PHPUnit\Framework\TestCase;
17
use Prophecy\Argument;
18
use Sonata\DatagridBundle\Pager\PagerInterface;
19
use Sonata\IntlBundle\Templating\Helper\DateTimeHelper;
20
use Sonata\NewsBundle\Action\DailyPostArchiveAction;
21
use Sonata\NewsBundle\Entity\PostManager;
22
use Sonata\NewsBundle\Model\BlogInterface;
23
use Symfony\Component\DependencyInjection\Container;
24
use Symfony\Component\HttpFoundation\Request;
25
use Symfony\Component\HttpFoundation\Response;
26
use Symfony\Component\Translation\TranslatorInterface;
27
use Twig\Environment;
28
29
class DailyPostArchiveActionTest extends TestCase
30
{
31
    public function testInvoke(): void
32
    {
33
        $blog = $this->prophesize(BlogInterface::class);
34
        $translator = $this->prophesize(TranslatorInterface::class);
35
        $dateTimeHelper = $this->prophesize(DateTimeHelper::class);
36
37
        $dataParams = [
38
            'query' => 'foo.publicationDateStart >= :startDate AND bar.publicationDateStart < :endDate',
39
            'params' => [
40
                'startDate' => new \DateTime(),
41
                'endDate' => new \DateTime('tomorrow'),
42
            ],
43
        ];
44
45
        $postManager = $this->prophesize(PostManager::class);
46
        $postManager->getPublicationDateQueryParts('2018-7-8', 'day')
47
            ->willReturn($dataParams);
48
        $postManager->getPager([
49
            'date' => $dataParams,
50
        ], 1)
51
            ->willReturn($this->prophesize(PagerInterface::class));
52
53
        $twig = $this->prophesize(Environment::class);
54
        $twig->render('@SonataNews/Post/archive.html.twig', Argument::any())
55
            ->willReturn('HTML CONTENT');
56
57
        $container = new Container();
58
        $container->set('twig', $twig->reveal());
59
60
        $action = new DailyPostArchiveAction(
61
            $blog->reveal(),
62
            $postManager->reveal(),
63
            $translator->reveal(),
64
            $dateTimeHelper->reveal()
65
        );
66
        $action->setContainer($container);
67
68
        $request = new Request();
69
        $request->query->set('page', 1);
70
71
        $response = $action($request, 2018, 7, 8);
72
73
        $this->assertInstanceOf(Response::class, $response);
74
    }
75
}
76