22
33//require_once '../../../../../vendor/autoload.php';
44
5- class Base
6- {
7- const TEMPLATE ='034_parent.tpl ' ;
5+ if (version_compare (phpversion (), '5.5.0 ' , '> ' )) {
86
9- public $ id =null ;
10-
11- public function __construct ($ id )
7+ class Base
128 {
13- $ this ->id =$ id ;
14- }
9+ const TEMPLATE = '034_parent.tpl ' ;
1510
16- public function getHTML ()
17- {
18- return static ::class;
19- }
20- }
11+ public $ id = null ;
2112
22- class Child extends Base
23- {
24- const TEMPLATE ='034_child.tpl ' ;
13+ public function __construct ($ id )
14+ {
15+ $ this ->id = $ id ;
16+ }
2517
26- public function getText ()
27- {
28- return $ this ->getHTML ();
18+ public function getHTML ()
19+ {
20+ return static ::class;
21+ }
2922 }
30- }
31-
32- class BaseClone extends Base
33- {
34-
35- }
3623
24+ class Child extends Base
25+ {
26+ const TEMPLATE = '034_child.tpl ' ;
3727
38- /*
39- * @requires PHP 5.5
40- */
41- class InheritanceTest extends PHPUnit_Framework_TestCase
42- {
43- protected $ smarty ;
28+ public function getText ()
29+ {
30+ return $ this ->getHTML ();
31+ }
32+ }
4433
45- protected function setUp ()
34+ class BaseClone extends Base
4635 {
47- chdir (dirname (__FILE__ ));
48- $ this ->smarty =new Smarty ();
49- $ this ->smarty ->setTemplateDir ('./templates ' );
50- $ this ->smarty ->setCompileDir ('./templates_c ' );
51- $ this ->smarty ->setCacheDir ('./cache ' );
52- $ this ->smarty ->caching =false ;
36+
5337 }
5438
55- /**
56- * @dataProvider providerInheritance
39+ /*
40+ * @requires PHP 5.5
5741 */
58- public function testInheritance ($ elements , $ assertions )
42+
43+ class InheritanceTest extends PHPUnit_Framework_TestCase
5944 {
60- foreach ($ elements as $ nr => $ element )
45+ protected $ smarty ;
46+
47+ protected function setUp ()
6148 {
62- $ this ->smarty ->assign ('e ' , $ element );
63- $ this ->assertSame ($ assertions [$ nr ], $ this ->smarty ->fetch ($ element ::TEMPLATE ));
49+ chdir (dirname (__FILE__ ));
50+ $ this ->smarty = new Smarty ();
51+ $ this ->smarty ->setTemplateDir ('./templates ' );
52+ $ this ->smarty ->setCompileDir ('./templates_c ' );
53+ $ this ->smarty ->setCacheDir ('./cache ' );
54+ $ this ->smarty ->caching = false ;
6455 }
65- }
66- /**
67- * @dataProvider providerInheritance
68- */
69- public function testInheritanceCaching ($ elements , $ assertions )
70- {
71- $ this ->smarty ->caching = true ;
72- foreach ($ elements as $ nr => $ element )
56+
57+ /**
58+ * @dataProvider providerInheritance
59+ * @requires PHP5.5
60+ */
61+ public function testInheritance ($ elements , $ assertions )
7362 {
74- $ this ->smarty ->assign ('e ' , $ element );
75- $ this ->assertSame ($ assertions [$ nr ], $ this ->smarty ->fetch ($ element ::TEMPLATE ));
63+ foreach ($ elements as $ nr => $ element ) {
64+ $ this ->smarty ->assign ('e ' , $ element );
65+ $ this ->assertSame ($ assertions [ $ nr ], $ this ->smarty ->fetch ($ element ::TEMPLATE ));
66+ }
7667 }
77- }
78- /**
79- * @dataProvider providerInheritance
80- */
81- public function testInheritanceCaching1 ($ elements , $ assertions )
82- {
83- $ this ->smarty ->caching = true ;
84- foreach ($ elements as $ nr => $ element )
68+
69+ /**
70+ * @dataProvider providerInheritance
71+ */
72+ public function testInheritanceCaching ($ elements , $ assertions )
8573 {
86- $ this ->smarty ->assign ('e ' , $ element );
87- $ stat = $ this ->smarty ->isCached ($ element ::TEMPLATE );
88- $ this ->assertSame ($ assertions [$ nr ], $ this ->smarty ->fetch ($ element ::TEMPLATE ));
89- $ this ->assertTrue ($ stat );
74+ $ this ->smarty ->caching = true ;
75+ foreach ($ elements as $ nr => $ element ) {
76+ $ this ->smarty ->assign ('e ' , $ element );
77+ $ this ->assertSame ($ assertions [ $ nr ], $ this ->smarty ->fetch ($ element ::TEMPLATE ));
78+ }
9079 }
91- }
9280
93- public function providerInheritance ()
94- {
95- return [
96- [
97- //(#0) This test works as expected
98- [
99- new Base (1 ),
100- new Base (2 ),
101- new BaseClone (3 ),
102- ], [
103- '1 Base ' ,
104- '2 Base ' ,
105- '3 BaseClone ' ,
106- ],
107- ], [
108- //(#1) This test works as expected
109- [
110- new Child (1 ),
111- new BaseClone (2 ), //This output is right(!)
112- ], [
113- '1 Child ' ,
114- '2 BaseClone ' ,
115- ],
116- ], [
117- //(#2) This test fails
118- [
119- new Child (1 ),
120- new Child (2 ),
121- new BaseClone (3 ),
122- ], [
123- '1 Child ' ,
124- '2 Child ' ,
125- '3 BaseClone ' , //Here the output is "2 Child"
126- ],
127- ], [
128- //(#3) This test fails
129- [
130- new Child (1 ),
131- new BaseClone (2 ),
132- new Child (3 ),
133- ], [
134- '1 Child ' ,
135- '2 BaseClone ' ,
136- '3 Child ' , //Here the output is "2 Child"
137- ],
138- ], [
139- //(#4) This test fails
140- [
141- new Child (1 ),
142- new Child (2 ),
143- new BaseClone (3 ),
144- new Child (4 ),
145- ], [
146- '1 Child ' ,
147- '2 Child ' ,
148- '3 BaseClone ' , //Here the output is also "2 Child"
149- '4 Child ' ,
150- ],
151- ], [
152- //(#5) This test fails
153- [
154- new BaseClone (1 ),
155- new Child (2 ),
156- new Child (3 ),
157- new BaseClone (4 ),
158- ], [
159- '1 BaseClone ' , //This output is right(!)
160- '2 Child ' ,
161- '3 Child ' ,
162- '4 BaseClone ' , //Here the output is "3 Child"
163- ],
164- ],
165- ];
81+ /**
82+ * @dataProvider providerInheritance
83+ */
84+ public function testInheritanceCaching1 ($ elements , $ assertions )
85+ {
86+ $ this ->smarty ->caching = true ;
87+ foreach ($ elements as $ nr => $ element ) {
88+ $ this ->smarty ->assign ('e ' , $ element );
89+ $ stat = $ this ->smarty ->isCached ($ element ::TEMPLATE );
90+ $ this ->assertSame ($ assertions [ $ nr ], $ this ->smarty ->fetch ($ element ::TEMPLATE ));
91+ $ this ->assertTrue ($ stat );
92+ }
93+ }
94+
95+ public function providerInheritance ()
96+ {
97+ return [[//(#0) This test works as expected
98+ [new Base (1 ), new Base (2 ), new BaseClone (3 ),], ['1 Base ' , '2 Base ' , '3 BaseClone ' ,],],
99+ [//(#1) This test works as expected
100+ [new Child (1 ), new BaseClone (2 ), //This output is right(!)
101+ ], ['1 Child ' , '2 BaseClone ' ,],], [//(#2) This test fails
102+ [new Child (1 ), new Child (2 ), new BaseClone (3 ),],
103+ ['1 Child ' , '2 Child ' , '3 BaseClone ' ,
104+ //Here the output is "2 Child"
105+ ],], [//(#3) This test fails
106+ [new Child (1 ), new BaseClone (2 ), new Child (3 ),],
107+ ['1 Child ' , '2 BaseClone ' , '3 Child ' ,
108+ //Here the output is "2 Child"
109+ ],], [//(#4) This test fails
110+ [new Child (1 ), new Child (2 ), new BaseClone (3 ),
111+ new Child (4 ),],
112+ ['1 Child ' , '2 Child ' , '3 BaseClone ' ,
113+ //Here the output is also "2 Child"
114+ '4 Child ' ,],], [//(#5) This test fails
115+ [new BaseClone (1 ), new Child (2 ),
116+ new Child (3 ), new BaseClone (4 ),],
117+ ['1 BaseClone ' ,
118+ //This output is right(!)
119+ '2 Child ' , '3 Child ' ,
120+ '4 BaseClone ' ,
121+ //Here the output is "3 Child"
122+ ],],];
123+ }
166124 }
167- }
125+ }
0 commit comments