コード例 #1
0
 public function testPath()
 {
     $builder = new Builder();
     $builder->expects($this->exactly(2))->with('first method call matcher');
     $builder->expects($this->once())->with('second method call matcher');
     $builder->expects($this->exactly(2))->with('third method call matcher');
     $matcher = $builder->matcher();
     $invocation = $this->createInvocation(['first method call matcher']);
     $matcher->matches($invocation);
     $matcher->invoked($invocation);
     $invocation = $this->createInvocation(['first method call matcher']);
     $matcher->matches($invocation);
     $matcher->invoked($invocation);
     $invocation = $this->createInvocation(['second method call matcher']);
     $matcher->matches($invocation);
     $matcher->invoked($invocation);
     $invocation = $this->createInvocation(['third method call matcher']);
     $matcher->matches($invocation);
     $matcher->invoked($invocation);
     $invocation = $this->createInvocation(['third method call matcher']);
     $matcher->matches($invocation);
     $matcher->invoked($invocation);
     $matcher->verify();
     $this->assertSame('', $matcher->toString());
 }
コード例 #2
0
 /**
  * @expectedException        \PHPUnit_Framework_ExpectationFailedException
  * @expectedExceptionMessage wrong argument
  */
 public function testWrongArguments()
 {
     $builder = new Builder();
     $builder->expects($this->exactly(2))->with('first method call matcher')->willReturnSelf();
     $builder->expects($this->once())->with('second method call matcher')->willReturn('second return');
     $dummy = $this->getMock(\stdClass::class, ['test']);
     $dummy->expects($builder->matcher())->method('test')->will($builder->mapper());
     $this->assertSame($dummy, $dummy->test('first method call matcher'));
     $this->assertSame($dummy, $dummy->test('first method call matcher'));
     $this->assertSame('second return', $dummy->test('wrong argument'));
 }
コード例 #3
0
 /**
  * @expectedException        \PHPUnit_Framework_ExpectationFailedException
  * @expectedExceptionMessage The invocation at index 2 is not defined.
  */
 public function testPath()
 {
     $builder = new Builder();
     $builder->expects($this->once())->with('first method call matcher');
     $builder->expects($this->once())->with('second method call matcher');
     $matcher = $builder->matcher();
     $invocation = $this->createInvocation(['first method call matcher']);
     $matcher->matches($invocation);
     $matcher->invoked($invocation);
     $invocation = $this->createInvocation(['second method call matcher']);
     $matcher->matches($invocation);
     $matcher->invoked($invocation);
     $invocation = $this->createInvocation(['random']);
     $matcher->matches($invocation);
     $matcher->invoked($invocation);
     $matcher->verify();
 }
コード例 #4
0
 public function testSolution()
 {
     $builder = new Builder();
     $builder->expects($this->exactly(2))->with(new DummyValueHolder('aaa'))->willReturnSelf();
     $builder->expects($this->once())->with('second method call matcher')->willReturn('second return');
     $builder->expects($this->exactly(2))->with('third method call matcher')->willReturn('third return');
     $dummy = $this->getMock(\stdClass::class, ['test']);
     $dummy->expects($builder->matcher())->method('test')->will($builder->mapper());
     $this->assertSame($dummy, $dummy->test(new DummyValueHolder('aaa')));
     $this->assertSame($dummy, $dummy->test(new DummyValueHolder('aaa')));
     $this->assertSame('second return', $dummy->test('second method call matcher'));
     $this->assertSame('third return', $dummy->test('third method call matcher'));
     $this->assertSame('third return', $dummy->test('third method call matcher'));
 }