|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/* |
| 3 | + * This file is part of PHPUnit. |
| 4 | + * |
| 5 | + * (c) Sebastian Bergmann <[email protected]> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | +namespace PHPUnit\TestFixture\Issue5891; |
| 11 | + |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | + |
| 14 | +final class Issue5891Test extends TestCase |
| 15 | +{ |
| 16 | + public function testVariadicParam(): void |
| 17 | + { |
| 18 | + $variadicParam = $this->createMock(VariadicParam::class); |
| 19 | + $variadicParam |
| 20 | + ->method('foo') |
| 21 | + ->with($this->callback(static function (...$items): bool |
| 22 | + { |
| 23 | + self::assertSame([1], $items); // should be "self::assertSame([1, 2, 3], $items);" |
| 24 | + |
| 25 | + return true; |
| 26 | + })); |
| 27 | + |
| 28 | + $variadicParam->foo(1, 2, 3); |
| 29 | + } |
| 30 | + |
| 31 | + public function testTwoParametersAndVariadicParam(): void |
| 32 | + { |
| 33 | + $twoParametersAndVariadicParam = $this->createMock(TwoParametersAndVariadicParam::class); |
| 34 | + $twoParametersAndVariadicParam |
| 35 | + ->method('foo') |
| 36 | + ->with($this->callback(static function ($head, ...$tail): bool |
| 37 | + { |
| 38 | + self::assertSame('1st', $head); |
| 39 | + self::assertSame([], $tail); // should be "self::assertSame(['2nd', '3rd', '4th'], $tail);" |
| 40 | + |
| 41 | + return true; |
| 42 | + })); |
| 43 | + |
| 44 | + $twoParametersAndVariadicParam->foo('1st', '2nd', '3rd', '4th'); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +interface VariadicParam |
| 49 | +{ |
| 50 | + public function foo(int ...$items): void; |
| 51 | +} |
| 52 | +interface TwoParametersAndVariadicParam |
| 53 | +{ |
| 54 | + public function foo(string $first, string $second, string ...$rest): void; |
| 55 | +} |
0 commit comments