Beispiel #1
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();
 }