1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stfalcon\Bundle\EventBundle\Tests\Controller; |
4
|
|
|
|
5
|
|
|
use Application\Bundle\DefaultBundle\Controller\InterkassaController; |
|
|
|
|
6
|
|
|
use Application\Bundle\DefaultBundle\Controller\WayForPayController; |
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\Registry; |
8
|
|
|
use Prophecy\Argument; |
9
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\Payment; |
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
11
|
|
|
|
12
|
|
|
class WayForPayControllerTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var \Prophecy\Prophet |
16
|
|
|
*/ |
17
|
|
|
protected $prophet; |
18
|
|
|
|
19
|
|
|
protected function setup() |
20
|
|
|
{ |
21
|
|
|
$this->prophet = new \Prophecy\Prophet(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function tearDown() |
25
|
|
|
{ |
26
|
|
|
$this->prophet->checkPredictions(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testPaymentSetPaid() |
30
|
|
|
{ |
31
|
|
|
$request = $this->prophet->prophesize('Symfony\Component\HttpFoundatio\Request'); |
32
|
|
|
$request->willExtend('Symfony\Component\HttpFoundation\Request'); |
33
|
|
|
|
34
|
|
|
$wayforpayService = $this->prophet->prophesize('Application\Bundle\DefaultBundle\Service\WayForPayService'); |
35
|
|
|
$paymentService = $this->prophet->prophesize('Application\Bundle\DefaultBundle\Service\PaymentService'); |
36
|
|
|
|
37
|
|
|
$container = $this->prophet->prophesize('Symfony\Component\DependencyInjection\Container'); |
38
|
|
|
$doctrine = $this->prophet->prophesize('Doctrine\Bundle\DoctrineBundle\Registry'); |
39
|
|
|
$em = $this->prophet->prophesize('Doctrine\ORM\EntityManager'); |
40
|
|
|
$paymentRepository = $this->prophet->prophesize('Stfalcon\Bundle\EventBundle\Repository\PaymentRepository'); |
41
|
|
|
$payment = $this->prophet->prophesize('Stfalcon\Bundle\EventBundle\Entity\Payment'); |
42
|
|
|
$logger = $this->prophet->prophesize('Symfony\Bridge\Monolog\Logger'); |
43
|
|
|
$referralService = $this->prophet->prophesize('Application\Bundle\DefaultBundle\Service\ReferralService'); |
44
|
|
|
$session = $this->prophet->prophesize('Symfony\Component\HttpFoundation\Session\Session'); |
45
|
|
|
|
46
|
|
|
$request->getContent()->shouldBeCalled() |
47
|
|
|
->willReturn('{"orderNo":"1"}'); |
48
|
|
|
|
49
|
|
|
$doctrine->getRepository('StfalconEventBundle:Payment') |
50
|
|
|
->shouldBeCalled() |
51
|
|
|
->willReturn($paymentRepository); |
52
|
|
|
|
53
|
|
|
$doctrine->getManager()->willReturn($em); |
54
|
|
|
|
55
|
|
|
$payment->isPending()->shouldBeCalled()->willReturn(true); |
56
|
|
|
$payment->setPaidWithGate(Payment::WAYFORPAY_GATE)->shouldBeCalled(); |
57
|
|
|
|
58
|
|
|
$session->set('way_for_pay_payment', 1)->shouldBeCalled()->willReturn(null); |
59
|
|
|
|
60
|
|
|
$referralService->chargingReferral($payment)->shouldBeCalled()->willReturn(null); |
61
|
|
|
$referralService->utilizeBalance($payment)->shouldBeCalled()->willReturn(null); |
62
|
|
|
|
63
|
|
|
$container->has('doctrine')->willReturn(true); |
64
|
|
|
$container->get('doctrine')->willReturn($doctrine); |
65
|
|
|
|
66
|
|
|
$paymentRepository->findOneBy(Argument::any())->willReturn($payment); |
67
|
|
|
|
68
|
|
|
$container->get('app.way_for_pay.service')->willReturn($wayforpayService); |
69
|
|
|
$container->get('stfalcon_event.referral.service')->willReturn($referralService); |
70
|
|
|
$container->get('stfalcon_event.payment.service')->willReturn($paymentService); |
71
|
|
|
$container->get('logger')->willReturn($logger); |
72
|
|
|
$container->get('session')->willReturn($session); |
73
|
|
|
|
74
|
|
|
$wayforpayService->checkPayment(Argument::any(), Argument::any()) |
75
|
|
|
->willReturn(true) |
76
|
|
|
->shouldBeCalled(); |
77
|
|
|
$wayforpayService->saveResponseLog($payment, Argument::any(), 'set paid')->willReturn(null) |
78
|
|
|
->shouldBeCalled(); |
79
|
|
|
$wayforpayService->getResponseOnServiceUrl(Argument::any())->willReturn([]) |
80
|
|
|
->shouldBeCalled(); |
81
|
|
|
$em->flush()->shouldBeCalled(); |
82
|
|
|
|
83
|
|
|
$wayforpayController = new WayForPayController(); |
84
|
|
|
$wayforpayController->setContainer($container->reveal()); |
85
|
|
|
$result = $wayforpayController->serviceInteractionAction($request->reveal()); |
86
|
|
|
|
87
|
|
|
$this->assertEquals(200, $result->getStatusCode()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testPaymentNotFound() |
91
|
|
|
{ |
92
|
|
|
$request = $this->prophet->prophesize('Symfony\Component\HttpFoundatio\Request'); |
93
|
|
|
$request->willExtend('Symfony\Component\HttpFoundation\Request'); |
94
|
|
|
|
95
|
|
|
$container = $this->prophet->prophesize('Symfony\Component\DependencyInjection\Container'); |
96
|
|
|
$doctrine = $this->prophet->prophesize('Doctrine\Bundle\DoctrineBundle\Registry'); |
97
|
|
|
$em = $this->prophet->prophesize('Doctrine\ORM\EntityManager'); |
98
|
|
|
$paymentRepository = $this->prophet->prophesize('Stfalcon\Bundle\EventBundle\Repository\PaymentRepository'); |
99
|
|
|
$logger = $this->prophet->prophesize('Symfony\Bridge\Monolog\Logger'); |
100
|
|
|
$wayforpayService = $this->prophet->prophesize('Application\Bundle\DefaultBundle\Service\WayForPayService'); |
101
|
|
|
|
102
|
|
|
$wayforpayService->saveResponseLog(null, Argument::any(), Argument::any())->shouldBeCalled(); |
103
|
|
|
|
104
|
|
|
$request->getContent()->shouldBeCalled() |
105
|
|
|
->willReturn('{"orderNo":"1"}'); |
106
|
|
|
|
107
|
|
|
$doctrine->getManager()->willReturn($em); |
108
|
|
|
$doctrine->getRepository('StfalconEventBundle:Payment') |
109
|
|
|
->shouldBeCalled() |
110
|
|
|
->willReturn($paymentRepository); |
111
|
|
|
$logger->addCritical(Argument::any())->shouldBeCalled(); |
112
|
|
|
|
113
|
|
|
$container->get('app.way_for_pay.service')->willReturn($wayforpayService); |
114
|
|
|
$container->has('doctrine')->willReturn(true); |
115
|
|
|
$container->get('doctrine')->willReturn($doctrine); |
116
|
|
|
$container->get('logger')->willReturn($logger); |
117
|
|
|
|
118
|
|
|
$paymentRepository->findOneBy(Argument::any())->willReturn(null); |
119
|
|
|
|
120
|
|
|
$wayforpayController = new WayForPayController(); |
121
|
|
|
$wayforpayController->setContainer($container->reveal()); |
122
|
|
|
$result = $wayforpayController->serviceInteractionAction($request->reveal()); |
123
|
|
|
|
124
|
|
|
$this->assertEquals(400, $result->getStatusCode()); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths