diff --git a/recess/test/recess/core/CandyTest.php b/recess/test/recess/core/CandyTest.php index 9ed003d..f863cee 100644 --- a/recess/test/recess/core/CandyTest.php +++ b/recess/test/recess/core/CandyTest.php @@ -66,8 +66,58 @@ function testLIFO() { function testLazyLinks() { $candy = new Candy(function($num) { return $num + 1; }); $candy->wrap(function($candy, &$num) { $num += 1; }) - ->wrap(function($candy, $num) { /* echo or log something */ }); + ->wrap(function($candy, $num) { /* echo or log something */ }); $this->assertEquals(3, $candy(1)); } -} \ No newline at end of file + function testNonCallableException() { + try { + $candy = new Candy('unknownFunc'); + $this->assertTrue(false); + } catch(Exception $e) { + $this->assertTrue(true); + return; + } + $this->assertTrue(false); + } + + function testPlainOldFunction() { + $candy = new Candy('callMe'); + $this->assertEquals('pass',$candy()); + $candy->wrap(function ($candy) { return $candy() . 'me'; }); + $this->assertEquals('passme',$candy()); + } + + function testStaticMethod() { + $candy = new Candy(array('SomeStaticClass','callMe')); + $this->assertEquals('pass',$candy()); + $candy->wrap(function ($candy) { return $candy() . 'me'; }); + $this->assertEquals('passme',$candy()); + } + + function testMethod() { + $candy = new Candy(array(new SomeStaticClass,'callMe')); + $this->assertEquals('pass',$candy()); + $candy->wrap(function ($candy) { return $candy() . 'me'; }); + $this->assertEquals('passme',$candy()); + } + + function testManyArgsUnwrapped() { + $candy = new Candy(function() { return array_sum(func_get_args()); }); + $this->assertEquals(0, $candy()); + $this->assertEquals(1, $candy(1)); + $this->assertEquals(2, $candy(1,1)); + $this->assertEquals(3, $candy(1,1,1)); + $this->assertEquals(4, $candy(1,1,1,1)); + $this->assertEquals(5, $candy(1,1,1,1,1)); + $this->assertEquals(6, $candy(1,1,1,1,1,1)); + $this->assertEquals(7, $candy(1,1,1,1,1,1,1)); + } +} + + +class SomeStaticClass { + static function callMe() { return 'pass'; } + function callMeToo() { return 'pass'; } +} +function callMe() { return 'pass'; } \ No newline at end of file diff --git a/recess/test/recess/core/EventTest.php b/recess/test/recess/core/EventTest.php index 1851fa4..eef6248 100644 --- a/recess/test/recess/core/EventTest.php +++ b/recess/test/recess/core/EventTest.php @@ -65,4 +65,28 @@ function testInvokeManyArgs() { $onSum(1,1,1,1,1,1,1,1,1,1); $this->assertEquals(10, $theSum); } + + function testVaryingArgNumbers() { + $onSum = new Event; + $theSum = 0; + $onSum->call(function() use (&$theSum) { $theSum = array_sum(func_get_args()); }); + $onSum(1); + $this->assertEquals(1,$theSum); + $theSum = 0; + $onSum(1,1); + $this->assertEquals(2,$theSum); + $theSum = 0; + $onSum(1,1,1); + $this->assertEquals(3,$theSum); + $theSum = 0; + $onSum(1,1,1,1); + $this->assertEquals(4,$theSum); + $theSum = 0; + $onSum(1,1,1,1,1); + $this->assertEquals(5,$theSum); + $theSum = 0; + $onSum(1,1,1,1,1,1); + $this->assertEquals(6,$theSum); + $theSum = 0; + } } \ No newline at end of file