/** * Tests the setName() method. * @covers \ManiaScript\Builder\Event\Custom::setName */ public function testSetName() { $expected = 'abc'; $event = new Custom(); $result = $event->setName($expected); $this->assertEquals($event, $result); $this->assertPropertyEquals($expected, $event, 'name'); }
/** * Tests the buildGlobalCode() method. * @covers \ManiaScript\Builder\Event\Handler\Custom::buildGlobalCode */ public function testBuildGlobalCode() { $event1 = new CustomEvent(); $event1->setName('abc')->setCode('def')->setInline(true); $event2 = new CustomEvent(); $event2->setName('ghi')->setCode('jkl')->setInline(false); $expectedGlobalCode = 'mno'; /* @var $handler \ManiaScript\Builder\Event\Handler\Custom|\PHPUnit_Framework_MockObject_MockObject */ $handler = $this->getMockBuilder('ManiaScript\\Builder\\Event\\Handler\\Custom')->setMethods(array('buildHandlerFunction'))->setConstructorArgs(array(new Builder()))->getMock(); $handler->expects($this->once())->method('buildHandlerFunction')->with($event2)->will($this->returnValue('mno')); $this->injectProperty($handler, 'events', array($event1, $event2)); $result = $this->invokeMethod($handler, 'buildGlobalCode'); $this->assertEquals($expectedGlobalCode, $result); }
/** * Adds a custom event to the ManiaScript. * @param string $name The name of the event. * @param string $code The code to be executed. * @param int $priority The priority, 0 for most important, bigger for less important. * @param boolean $inline Whether this event is handled inline, i.e. without wrapping function. * @return $this Implementing fluent interface. */ public function addCustomEvent($name, $code, $priority = 5, $inline = false) { $custom = new Custom(); $custom->setName($name)->setCode($code)->setPriority($priority)->setInline($inline); $this->builder->addEvent($custom); return $this; }