Skip to content

Commit e7cc406

Browse files
author
cpriest
committed
ADDED: Iterated contextual tests for accessors (object|static) (get|set|isset|unset) (autoimplement|defined-body|non-defined) tests. This set of tests should test all basic functionality in all contexts of accessors. Most tests pass at this point, but anything relying on static set is not presently passing.
1 parent fc65492 commit e7cc406

24 files changed

+669
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
ZE2 Tests that an auto-implemented getter has a protected auto-implemented variable defined and that it can be retrieved through the accessor
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
get;
9+
}
10+
11+
public function __construct() {
12+
$this->__b = 5;
13+
}
14+
}
15+
16+
$o = new AccessorTest();
17+
18+
$rf = new ReflectionClass($o);
19+
foreach($rf->getProperties(ReflectionProperty::IS_PROTECTED) as $rfp) {
20+
if($rfp->getName() == '__b')
21+
echo "Protected property: \$".$rfp->getName()." exists.\n";
22+
}
23+
24+
echo "\$o->b: ".$o->b."\n";
25+
echo "Done\n";
26+
?>
27+
--EXPECTF--
28+
Protected property: $__b exists.
29+
$o->b: 5
30+
Done
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
ZE2 Tests that an defined getter has its code executed and return value properly returned upon access
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
get {
9+
echo "get::\$b called.\n";
10+
return 10;
11+
}
12+
}
13+
}
14+
15+
$o = new AccessorTest();
16+
17+
echo "\$o->b: ".$o->b."\n";
18+
echo "Done\n";
19+
?>
20+
--EXPECTF--
21+
get::$b called.
22+
$o->b: 10
23+
Done
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
ZE2 Tests that a non-defined getter produces an error upon access
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
set;
9+
}
10+
}
11+
12+
$o = new AccessorTest();
13+
14+
echo "\$o->b: ".$o->b."\n";
15+
echo "Done\n";
16+
?>
17+
--EXPECTF--
18+
Fatal error: Cannot get property AccessorTest::$b, no getter defined. in %s on line %d
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
ZE2 Tests that an autoimplemented isset defaults to checking the value against a NULL/non-NULL state.
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
get;
9+
set;
10+
isset;
11+
}
12+
}
13+
14+
$o = new AccessorTest();
15+
16+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
17+
$o->b = 10;
18+
echo "\$o->b = 10;\n";
19+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
20+
$o->b = NULL;
21+
echo "\$o->b = NULL;\n";
22+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
23+
echo "Done";
24+
?>
25+
--EXPECTF--
26+
isset($o->b) = 0
27+
$o->b = 10;
28+
isset($o->b) = 1
29+
$o->b = NULL;
30+
isset($o->b) = 0
31+
Done
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
ZE2 Tests that an defined isset has its code executed and the return value passed back as the result of the isset() call.
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
get;
9+
set;
10+
isset {
11+
echo "\$b::isset Called.\n";
12+
return $this->b != NULL;
13+
}
14+
}
15+
}
16+
17+
$o = new AccessorTest();
18+
19+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
20+
$o->b = 10;
21+
echo "\$o->b = 10;\n";
22+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
23+
$o->b = NULL;
24+
echo "\$o->b = NULL;\n";
25+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
26+
echo "Done";
27+
?>
28+
--EXPECTF--
29+
$b::isset Called.
30+
isset($o->b) = 0
31+
$o->b = 10;
32+
$b::isset Called.
33+
isset($o->b) = 1
34+
$o->b = NULL;
35+
$b::isset Called.
36+
isset($o->b) = 0
37+
Done
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
ZE2 Tests that an unimplemented isset functions identically to an auto-implemented isset which is checking the value against a NULL/non-NULL state.
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
get;
9+
set;
10+
}
11+
}
12+
13+
$o = new AccessorTest();
14+
15+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
16+
$o->b = 10;
17+
echo "\$o->b = 10;\n";
18+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
19+
$o->b = NULL;
20+
echo "\$o->b = NULL;\n";
21+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
22+
echo "Done";
23+
?>
24+
--EXPECTF--
25+
isset($o->b) = 0
26+
$o->b = 10;
27+
isset($o->b) = 1
28+
$o->b = NULL;
29+
isset($o->b) = 0
30+
Done
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
ZE2 Tests that an auto-implemented setter has a protected auto-implemented variable defined and that it can be changed through the accessor
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
set;
9+
}
10+
11+
public function __construct() {
12+
$this->__b = 5;
13+
}
14+
public function _getProtectedValue() { return $this->__b; }
15+
}
16+
17+
$o = new AccessorTest();
18+
19+
$rf = new ReflectionClass($o);
20+
foreach($rf->getProperties(ReflectionProperty::IS_PROTECTED) as $rfp) {
21+
if($rfp->getName() == '__b')
22+
echo "Protected property: \$".$rfp->getName()." exists.\n";
23+
}
24+
25+
echo "\$o->b: ".$o->_getProtectedValue()."\n";
26+
$o->b = 10;
27+
echo "\$o->b: ".$o->_getProtectedValue()."\n";
28+
echo "Done\n";
29+
?>
30+
--EXPECTF--
31+
Protected property: $__b exists.
32+
$o->b: 5
33+
$o->b: 10
34+
Done
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
ZE2 Tests that an defined setter has a protected auto-implemented variable defined and that it can be changed through the accessor
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
set {
9+
echo "Setter called.\n";
10+
}
11+
}
12+
}
13+
14+
$o = new AccessorTest();
15+
16+
$o->b = 10;
17+
echo "Done\n";
18+
?>
19+
--EXPECTF--
20+
Setter called.
21+
Done
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
ZE2 Tests that an undefined setter cannot be called and produces an error
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
}
9+
}
10+
11+
$o = new AccessorTest();
12+
13+
$o->b = 10;
14+
?>
15+
--EXPECTF--
16+
Fatal error: Cannot set property AccessorTest::$b, no setter defined. in %s on line %d
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
ZE2 Tests that an autoimplemented unset defaults to setting the value to NULL
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
get;
9+
set;
10+
isset;
11+
unset;
12+
}
13+
}
14+
15+
$o = new AccessorTest();
16+
17+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
18+
$o->b = 10;
19+
echo "\$o->b = 10;\n";
20+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
21+
unset($o->b);
22+
echo "unset(\$o->b);\n";
23+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
24+
echo "Done";
25+
?>
26+
--EXPECTF--
27+
isset($o->b) = 0
28+
$o->b = 10;
29+
isset($o->b) = 1
30+
unset($o->b);
31+
isset($o->b) = 0
32+
Done
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
ZE2 Tests that an defined unset has it's code executed
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
get;
9+
set;
10+
isset;
11+
unset {
12+
echo "\$b::unset Called.\n";
13+
$this->b = NULL;
14+
}
15+
}
16+
}
17+
18+
$o = new AccessorTest();
19+
20+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
21+
$o->b = 10;
22+
echo "\$o->b = 10;\n";
23+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
24+
unset($o->b);
25+
echo "unset(\$o->b);\n";
26+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
27+
echo "Done";
28+
?>
29+
--EXPECTF--
30+
isset($o->b) = 0
31+
$o->b = 10;
32+
isset($o->b) = 1
33+
$b::unset Called.
34+
unset($o->b);
35+
isset($o->b) = 0
36+
Done
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
ZE2 Tests that an undefined unset defaults to the same functionality as an autodefined unset, which is setting the value to NULL
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public $b {
8+
get;
9+
set;
10+
isset;
11+
}
12+
}
13+
14+
$o = new AccessorTest();
15+
16+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
17+
$o->b = 10;
18+
echo "\$o->b = 10;\n";
19+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
20+
unset($o->b);
21+
echo "unset(\$o->b);\n";
22+
echo "isset(\$o->b) = ".(int)isset($o->b)."\n";
23+
echo "Done";
24+
?>
25+
--EXPECTF--
26+
isset($o->b) = 0
27+
$o->b = 10;
28+
isset($o->b) = 1
29+
unset($o->b);
30+
isset($o->b) = 0
31+
Done
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
ZE2 Tests that a static auto-implemented getter has a protected auto-implemented variable defined and that it can be retrieved through the accessor
3+
--FILE--
4+
<?php
5+
6+
class AccessorTest {
7+
public static $b {
8+
get;
9+
}
10+
11+
public static function setStaticValue($value) {
12+
self::$__b = $value;
13+
}
14+
}
15+
16+
$rf = new ReflectionClass('AccessorTest');
17+
foreach($rf->getProperties(ReflectionProperty::IS_PROTECTED) as $rfp) {
18+
if($rfp->getName() == '__b') {
19+
if($rfp->isProtected() && $rfp->isStatic())
20+
echo "Protected static property: \$".$rfp->getName()." exists.\n";
21+
}
22+
}
23+
24+
echo "AccessorTest::\$b: ".AccessorTest::$b."\n";
25+
AccessorTest::setStaticValue(5);
26+
echo "AccessorTest::setStaticValue(5);\n";
27+
echo "AccessorTest::\$b: ".AccessorTest::$b."\n";
28+
echo "Done\n";
29+
?>
30+
--EXPECTF--
31+
Protected static property: $__b exists.
32+
AccessorTest::$b:
33+
AccessorTest::setStaticValue(5);
34+
AccessorTest::$b: 5
35+
Done

0 commit comments

Comments
 (0)