Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ObjectMixin: added support for getting public methods as Closure
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Object closure properties. | ||
* | ||
* @author David Grudl | ||
* @package Nette | ||
* @subpackage UnitTests | ||
*/ | ||
|
||
|
||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
|
||
class TestClass extends Nette\Object | ||
{ | ||
private $id; | ||
|
||
function __construct($id = NULL) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function publicMethod($a, $b) | ||
{ | ||
return "$this->id $a $b"; | ||
} | ||
|
||
protected function protectedMethod() | ||
{ | ||
} | ||
|
||
private function privateMethod() | ||
{ | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
$obj1 = new TestClass(1); | ||
$method = $obj1->publicMethod; | ||
Assert::same( "1 2 3", $method(2, 3) ); | ||
|
||
|
||
Assert::throws(function() { | ||
$obj = new TestClass; | ||
$method = $obj->protectedMethod; | ||
}, 'Nette\MemberAccessException', 'Cannot read an undeclared property TestClass::$protectedMethod.'); | ||
|
||
|
||
Assert::throws(function() { | ||
$obj = new TestClass; | ||
$method = $obj->privateMethod; | ||
}, 'Nette\MemberAccessException', 'Cannot read an undeclared property TestClass::$privateMethod.'); |
f4b9762
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boner.