Passed
Push — master ( 675168...23a502 )
by Paweł
03:16
created

TwigAdapterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A setUpTwig() 0 10 1
A testRendersTemplate() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gorynych\Tests\Adapter;
6
7
use Gorynych\Adapter\TwigAdapter;
8
use PHPUnit\Framework\MockObject\MockObject;
9
use PHPUnit\Framework\TestCase;
10
use Twig\Environment;
11
12
class TwigAdapterTest extends TestCase
13
{
14
    /** @var Environment|MockObject */
15
    private $twigMock;
16
17
    public function setUp(): void
18
    {
19
        $this->twigMock = $this->createMock(Environment::class);
20
    }
21
22
    public function testRendersTemplate(): void
23
    {
24
        $this->twigMock
25
            ->expects($this->once())
26
            ->method('render')
27
            ->with('foo.twig.html', ['foo' => 'bar'])
28
            ->willReturn('foo');
29
30
        $this->setUpTwig()->render('foo.twig.html', ['foo' => 'bar']);
31
    }
32
33
    private function setUpTwig(): TwigAdapter
34
    {
35
        $reflection = new \ReflectionClass(TwigAdapter::class);
36
        $twigAdapter = $reflection->newInstanceWithoutConstructor();
37
38
        $reflectionProperty = $reflection->getProperty('twig');
39
        $reflectionProperty->setAccessible(true);
40
        $reflectionProperty->setValue($twigAdapter, $this->twigMock);
41
42
        return $twigAdapter;
43
    }
44
}
45