1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
4
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
5
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
6
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
7
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
8
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ZfTwitterWidgetTests\View; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use TwitterWidgets\Options\WidgetOptions; |
15
|
|
|
use TwitterWidgets\Timeline\TimelineBuilder; |
16
|
|
|
use ZfTwitterWidget\View\TwViewHelper; |
17
|
|
|
|
18
|
|
|
class TwViewHelperTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
public function testTwViewHelper() |
21
|
|
|
{ |
22
|
|
|
$widgetOption = $this |
23
|
|
|
->getMockBuilder(WidgetOptions::class) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$timelineBuilder = $this |
28
|
|
|
->getMockBuilder(TimelineBuilder::class) |
29
|
|
|
->disableOriginalConstructor() |
30
|
|
|
->setMethods(['filterAttr', 'getSingleWidgetJs']) |
31
|
|
|
->getMock(); |
32
|
|
|
|
33
|
|
|
$timelineBuilder |
34
|
|
|
->expects($this->once()) |
35
|
|
|
->method('filterAttr') |
36
|
|
|
->willReturn([]); |
37
|
|
|
|
38
|
|
|
$timelineBuilder |
39
|
|
|
->expects($this->once()) |
40
|
|
|
->method('getSingleWidgetJs') |
41
|
|
|
->willReturn('achievement unlocked!'); |
42
|
|
|
|
43
|
|
|
$viewHelper = new TwViewHelper( |
44
|
|
|
$widgetOption, |
45
|
|
|
$timelineBuilder |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->assertGreaterThan(0, strpos($viewHelper([]), 'achievement unlocked!')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @expectedException \InvalidArgumentException |
53
|
|
|
*/ |
54
|
|
|
public function testWrongTypeThrowsException() |
55
|
|
|
{ |
56
|
|
|
$widgetOption = $this |
57
|
|
|
->getMockBuilder(WidgetOptions::class) |
58
|
|
|
->disableOriginalConstructor() |
59
|
|
|
->getMock(); |
60
|
|
|
|
61
|
|
|
$timelineBuilder = $this |
62
|
|
|
->getMockBuilder(TimelineBuilder::class) |
63
|
|
|
->disableOriginalConstructor() |
64
|
|
|
->getMock(); |
65
|
|
|
|
66
|
|
|
$viewHelper = new TwViewHelper($widgetOption, $timelineBuilder); |
67
|
|
|
$options = new \stdClass(); |
68
|
|
|
|
69
|
|
|
$viewHelper->__invoke($options); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: