forked from Payum/PayumBundle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NotifyControllerTest.php
57 lines (47 loc) · 1.77 KB
/
NotifyControllerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Payum\Bundle\PayumBundle\Tests\Controller;
use Payum\Bundle\PayumBundle\Controller\NotifyController;
use Payum\Core\GatewayInterface;
use Payum\Core\Payum;
use Payum\Core\Request\Notify;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class NotifyControllerTest extends TestCase
{
/**
* @test
*/
public function shouldBeSubClassOfController(): void
{
$rc = new \ReflectionClass(NotifyController::class);
$this->assertTrue($rc->isSubclassOf(AbstractController::class));
}
/**
* @test
*/
public function shouldExecuteNotifyRequestOnDoUnsafe(): void
{
$request = Request::create('/');
$request->query->set('gateway', 'theGatewayName');
$gatewayMock = $this->createMock(GatewayInterface::class);
$gatewayMock
->expects($this->any())
->method('execute')
->with($this->isInstanceOf(Notify::class));
$registryMock = $this->createMock(Payum::class);
$registryMock
->expects($this->any())
->method('getGateway')
->with('theGatewayName')
->will($this->returnValue($gatewayMock));
$controller = new NotifyController();
$controller->setContainer(new ServiceLocator(['payum' => function () use ($registryMock) { return $registryMock; }]));
$response = $controller->doUnsafeAction($request);
$this->assertInstanceOf(Response::class, $response);
$this->assertEquals(204, $response->getStatusCode());
$this->assertEquals('', $response->getContent());
}
}