예제 #1
0
 public function setUp()
 {
     $sxml = new SimpleXMLElement('<foo/>');
     $this->_mainConfig = $this->getMockBuilder('\\Erebot\\Interfaces\\Config\\Main')->getMock();
     $networkConfig = $this->getMockBuilder('\\Erebot\\Interfaces\\Config\\Network')->setConstructorArgs(array($this->_mainConfig, $sxml))->getMock();
     $serverConfig = $this->getMockBuilder('\\Erebot\\Interfaces\\Config\\Server')->setConstructorArgs(array($networkConfig, $sxml))->getMock();
     $bot = $this->getMockBuilder('\\Erebot\\Interfaces\\Core')->setConstructorArgs(array($this->_mainConfig))->getMock();
     $this->_connection = $this->getMockBuilder('\\Erebot\\Interfaces\\Connection')->setConstructorArgs(array($bot, $serverConfig))->getMock();
     $this->_cb = \Erebot\CallableWrapper::wrap(array($this, 'dummyCallback'));
 }
예제 #2
0
 /**
  * @covers \Erebot\Timer::setRepetition
  * @covers \Erebot\Timer::getRepetition
  */
 public function testRepetition()
 {
     $callback = \Erebot\CallableWrapper::wrap(array($this, 'helper'));
     $args = array('foo', 'bar');
     $timer = new \Erebot\Timer($callback, 42, FALSE, $args);
     $this->assertEquals(1, $timer->getRepetition());
     $timer->setRepetition(TRUE);
     $this->assertEquals(-1, $timer->getRepetition());
     $timer->setRepetition(2);
     $this->assertEquals(2, $timer->getRepetition());
 }
예제 #3
0
파일: TimerTest.php 프로젝트: erebot/timer
 /**
  * Nominal case for timers.
  *
  * We create a timer set to go off twice with a delay of 2.5 seconds.
  * We check that each parameter is correctly set before each run.
  *
  * @covers \Erebot\Timer::reset
  * @covers \Erebot\Timer::getStream
  * @covers \Erebot\Timer::activate
  * @covers \Erebot\Timer::__construct
  * @covers \Erebot\Timer::__destruct
  */
 public function testNominalCase()
 {
     $this->timer = new \Erebot\Timer(\Erebot\CallableWrapper::wrap(array($this, 'helper')), $this->delay, 2, array('foo', 'bar'));
     // Do a first pass : after that,
     // we expect exactly 1 repetition left.
     $this->check();
     $this->assertEquals(1, $this->timer->getRepetition());
     // Do a second pass : after that,
     // we expect exactly 0 repetitions left.
     $this->check();
     $this->assertEquals(0, $this->timer->getRepetition());
     // Trying to reset the timer MUST fail
     // because there are no more repetitions left.
     $this->assertFalse($this->timer->reset());
 }
예제 #4
0
파일: Proxy.php 프로젝트: erebot/erebot
 public function parseReal($module, $param, $default = null)
 {
     return $this->parseSomething($module, $param, $default, \Erebot\CallableWrapper::wrap(array($this, 'parseRealHelper')), __FUNCTION__, \Erebot\CallableWrapper::wrap('is_real'));
 }
예제 #5
0
파일: Base.php 프로젝트: erebot/api
 /**
  * Public method to (re)load a module.
  * This eventually reconfigures the bot.
  *
  * \param Erebot::Interface::Connection $connection
  *      IRC connection associated with this instance.
  *
  * \param int $flags
  *      A bitwise OR of the Erebot::Module::Base::RELOAD_*
  *      constants. Your method should take proper actions
  *      depending on the value of those flags.
  *
  * \note
  *      See the documentation on individual RELOAD_*
  *      constants for a list of possible values.
  */
 public final function reloadModule(\Erebot\Interfaces\Connection $connection, $flags)
 {
     if ($this->connection === null) {
         $flags |= self::RELOAD_INIT;
     } else {
         $flags &= ~self::RELOAD_INIT;
     }
     $this->connection = $connection;
     $serverCfg = $this->connection->getConfig(null);
     $this->mainCfg = $serverCfg->getMainCfg();
     $this->translator = $this->mainCfg->getTranslator(get_called_class());
     $this->reload($flags);
     if ($this instanceof \Erebot\Interfaces\HelpEnabled) {
         $this->registerHelpMethod(\Erebot\CallableWrapper::wrap(array($this, 'getHelp')));
     }
 }