/**
  * Tests the setName() method.
  * @covers \ManiaScript\Builder\Event\Timer::setName
  */
 public function testSetName()
 {
     $expected = 'abc';
     $timer = new Timer();
     $result = $timer->setName($expected);
     $this->assertEquals($timer, $result);
     $this->assertPropertyEquals($expected, $timer, 'name');
 }
Exemple #2
0
 /**
  * Adds a timer handler to the ManiaScript.
  * @param string $name The name of the timer.
  * @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 addTimer($name, $code, $priority = 5, $inline = false)
 {
     $timer = new Timer();
     $timer->setName($name)->setCode($code)->setPriority($priority)->setInline($inline);
     $this->builder->addEvent($timer);
     return $this;
 }
 /**
  * Tests the buildGlobalCode() method.
  * @covers \ManiaScript\Builder\Event\Handler\Timer::buildGlobalCode
  */
 public function testBuildGlobalCode()
 {
     $event1 = new TimerEvent();
     $event1->setName('abc')->setCode('def')->setInline(true);
     $event2 = new TimerEvent();
     $event2->setName('ghi')->setCode('jkl')->setInline(false);
     $expectedGlobalCode = 'mno';
     /* @var $handler \ManiaScript\Builder\Event\Handler\Timer|\PHPUnit_Framework_MockObject_MockObject */
     $handler = $this->getMockBuilder('ManiaScript\\Builder\\Event\\Handler\\Timer')->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);
 }