comparison vendor/phpunit/phpunit-mock-objects/tests/Builder/InvocationMockerTest.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /*
3 * This file is part of the phpunit-mock-objects package.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 use PHPUnit\Framework\TestCase;
12
13 class InvocationMockerTest extends TestCase
14 {
15 public function testWillReturnWithOneValue()
16 {
17 $mock = $this->getMockBuilder(stdClass::class)
18 ->setMethods(['foo'])
19 ->getMock();
20
21 $mock->expects($this->any())
22 ->method('foo')
23 ->willReturn(1);
24
25 $this->assertEquals(1, $mock->foo());
26 }
27
28 public function testWillReturnWithMultipleValues()
29 {
30 $mock = $this->getMockBuilder(stdClass::class)
31 ->setMethods(['foo'])
32 ->getMock();
33
34 $mock->expects($this->any())
35 ->method('foo')
36 ->willReturn(1, 2, 3);
37
38 $this->assertEquals(1, $mock->foo());
39 $this->assertEquals(2, $mock->foo());
40 $this->assertEquals(3, $mock->foo());
41 }
42
43 public function testWillReturnOnConsecutiveCalls()
44 {
45 $mock = $this->getMockBuilder(stdClass::class)
46 ->setMethods(['foo'])
47 ->getMock();
48
49 $mock->expects($this->any())
50 ->method('foo')
51 ->willReturnOnConsecutiveCalls(1, 2, 3);
52
53 $this->assertEquals(1, $mock->foo());
54 $this->assertEquals(2, $mock->foo());
55 $this->assertEquals(3, $mock->foo());
56 }
57
58 public function testWillReturnByReference()
59 {
60 $mock = $this->getMockBuilder(stdClass::class)
61 ->setMethods(['foo'])
62 ->getMock();
63
64 $mock->expects($this->any())
65 ->method('foo')
66 ->willReturnReference($value);
67
68 $this->assertSame(null, $mock->foo());
69 $value = 'foo';
70 $this->assertSame('foo', $mock->foo());
71 $value = 'bar';
72 $this->assertSame('bar', $mock->foo());
73 }
74 }