1<?php 2class Framework_MockObject_Builder_InvocationMockerTest extends PHPUnit_Framework_TestCase 3{ 4 public function testWillReturnWithOneValue() 5 { 6 $mock = $this->getMockBuilder(stdClass::class) 7 ->setMethods(['foo']) 8 ->getMock(); 9 10 $mock->expects($this->any()) 11 ->method('foo') 12 ->willReturn(1); 13 14 $this->assertEquals(1, $mock->foo()); 15 } 16 17 public function testWillReturnWithMultipleValues() 18 { 19 $mock = $this->getMockBuilder(stdClass::class) 20 ->setMethods(['foo']) 21 ->getMock(); 22 23 $mock->expects($this->any()) 24 ->method('foo') 25 ->willReturn(1, 2, 3); 26 27 $this->assertEquals(1, $mock->foo()); 28 $this->assertEquals(2, $mock->foo()); 29 $this->assertEquals(3, $mock->foo()); 30 } 31 32 public function testWillReturnOnConsecutiveCalls() 33 { 34 $mock = $this->getMockBuilder(stdClass::class) 35 ->setMethods(['foo']) 36 ->getMock(); 37 38 $mock->expects($this->any()) 39 ->method('foo') 40 ->willReturnOnConsecutiveCalls(1, 2, 3); 41 42 $this->assertEquals(1, $mock->foo()); 43 $this->assertEquals(2, $mock->foo()); 44 $this->assertEquals(3, $mock->foo()); 45 } 46 47 public function testWillReturnByReference() 48 { 49 $mock = $this->getMockBuilder(stdClass::class) 50 ->setMethods(['foo']) 51 ->getMock(); 52 53 $mock->expects($this->any()) 54 ->method('foo') 55 ->willReturnReference($value); 56 57 $this->assertSame(null, $mock->foo()); 58 $value = 'foo'; 59 $this->assertSame('foo', $mock->foo()); 60 $value = 'bar'; 61 $this->assertSame('bar', $mock->foo()); 62 } 63} 64