|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tworzenieweb\Helper; |
|
4
|
|
|
|
|
5
|
|
|
use Mockery; |
|
6
|
|
|
use Mockery\MockInterface; |
|
7
|
|
|
use PHPUnit_Framework_TestCase; |
|
8
|
|
|
use Zend_View; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @author Luke Adamczewski |
|
12
|
|
|
* @package Tworzenieweb\Helper |
|
13
|
|
|
*/ |
|
14
|
|
|
class LegacyViewHelperWrapperTest extends PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var BCViewHelperInterface|MockInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $helper; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var LegacyViewHelper |
|
23
|
|
|
*/ |
|
24
|
|
|
private $helperWrapper; |
|
25
|
|
|
|
|
26
|
|
|
public function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->helper = Mockery::mock('\Tworzenieweb\Helper\JobleadsHelper')->makePartial(); |
|
29
|
|
|
$this->helperWrapper = new LegacyViewHelper(); |
|
30
|
|
|
$this->helperWrapper->injectHelper($this->helper); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testInnerHelperInvokeMethodShouldBeInvoked() |
|
34
|
|
|
{ |
|
35
|
|
|
$args = [1, 2, 3]; |
|
36
|
|
|
$this->assertTrue(true, is_callable($this->helperWrapper)); |
|
37
|
|
|
$this->helper->shouldReceive('__invoke')->once()->withArgs($args); |
|
38
|
|
|
|
|
39
|
|
|
$this->helperWrapper->__invoke($args); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testHelperWrapperShouldBeCompatibleWithZendView() |
|
43
|
|
|
{ |
|
44
|
|
|
$view = new Zend_View(); |
|
45
|
|
|
$name = $this->helperWrapper->getName(); |
|
46
|
|
|
$view->registerHelper($this->helperWrapper, $name); |
|
47
|
|
|
$this->helper->shouldReceive('__invoke')->once()->with(1, 2, 3); |
|
48
|
|
|
|
|
49
|
|
|
$view->{$name}(1, 2, 3); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @expectedException \RuntimeException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testItShouldFailWhenHelperIsNotCallable() |
|
56
|
|
|
{ |
|
57
|
|
|
$notCallableMock = Mockery::mock('\Tworzenieweb\Helper\BCViewHelperInterface'); |
|
58
|
|
|
$this->helperWrapper->injectHelper($notCallableMock); |
|
59
|
|
|
$this->helperWrapper->__invoke(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @expectedException \InvalidArgumentException |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testHelperShouldBeCallableByNameOnly() |
|
66
|
|
|
{ |
|
67
|
|
|
$name = $this->helperWrapper->getName(); |
|
68
|
|
|
$this->helper->shouldReceive('__invoke')->once(); |
|
69
|
|
|
$this->helperWrapper->{$name}(); |
|
70
|
|
|
|
|
71
|
|
|
$this->helperWrapper->someOtherMagicMethodThatWillFail(); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testDirect() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertNull($this->helperWrapper->direct()); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: