Skip to content

Commit def448b

Browse files
author
cpriest
committed
Added tests which confirm parenthesized get/set/unset/isset accessor definitions
1 parent d2ed599 commit def448b

6 files changed

+175
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
ZE2 Tests that a getter defined with parameters throws an error
3+
--FILE--
4+
<?php
5+
6+
class TimePeriod {
7+
public $Hours {
8+
get($x) { return 5; }
9+
}
10+
}
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Getters do not accept parameters for variable TimePeriod::$Hours in %s on line %d
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
ZE2 Tests that a getter can be defined with or without parenthesis
3+
--FILE--
4+
<?php
5+
6+
class TimePeriod {
7+
public $Seconds = 3600;
8+
9+
public $Hours {
10+
get { return $this->Seconds / 3600; }
11+
}
12+
public $Hours2 {
13+
get;
14+
}
15+
public $Hours3 {
16+
get();
17+
}
18+
public $Hours4 {
19+
get() { return $this->Seconds / 3600; }
20+
}
21+
}
22+
23+
$o = new TimePeriod();
24+
25+
echo $o->Hours."\n";
26+
echo $o->Hours2."\n";
27+
echo $o->Hours3."\n";
28+
echo $o->Hours4."\n";
29+
echo $o->Seconds."\n";
30+
31+
echo "Done\n";
32+
?>
33+
--EXPECTF--
34+
1
35+
36+
37+
1
38+
3600
39+
Done
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
ZE2 Tests that an issetter may be defined with or without parameters
3+
--FILE--
4+
<?php
5+
6+
class TimePeriod {
7+
public $Test1 {
8+
get { return 1; }
9+
isset { return true; }
10+
}
11+
public $Test2 {
12+
get() { return 1; }
13+
isset() { return false; }
14+
}
15+
}
16+
17+
$o = new TimePeriod();
18+
19+
echo (int)isset($o->Test1)."\n";
20+
echo (int)isset($o->Test2)."\n";
21+
echo "Done\n";
22+
?>
23+
--EXPECTF--
24+
1
25+
0
26+
Done
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
ZE2 Tests that a setter defined with a typehint produces error on invalid parameter pass
3+
--FILE--
4+
<?php
5+
6+
class TestClass {
7+
public function __toString() {
8+
return "Object [TestClass]";
9+
}
10+
}
11+
12+
class TimePeriod {
13+
public $Object {
14+
set(TestClass2 $y) { $this->_Seconds = $y; }
15+
}
16+
}
17+
18+
$o = new TimePeriod();
19+
$tc = new TestClass();
20+
21+
$o->Object = $tc;
22+
?>
23+
--EXPECTF--
24+
Catchable fatal error: Argument 1 passed to setter TimePeriod::$Object must be an instance of TestClass2, instance of TestClass given in %s on line %d
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
ZE2 Tests that a setter may be defined with or without parameters
3+
--FILE--
4+
<?php
5+
6+
class TestClass {
7+
public function __toString() {
8+
return "Object [TestClass]";
9+
}
10+
}
11+
12+
class TimePeriod {
13+
public $_Seconds = 3600;
14+
15+
public $Seconds {
16+
set { $this->_Seconds = $value; }
17+
}
18+
public $Seconds2 {
19+
set;
20+
}
21+
public $Seconds3 {
22+
set($x) { $this->_Seconds = $x; }
23+
}
24+
public $Object {
25+
set(TestClass $y) { $this->_Seconds = $y; }
26+
}
27+
}
28+
29+
$o = new TimePeriod();
30+
$tc = new TestClass();
31+
32+
echo $o->_Seconds."\n";
33+
$o->Seconds = 4000;
34+
echo $o->_Seconds."\n";
35+
$o->Seconds2 = 45;
36+
echo $o->_Seconds."\n";
37+
$o->Seconds3 = 5000;
38+
echo $o->_Seconds."\n";
39+
$o->Object = $tc;
40+
echo $o->_Seconds."\n";
41+
42+
echo "Done\n";
43+
?>
44+
--EXPECTF--
45+
3600
46+
4000
47+
4000
48+
5000
49+
Object [TestClass]
50+
Done
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
ZE2 Tests that an unsetter may be defined with or without parameters
3+
--FILE--
4+
<?php
5+
6+
class TimePeriod {
7+
public $Test1 {
8+
set { }
9+
unset { }
10+
}
11+
public $Test2 {
12+
set() { }
13+
unset() { }
14+
}
15+
}
16+
17+
$o = new TimePeriod();
18+
19+
echo "Done\n";
20+
?>
21+
--EXPECTF--
22+
Done

0 commit comments

Comments
 (0)