|
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\RequestPayloadArgument; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
17
|
|
|
use InvalidArgumentException; |
|
18
|
|
|
|
|
19
|
|
|
final class RequestPayloadArgumentTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @test |
|
24
|
|
|
*/ |
|
25
|
|
|
public function shouldResolveRequestPayloadContent() |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var Request $request */ |
|
28
|
|
|
$request = $this->createMock(Request::class); |
|
29
|
|
|
$request->expects($this->once())->method('getContent')->with( |
|
|
|
|
|
|
30
|
|
|
$this->equalTo(false) |
|
31
|
|
|
)->willReturn("some-payload-content"); |
|
32
|
|
|
|
|
33
|
|
|
$requestStack = $this->createMock(RequestStack::class); |
|
34
|
|
|
$requestStack->method('getCurrentRequest')->willReturn($request); |
|
35
|
|
|
|
|
36
|
|
|
$argument = new RequestPayloadArgument($requestStack); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** @var mixed $actualResult */ |
|
39
|
|
|
$actualResult = $argument->resolve(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals("some-payload-content", $actualResult); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @test |
|
46
|
|
|
*/ |
|
47
|
|
View Code Duplication |
public function shouldRejectResolvingWithoutRequest() |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
50
|
|
|
|
|
51
|
|
|
$requestStack = $this->createMock(RequestStack::class); |
|
52
|
|
|
$requestStack->method('getCurrentRequest')->willReturn(null); |
|
53
|
|
|
|
|
54
|
|
|
$argument = new RequestPayloadArgument($requestStack); |
|
|
|
|
|
|
55
|
|
|
$argument->resolve(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
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.