Esempio n. 1
0
 public function testMapIterator()
 {
     $callback = new MockeryCallableMock();
     $iterator = new ArrayIterator(['key' => 'value', 'second' => 'monkey', 'third']);
     $mapIterator = new MapIterator($iterator, $callback);
     $callback->shouldBeCalled()->with('value', 'key', $iterator)->andReturn('modified');
     $callback->shouldBeCalled()->with('monkey', 'second', $iterator)->andReturn('fish');
     $callback->shouldBeCalled()->with('third', 0, $iterator)->andReturn('cake');
     $results = iterator_to_array($mapIterator, true);
     static::assertEquals(['key' => 'modified', 'second' => 'fish', 'cake'], $results);
 }
Esempio n. 2
0
 /**
  * @expectedException \Tebru\Executioner\Exception\FailedException
  */
 public function testWithLogger()
 {
     $callable = new MockeryCallableMock();
     $exception = new Exception();
     $callable->shouldBeCalled()->times(1)->withNoArgs()->andThrow($exception);
     $callable->shouldBeCalled()->times(1)->withNoArgs()->andReturn(true);
     $logger = Mockery::mock(LoggerInterface::class);
     $dispatchException = new Exception();
     $logger->shouldReceive('info')->times(1)->with('Attempting "test" with 1 attempts to go. (uq)');
     $logger->shouldReceive('info')->times(1)->with('Attempting "test" with 0 attempts to go. (uq)');
     $logger->shouldReceive('info')->times(1)->with('Completed attempt for "test" (uq)', ['result' => true])->andThrow($dispatchException);
     $logger->shouldReceive('notice')->times(1)->with('Failed attempt for "test", retrying. 0 attempts remaining (uq)', ['exception' => $exception]);
     $logger->shouldReceive('error')->times(1)->with('Could not complete "test" (uq)', ['exception' => $dispatchException]);
     $loggerSubscriber = new LoggerSubscriber('test', $logger, 'uq');
     $dispatcher = Mockery::mock(EventDispatcher::class);
     $dispatcher->makePartial();
     $dispatcher->shouldReceive('dispatch')->times(5)->passthru();
     $dispatcher->shouldReceive('addSubscriber')->times(1)->with($loggerSubscriber)->passthru();
     $executor = new Executor();
     $executor->setDispatcher($dispatcher);
     $executor->addSubscriber($loggerSubscriber);
     $executor->execute(1, $callable);
 }
Esempio n. 3
0
 private function assertFailureCalled($times, RuleInterface $rule, Node $node, CallbackVisitor $visitor)
 {
     $callback = new MockeryCallableMock();
     $callback->shouldBeCalled()->with($rule, $node, $this->file)->times($times);
     $visitor->onNodeFailure($callback);
     $visitor->enterNode($node);
 }
 public function testReturning()
 {
     $mock = new MockeryCallableMock();
     $mock->shouldBeCalled()->andReturn('foo');
     $this->assertSame('foo', $mock());
 }
 public function testParseCallback()
 {
     $this->parse->shouldBeCalled()->with('text')->andReturn('first', 'second');
     static::assertEquals('first', $this->parser->parseValue('text'));
     static::assertEquals('second', $this->parser->parseValue('text'));
 }