|
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 TwitterWidgetBundleTests\Extension; |
|
12
|
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use TwitterWidgetBundle\Extension\TimelineWidget; |
|
15
|
|
|
use TwitterWidgets\Options\WidgetOptions; |
|
16
|
|
|
use TwitterWidgets\Timeline\TimelineBuilder; |
|
17
|
|
|
|
|
18
|
|
|
class TimelineWidgetTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testInstance() |
|
21
|
|
|
{ |
|
22
|
|
|
$widgetOptions = $this->createMock(WidgetOptions::class); |
|
23
|
|
|
$timelineBuilder = new TimelineBuilder($widgetOptions); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertInstanceOf(TimelineWidget::class, new TimelineWidget($widgetOptions, $timelineBuilder)); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testTwoFunctionsAreRegistered() |
|
29
|
|
|
{ |
|
30
|
|
|
$widgetOptions = $this->createMock(WidgetOptions::class); |
|
31
|
|
|
$timelineBuilder = new TimelineBuilder($widgetOptions); |
|
32
|
|
|
|
|
33
|
|
|
$extension = new TimelineWidget($widgetOptions, $timelineBuilder); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertCount(2, $extension->getFunctions()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testName() |
|
39
|
|
|
{ |
|
40
|
|
|
$widgetOptions = $this->createMock(WidgetOptions::class); |
|
41
|
|
|
$timelineBuilder = new TimelineBuilder($widgetOptions); |
|
42
|
|
|
|
|
43
|
|
|
$extension = new TimelineWidget($widgetOptions, $timelineBuilder); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertEquals('timelinewidgetextensions', $extension->getName()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testOneTimeJs() |
|
49
|
|
|
{ |
|
50
|
|
|
$widgetOptions = $this->createMock(WidgetOptions::class); |
|
51
|
|
|
$timelineBuilder = new TimelineBuilder($widgetOptions); |
|
52
|
|
|
|
|
53
|
|
|
$extension = new TimelineWidget($widgetOptions, $timelineBuilder); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertGreaterThan(0, strpos($extension->getOneTimeWidgetJs(), 'widgets.js')); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function testRenderWidget() |
|
60
|
|
|
{ |
|
61
|
|
|
$widgetOptions = $this->createMock(WidgetOptions::class); |
|
62
|
|
|
|
|
63
|
|
|
$timelinebuilder = $this |
|
64
|
|
|
->getMockBuilder(TimelineBuilder::class) |
|
65
|
|
|
->disableOriginalConstructor() |
|
66
|
|
|
->getMock(); |
|
67
|
|
|
|
|
68
|
|
|
$timelinebuilder->expects($this->any()) |
|
69
|
|
|
->method('renderWidget') |
|
70
|
|
|
->will($this->returnValue('rendered!')); |
|
71
|
|
|
|
|
72
|
|
|
$extension = new TimelineWidget($widgetOptions, $timelinebuilder); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertEquals('rendered!', $extension->renderWidget([])); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @expectedException \InvalidArgumentException |
|
79
|
|
|
*/ |
|
80
|
|
|
public function testWrongTypeThrowsException() |
|
81
|
|
|
{ |
|
82
|
|
|
$widgetOption = $this |
|
83
|
|
|
->getMockBuilder(WidgetOptions::class) |
|
84
|
|
|
->disableOriginalConstructor() |
|
85
|
|
|
->getMock(); |
|
86
|
|
|
|
|
87
|
|
|
$timelineBuilder = $this |
|
88
|
|
|
->getMockBuilder(TimelineBuilder::class) |
|
89
|
|
|
->disableOriginalConstructor() |
|
90
|
|
|
->getMock(); |
|
91
|
|
|
|
|
92
|
|
|
$viewHelper = new TimelineWidget($widgetOption, $timelineBuilder); |
|
93
|
|
|
$options = new \stdClass(); |
|
94
|
|
|
|
|
95
|
|
|
$viewHelper->renderWidget($options); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
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: