2015-10-06 12:43:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Tester\Assert;
|
|
|
|
|
|
|
|
require __DIR__ . '/bootstrap.php';
|
|
|
|
|
|
|
|
|
2015-10-06 12:54:27 +02:00
|
|
|
class TestClass
|
2015-10-06 12:43:45 +02:00
|
|
|
{
|
2015-10-06 12:54:27 +02:00
|
|
|
use DibiStrict;
|
2015-10-06 12:44:37 +02:00
|
|
|
|
2015-10-06 12:43:45 +02:00
|
|
|
public function getBar()
|
|
|
|
{
|
|
|
|
return 123;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isFoo()
|
|
|
|
{
|
|
|
|
return 456;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 12:54:27 +02:00
|
|
|
class TestChild extends TestClass
|
|
|
|
{
|
|
|
|
public function callParent()
|
|
|
|
{
|
|
|
|
parent::callParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 12:43:45 +02:00
|
|
|
|
|
|
|
// calling
|
|
|
|
Assert::exception(function () {
|
|
|
|
$obj = new TestClass;
|
|
|
|
$obj->undeclared();
|
|
|
|
}, 'LogicException', 'Call to undefined method TestClass::undeclared().');
|
|
|
|
|
|
|
|
Assert::exception(function () {
|
|
|
|
TestClass::undeclared();
|
|
|
|
}, 'LogicException', 'Call to undefined static method TestClass::undeclared().');
|
|
|
|
|
2015-10-06 12:44:37 +02:00
|
|
|
Assert::exception(function () {
|
2015-10-06 12:54:27 +02:00
|
|
|
$obj = new TestChild;
|
2015-10-06 12:44:37 +02:00
|
|
|
$obj->callParent();
|
|
|
|
}, 'LogicException', 'Call to undefined method parent::callParent().');
|
|
|
|
|
2015-10-06 12:43:45 +02:00
|
|
|
|
|
|
|
// writing
|
|
|
|
Assert::exception(function () {
|
|
|
|
$obj = new TestClass;
|
|
|
|
$obj->undeclared = 'value';
|
2015-10-06 12:44:37 +02:00
|
|
|
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$undeclared.');
|
2015-10-06 12:43:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
// property getter
|
|
|
|
$obj = new TestClass;
|
2015-10-06 12:44:37 +02:00
|
|
|
Assert::false(isset($obj->bar));
|
2015-10-06 12:43:45 +02:00
|
|
|
Assert::same(123, $obj->bar);
|
|
|
|
Assert::false(isset($obj->foo));
|
|
|
|
Assert::same(456, $obj->foo);
|
|
|
|
|
|
|
|
|
|
|
|
// reading
|
|
|
|
Assert::exception(function () {
|
|
|
|
$obj = new TestClass;
|
|
|
|
$val = $obj->undeclared;
|
2015-10-06 12:44:37 +02:00
|
|
|
}, 'LogicException', 'Attempt to read undeclared property TestClass::$undeclared.');
|
2015-10-06 12:43:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
// unset/isset
|
|
|
|
Assert::exception(function () {
|
|
|
|
$obj = new TestClass;
|
|
|
|
unset($obj->undeclared);
|
2015-10-06 12:44:37 +02:00
|
|
|
}, 'LogicException', 'Attempt to unset undeclared property TestClass::$undeclared.');
|
2015-10-06 12:43:45 +02:00
|
|
|
|
|
|
|
Assert::false(isset($obj->undeclared));
|
|
|
|
|
|
|
|
|
|
|
|
// extension method
|
|
|
|
TestClass::extensionMethod('join', $func = function (TestClass $that, $separator) {
|
|
|
|
return $that->foo . $separator . $that->bar;
|
|
|
|
});
|
|
|
|
|
|
|
|
$obj = new TestClass;
|
|
|
|
Assert::same('456*123', $obj->join('*'));
|