mirror of
https://github.com/dg/dibi.git
synced 2025-08-11 00:24:19 +02:00
DibiObject: fixed compatibility with PHP 7
This commit is contained in:
70
tests/dibi/DibiObject.phpt
Normal file
70
tests/dibi/DibiObject.phpt
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
|
||||
class TestClass extends DibiObject
|
||||
{
|
||||
public function getBar()
|
||||
{
|
||||
return 123;
|
||||
}
|
||||
|
||||
public function isFoo()
|
||||
{
|
||||
return 456;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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().');
|
||||
|
||||
|
||||
// writing
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->undeclared = 'value';
|
||||
}, 'LogicException', 'Cannot assign to an undeclared property TestClass::$undeclared.');
|
||||
|
||||
|
||||
// property getter
|
||||
$obj = new TestClass;
|
||||
Assert::true(isset($obj->bar));
|
||||
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;
|
||||
}, 'LogicException', 'Cannot read an undeclared property TestClass::$undeclared.');
|
||||
|
||||
|
||||
// unset/isset
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
unset($obj->undeclared);
|
||||
}, 'LogicException', 'Cannot unset the property TestClass::$undeclared.');
|
||||
|
||||
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('*'));
|
Reference in New Issue
Block a user