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
|
|
|
|