Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating dependencies #8

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
}
},
"require": {
"omnipay/common": "~2.0",
"vimeo/payment-gateway-logger": "^1.0",
"omnipay/common": "^3.0",
"vimeo/payment-gateway-logger": "dev-update-dependencies",
"ext-simplexml": "*"
},
"require-dev": {
"omnipay/tests": "~2.0"
"omnipay/tests": "^4.0"
}
}
55 changes: 51 additions & 4 deletions tests/Framework/MockPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,44 @@

namespace Omnipay\BlueSnap\Test\Framework;

use Guzzle\Http\Message\Response;
use Exception;
use InvalidArgumentException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MockPlugin extends \Guzzle\Plugin\Mock\MockPlugin
class MockPlugin implements EventSubscriberInterface
{
/** @var array Array of mock responses / exceptions */
protected $queue = array();

/** @var bool Whether or not to remove the plugin when the queue is empty */
protected $temporary = false;

/** @var array Array of requests that were mocked */
protected $received = array();

/** @var bool Whether or not to consume an entity body when a mock response is served */
protected $readBodies;

/**
* @param array $items Array of responses or exceptions to queue
* @param bool $temporary Set to TRUE to remove the plugin when the queue is empty
* @param bool $readBodies Set to TRUE to consume the entity body when a mock is served
*/
public function __construct(array $items = null, bool $temporary = false, bool $readBodies = false)
{
$this->readBodies = $readBodies;
$this->temporary = $temporary;
if ($items) {
foreach ($items as $item) {
if ($item instanceof \Exception) {
$this->addException($item);
} else {
$this->addResponse($item);
}
}
}
}

/**
* Get a mock response from a file
*
Expand All @@ -18,7 +51,7 @@ class MockPlugin extends \Guzzle\Plugin\Mock\MockPlugin
* @return Response|false
* @throws InvalidArgumentException if the file is not found
*/
public static function getMockFile($path, $substitutions = array())
public static function getMockFile(string $path, array $substitutions = array())
{
if (!file_exists($path)) {
throw new InvalidArgumentException('Unable to open mock file: ' . $path);
Expand Down Expand Up @@ -47,7 +80,7 @@ public static function getMockFile($path, $substitutions = array())
* @psalm-suppress FailedTypeResolution because we want run time checks
* @psalm-suppress RedundantConditionGivenDocblockType because we want run time checks on $response
*/
public function addResponse($response)
public function addResponse($response): self
{
if (!($response instanceof Response)) {
if (!is_string($response)) {
Expand All @@ -64,4 +97,18 @@ public function addResponse($response)

return $this;
}

/**
* Add an exception to the end of the queue
*
* @param Exception $e Exception to throw when the request is executed
*
* @return MockPlugin
*/
public function addException(Exception $e): self
{
$this->queue[] = $e;

return $this;
}
}