public function testGetRunner()
 {
     $this->given($this->getMockGenerator()->orphanize('__construct'))->given($mockRunner = new mockRunner())->given($mockLogger = new mockLogger())->given($mockRunner->setLogger($mockLogger))->given($mockContainer = new mockContainer())->given($this->calling($mockContainer)->get = function ($service) use($mockRunner, $mockLogger) {
         switch ($service) {
             case 'atipik_hoa_web_socket.logger':
                 return $mockLogger;
             case 'atipik_hoa_web_socket.runner':
                 return $mockRunner;
         }
     })->given($mockInput = new mockInput())->given($mockOutput = new mockOutput())->given($command = new TestedClass())->given($command->setContainer($mockContainer))->object($runner = $command->getRunner($mockInput, $mockOutput))->isIdenticalTo($mockRunner)->object($runner->getLogger()->getOutput())->isIdenticalTo($mockOutput)->array($runner->getGroups())->isEmpty()->given($this->calling($mockInput)->getOption = $groups = array('foo', 'bar'))->object($runner = $command->getRunner($mockInput, $mockOutput))->isIdenticalTo($mockRunner)->array($runner->getGroups())->isEqualTo($groups);
 }
Example #2
0
 public function testOnEvent()
 {
     $this->given($logger = new mockLogger())->given($logger->setOutput(new mockOutput()))->given($runner = new mockTestedClass($this->generateMockWebSocketServer(), $logger))->given($runner->addModule($module1 = new mocktestModule1()))->given($runner->addModule($module2 = new mocktestModule2()))->given($runner->loadEvents())->given($mockBucket = new mockBucket())->given($this->calling($mockBucket)->getData = $rawData = uniqid())->given($this->calling($mockBucket)->getSource = $mockSource = new mockWebSocketServer())->given($this->getMockGenerator()->orphanize('__construct'))->given($this->calling($mockSource)->getConnection = $mockConnection = new \mock\Hoa\Socket\Connection())->given($this->getMockGenerator()->orphanize('__construct'))->given($this->calling($mockConnection)->getCurrentNode = $mockNode = new \mock\Hoa\Socket\Node())->given($this->calling($mockNode)->getId = $nodeId = uniqid())->assert('No log')->if($runner->onEvent(uniqid(), $mockBucket, null, false))->mock($logger)->call('log')->never()->assert('Log')->if($runner->onEvent($event = uniqid(), $mockBucket))->mock($logger)->call('log')->once()->withIdenticalArguments('%s - %s (%d) > %s + %s', $nodeId, $event, 0, json_encode($rawData), json_encode(null))->once()->assert('Log with array raw data')->given($this->calling($mockBucket)->getData = $rawData = array(uniqid() => uniqid(), uniqid() => uniqid()))->if($runner->onEvent($event = uniqid(), $mockBucket))->mock($logger)->call('log')->once()->withIdenticalArguments('%s - %s (%d) > %s + %s', $nodeId, $event, 0, json_encode($rawData, JSON_PRETTY_PRINT), json_encode(null, JSON_PRETTY_PRINT))->once()->assert('Single event')->if($runner->onEvent('event1', $mockBucket))->mock($module1)->call('setBucket')->once()->withIdenticalArguments($mockBucket)->once()->call('onEvent1')->once()->withIdenticalArguments(null)->once()->assert('Double event')->if($runner->onEvent('event2', $mockBucket))->mock($module1)->call('setBucket')->once()->withIdenticalArguments($mockBucket)->once()->call('onEvent2')->once()->withIdenticalArguments(null)->once()->mock($module2)->call('setBucket')->once()->withIdenticalArguments($mockBucket)->once()->call('onEvent2')->once()->withIdenticalArguments(null)->once()->assert('Additionnal data')->if($runner->onEvent('event1', $mockBucket, $additionnalData = uniqid()))->mock($module1)->call('setBucket')->once()->withIdenticalArguments($mockBucket)->once()->call('onEvent1')->once()->withIdenticalArguments($additionnalData)->once();
 }