Skip to content

Commit

Permalink
Merge pull request #81 from ETSGlobal/remove-scope-request
Browse files Browse the repository at this point in the history
Remove scoped services
  • Loading branch information
graillus authored Apr 15, 2019
2 parents a2cf3cd + 6e97e93 commit 8fa6ce9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
<argument type="service" id="payment.ogone.client.token" />
</service>

<service id="payment.ogone.feedback_response" class="ETS\Payment\OgoneBundle\Response\FeedbackResponse" scope="request" public="false">
<argument type="service" id="request" />
<service id="payment.ogone.feedback_response" class="ETS\Payment\OgoneBundle\Response\FeedbackResponse" public="false">
<argument type="service" id="request_stack" />
</service>

<service id="payment.ogone" class="ETS\Payment\OgoneBundle\Service\Ogone" scope="request">
<service id="payment.ogone" class="ETS\Payment\OgoneBundle\Service\Ogone">
<argument type="service" id="payment.plugin_controller" />
<argument type="service" id="payment.ogone.hash.sha1out" />
<argument type="service" id="payment.ogone.feedback_response" />
Expand Down
20 changes: 11 additions & 9 deletions Response/FeedbackResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ETS\Payment\OgoneBundle\Response;

use Symfony\Component\HttpFoundation\Request;

use ETS\Payment\OgoneBundle\Hash\Sha1Out;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

/*
* Copyright 2013 ETSGlobal <ecs@etsglobal.org>
Expand Down Expand Up @@ -32,14 +32,16 @@ class FeedbackResponse extends AbstractResponse
private $values = array();
private $hash;

/**
* FeedbackResponse constructor
*
* @param Request $request
*/
public function __construct(Request $request)
public function __construct(RequestStack $requestStack)
{
foreach (array_merge($request->query->all(), $request->request->all()) as $receivedField => $value) {
$requestParams = [];

$request = $requestStack->getCurrentRequest();
if ($request instanceof Request) {
$requestParams = array_merge($request->query->all(), $request->request->all());
}

foreach ($requestParams as $receivedField => $value) {
if (Sha1Out::isAcceptableField($receivedField)) {
if ((string) $value !== '') {
$this->addValue($receivedField, $value);
Expand Down
7 changes: 6 additions & 1 deletion Tests/Plugin/OgoneGatewayPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ETS\Payment\OgoneBundle\Plugin\OgoneGatewayPluginMock;
use ETS\Payment\OgoneBundle\Response\FeedbackResponse;
use ETS\Payment\OgoneBundle\Test\RequestStubber;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* Copyright 2013 ETSGlobal <ecs@etsglobal.org>
Expand Down Expand Up @@ -326,8 +327,12 @@ public function testProcesses()
*/
public function testGetResponseReturnsFeedbackResponse(FinancialTransaction $transaction)
{
$requestStack = new RequestStack();
$requestStack->push($this->requestStubber->getStubbedRequest());
$feedbackResponse = new FeedbackResponse($requestStack);

$plugin = $this->createPluginMock();
$plugin->setFeedbackResponse(new FeedbackResponse($this->requestStubber->getStubbedRequest()));
$plugin->setFeedbackResponse($feedbackResponse);

$class = new \ReflectionClass($plugin);
$getResponseMethod = $class->getMethod('getResponse');
Expand Down
22 changes: 17 additions & 5 deletions Tests/Response/FeedbackResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@

use ETS\Payment\OgoneBundle\Response\FeedbackResponse;
use ETS\Payment\OgoneBundle\Test\RequestStubber;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RequestStack;

class FeedbackResponseTest extends \PHPUnit\Framework\TestCase
class FeedbackResponseTest extends TestCase
{
/**
* @var \ETS\Payment\OgoneBundle\Test\RequestStubber
* @var RequestStubber
*/
private $requestStubber;

/**
* @var RequestStack
*/
private $requestStack;

public function setUp()
{
$this->requestStubber = new RequestStubber(array(
Expand All @@ -24,6 +31,8 @@ public function setUp()
array('PAYID', null, false, 43),
array('SHASign', null, false, 'fzgzgzghz4648zh6z5h')
));

$this->requestStack = new RequestStack();
}

/**
Expand All @@ -32,7 +41,8 @@ public function setUp()
*/
public function testAddValueFieldAlreadySetEvenIfDifferentCase()
{
$feedbackResponse = new FeedbackResponse($this->requestStubber->getStubbedRequest());
$this->requestStack->push($this->requestStubber->getStubbedRequest());
$feedbackResponse = new FeedbackResponse($this->requestStack);

$class = new \ReflectionClass($feedbackResponse);
$addValueMethod = $class->getMethod('addValue');
Expand All @@ -47,7 +57,8 @@ public function testAddValueFieldAlreadySetEvenIfDifferentCase()
*/
public function testGetValueUnsetField()
{
$feedbackResponse = new FeedbackResponse($this->requestStubber->getStubbedRequest());
$this->requestStack->push($this->requestStubber->getStubbedRequest());
$feedbackResponse = new FeedbackResponse($this->requestStack);

$class = new \ReflectionClass($feedbackResponse);
$getValueMethod = $class->getMethod('getValue');
Expand All @@ -58,7 +69,8 @@ public function testGetValueUnsetField()

public function testConstructor()
{
$feedbackResponse = new FeedbackResponse($this->requestStubber->getStubbedRequest());
$this->requestStack->push($this->requestStubber->getStubbedRequest());
$feedbackResponse = new FeedbackResponse($this->requestStack);

$this->assertSame($this->requestStubber->getMapForParameterBags(false), $feedbackResponse->getValues());
$this->assertSame($this->requestStubber->getHashFromMap(), $feedbackResponse->getHash());
Expand Down

0 comments on commit 8fa6ce9

Please sign in to comment.