Passed
Push — main ( 49ed5d...7bc915 )
by Peter
02:48
created

testCreateMetaViewFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AbterPhp\Framework\Bootstrappers\Views;
4
5
use Opulence\Http\Requests\Request;
6
use Opulence\Ioc\Container;
7
use Opulence\Routing\Urls\UrlGenerator;
8
use Opulence\Sessions\ISession;
9
use Opulence\Views\Compilers\Fortune\ITranspiler;
10
use Opulence\Views\Compilers\Fortune\Transpiler;
11
use PHPUnit\Framework\TestCase;
12
13
class ViewFunctionsBootstrapperTest extends TestCase
14
{
15
    /** @var ViewFunctionsBootstrapper */
16
    protected ViewFunctionsBootstrapper $sut;
17
18
    public function setUp(): void
19
    {
20
        $this->sut = new ViewFunctionsBootstrapper();
21
    }
22
23
    public function testRegisterBindings()
24
    {
25
        $requestMock      = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
26
        $urlGeneratorMock = $this->getMockBuilder(UrlGenerator::class)->disableOriginalConstructor()->getMock();
27
        $sessionMock      = $this->getMockBuilder(ISession::class)->getMock();
28
        $transpilerMock   = $this->getMockBuilder(Transpiler::class)->disableOriginalConstructor()->getMock();
29
30
        $transpilerMock->expects($this->atLeast(3))->method('registerViewFunction');
31
32
        $container = new Container();
33
        $container->bindInstance(Request::class, $requestMock);
34
        $container->bindInstance(UrlGenerator::class, $urlGeneratorMock);
35
        $container->bindInstance(ISession::class, $sessionMock);
36
        $container->bindInstance(ITranspiler::class, $transpilerMock);
37
38
        $this->sut->registerBindings($container);
39
    }
40
41
    public function testCreateMetaViewFunction()
42
    {
43
        $nameStub = 'foo';
44
        $contentStubs = ['', 'bar', 'baz'];
45
46
        $actual = $this->sut->createMetaViewFunction()($nameStub, ...$contentStubs);
47
        $this->assertSame("<meta property=\"$nameStub\" name=\"$nameStub\" content=\"{$contentStubs[1]}\">\n", $actual);
48
    }
49
50
    public function testCreateAuthorNameViewFunction()
51
    {
52
        $authorStub = 'foo';
53
54
        $actual = $this->sut->createAuthorNameViewFunction()($authorStub);
55
        $this->assertSame("<meta property=\"author\" name=\"author\" content=\"{$authorStub}\">\n", $actual);
56
    }
57
58
    public function testCreateAuthorLinkViewFunction()
59
    {
60
        $authorStub = 'https://foo.example.com/';
61
62
        $actual = $this->sut->createAuthorLinkViewFunction()($authorStub);
63
        $this->assertSame("<link rel=\"author\" href=\"{$authorStub}\">\n", $actual);
64
    }
65
}
66