Completed
Push — develop ( a9d829...037456 )
by Jens
04:55 queued 43s
created

HandlebarsHelperTest::testAddHelper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
7
namespace JaySDe\HandlebarsBundle\Tests;
8
9
10
use JaySDe\HandlebarsBundle\HandlebarsHelper;
11
use JaySDe\HandlebarsBundle\Tests\Fixtures\InvokeHelper;
12
13
class HandlebarsHelperTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function testAddHelper()
16
    {
17
        $helperService = new HandlebarsHelper();
18
        $observer = $this->prophesize('\JaySDe\HandlebarsBundle\Helper\HelperInterface');
19
        $helperService->addHelper('test', $observer);
20
    }
21
22
    public function testGetHelperMethods()
23
    {
24
        $helperService = new HandlebarsHelper();
25
        $observer = $this->prophesize('\JaySDe\HandlebarsBundle\Helper\HelperInterface');
26
        $helperService->addHelper('test', $observer->reveal());
27
28
        $this->assertSame(['test'], $helperService->getHelperMethods());
29
    }
30
31
    public function testGetHelpers()
32
    {
33
        $helperService = new HandlebarsHelper();
34
        $observer = $this->prophesize('\JaySDe\HandlebarsBundle\Helper\HelperInterface');
35
        $helper = $observer->reveal();
36
        $helperService->addHelper('test', $helper);
37
38
        $helpers = $helperService->getHelpers();
39
        $this->assertArrayHasKey('test', $helpers);
40
        $this->assertTrue(is_callable($helpers['test']));
41
        $this->assertSame([$helper, 'handle'], $helpers['test']);
42
    }
43
44
    public function testCallable()
45
    {
46
        $helperService = new HandlebarsHelper();
47
        $t = function () {};
48
        $helperService->addHelper('test', $t);
49
50
        $helper = $helperService->getHelpers()['test'];
51
        $this->assertTrue(is_callable($helper));
52
        $this->assertSame($t, $helper);
53
    }
54
55
    public function testInvoke()
56
    {
57
        $helperService = new HandlebarsHelper();
58
        $t = new InvokeHelper();
59
        $helperService->addHelper('test', $t);
60
61
        $this->assertInstanceOf(
62
            '\JaySDe\HandlebarsBundle\Tests\Fixtures\InvokeHelper',
63
            $helperService->getHelpers()['test']
64
        );
65
        $this->assertSame($t, $helperService->getHelpers()['test']);
66
    }
67
}
68