args)) { unset($this->args); } $this->error = false; } public function testCallbackShouldStoreMetadata() { $handler = new Zend_Stdlib_CallbackHandler('rand', array('event' => 'foo')); $this->assertEquals('foo', $handler->getMetadatum('event')); $this->assertEquals(array('event' => 'foo'), $handler->getMetadata()); } public function testCallbackShouldBeStringIfNoHandlerPassedToConstructor() { $handler = new Zend_Stdlib_CallbackHandler('rand'); $this->assertSame('rand', $handler->getCallback()); } public function testCallbackShouldBeArrayIfHandlerPassedToConstructor() { $handler = new Zend_Stdlib_CallbackHandler(array('Zend_Stdlib_TestAsset_SignalHandlers_ObjectCallback', 'test')); $this->assertSame(array('Zend_Stdlib_TestAsset_SignalHandlers_ObjectCallback', 'test'), $handler->getCallback()); } public function testCallShouldInvokeCallbackWithSuppliedArguments() { $handler = new Zend_Stdlib_CallbackHandler(array( $this, 'handleCall' )); $args = array('foo', 'bar', 'baz'); $handler->call($args); $this->assertSame($args, $this->args); } public function testPassingInvalidCallbackShouldRaiseInvalidCallbackExceptionDuringInstantiation() { $this->setExpectedException('Zend_Stdlib_Exception_InvalidCallbackException'); $handler = new Zend_Stdlib_CallbackHandler('boguscallback'); } public function testCallShouldReturnTheReturnValueOfTheCallback() { $handler = new Zend_Stdlib_CallbackHandler(array('Zend_Stdlib_TestAsset_SignalHandlers_ObjectCallback', 'test')); if (!is_callable(array('Zend_Stdlib_TestAsset_SignalHandlers_ObjectCallback', 'test'))) { echo "\nClass exists? " . var_export(class_exists('Zend_Stdlib_TestAsset_SignalHandlers_ObjectCallback'), 1) . "\n"; echo "Include path: " . get_include_path() . "\n"; } $this->assertEquals('bar', $handler->call(array())); } public function testStringCallbackResolvingToClassDefiningInvokeNameShouldRaiseException() { $this->setExpectedException('Zend_Stdlib_Exception_InvalidCallbackException'); $handler = new Zend_Stdlib_CallbackHandler('Zend_Stdlib_TestAsset_SignalHandlers_Invokable'); } public function testStringCallbackReferringToClassWithoutDefinedInvokeShouldRaiseException() { $this->setExpectedException('Zend_Stdlib_Exception_InvalidCallbackException'); $class = new Zend_Stdlib_TestAsset_SignalHandlers_InstanceMethod(); $handler = new Zend_Stdlib_CallbackHandler($class); } public function errorHandler($errno, $errstr) { $this->error = true; } public function testCallbackConsistingOfStringContextWithNonStaticMethodShouldRaiseException() { if (version_compare(PHP_VERSION, '5.3.0', '>=')) { $this->markTestSkipped('Behavior of is_callable changes between 5.2 and 5.3'); } $this->setExpectedException('Zend_Stdlib_Exception_InvalidCallbackException'); $handler = new Zend_Stdlib_CallbackHandler(array('Zend_Stdlib_TestAsset_SignalHandlers_InstanceMethod', 'handler')); } public function testStringCallbackConsistingOfNonStaticMethodShouldRaiseException() { if (version_compare(PHP_VERSION, '5.3.0', '>=')) { $this->markTestSkipped('Behavior of is_callable changes between 5.2 and 5.3'); } $this->setExpectedException('Zend_Stdlib_Exception_InvalidCallbackException'); $handler = new Zend_Stdlib_CallbackHandler('Zend_Stdlib_TestAsset_SignalHandlers_InstanceMethod::handler'); } public function testCallbackToClassImplementingOverloadingButNotInvocableShouldRaiseException() { $this->setExpectedException('Zend_Stdlib_Exception_InvalidCallbackException'); $handler = new Zend_Stdlib_CallbackHandler('foo', array( 'Zend_Stdlib_TestAsset_SignalHandlers_Overloadable', 'foo' )); } public function handleCall() { $this->args = func_get_args(); } } if (PHPUnit_MAIN_METHOD == 'Zend_Stdlib_CallbackHandlerTest::main') { Zend_Stdlib_CallbackHandlerTest::main(); }