1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2017 Gerrit Addiks. |
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
7
|
|
|
* @license GPL-3.0 |
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Addiks\SymfonyGenerics\Tests\Unit\Arguments; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Addiks\SymfonyGenerics\Arguments\RequestArgument; |
15
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use InvalidArgumentException; |
18
|
|
|
|
19
|
|
|
final class RequestArgumentTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @test |
24
|
|
|
*/ |
25
|
|
|
public function shouldResolveRequestArgument() |
26
|
|
|
{ |
27
|
|
|
/** @var Request $request */ |
28
|
|
|
$request = $this->createMock(Request::class); |
29
|
|
|
$request->expects($this->once())->method('get')->with( |
|
|
|
|
30
|
|
|
$this->equalTo("some-request-key") |
31
|
|
|
)->willReturn("some-request-data"); |
32
|
|
|
|
33
|
|
|
/** @var RequestStack $requestStack */ |
34
|
|
|
$requestStack = $this->createMock(RequestStack::class); |
35
|
|
|
$requestStack->method('getCurrentRequest')->willReturn($request); |
|
|
|
|
36
|
|
|
|
37
|
|
|
$subject = new RequestArgument($requestStack, "some-request-key"); |
38
|
|
|
|
39
|
|
|
$this->assertEquals("some-request-data", $subject->resolve()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @test |
44
|
|
|
*/ |
45
|
|
View Code Duplication |
public function shouldRejectResolvingWithoutRequest() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$this->expectException(InvalidArgumentException::class); |
48
|
|
|
|
49
|
|
|
$requestStack = $this->createMock(RequestStack::class); |
50
|
|
|
$requestStack->method('getCurrentRequest')->willReturn(null); |
51
|
|
|
|
52
|
|
|
$argument = new RequestArgument($requestStack, "some-request-key"); |
|
|
|
|
53
|
|
|
$argument->resolve(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.