| 1 | <?php |
||
| 13 | class InvokerTest extends PHPUnit_Framework_TestCase { |
||
| 14 | |||
| 15 | public function publicFunction() { |
||
| 16 | return 'public'; |
||
| 17 | } |
||
| 18 | |||
| 19 | protected function protectedFunction() { |
||
| 20 | return 'protected'; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @covers ::build |
||
| 25 | * @covers ::__construct |
||
| 26 | * @covers ::__invoke |
||
| 27 | */ |
||
| 28 | public function testBuild() { |
||
| 29 | $t = Invoker::build(12345); |
||
| 30 | $this->assertNull($t()); |
||
| 31 | |||
| 32 | $t = Invoker::build(array($this, 'protectedFunction')); |
||
| 33 | $this->assertNull($t()); |
||
| 34 | |||
| 35 | |||
| 36 | $t = Invoker::build(function () { return 'lambda';}); |
||
| 37 | $this->assertEquals('lambda', $t()); |
||
| 38 | |||
| 39 | $t = Invoker::build(array($this, 'publicFunction')); |
||
| 40 | $this->assertEquals('public', $t()); |
||
| 41 | |||
| 42 | $t = Invoker::build('mt_rand'); |
||
| 43 | $this->assertTrue(is_integer($t())); |
||
| 44 | |||
| 45 | // $t = Invoker::build('array_unshift'); |
||
| 46 | // $array = array('q'); |
||
| 47 | // $this->assertEquals(2, $t($array, 'w')); |
||
| 48 | // // TODO - uncomment for PHP > 5.3 |
||
| 49 | // $this->assertEquals(array('w', 'q'), $array); |
||
| 50 | } |
||
| 51 | |||
| 52 | } |
||
| 53 |