Failed Conditions
Push — develop ( 370527...a887b3 )
by Reüel
06:34
created

GatewayTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 26
c 2
b 0
f 0
dl 0
loc 55
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pre_http_request() 0 10 1
A test_init() 0 36 3
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay;
4
5
use WP_Http;
6
use WP_UnitTestCase;
7
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\MultiSafepay;
8
9
class GatewayTest extends WP_UnitTestCase {
10
	/**
11
	 * Pre HTTP request
12
	 *
13
	 * @link https://github.com/WordPress/WordPress/blob/3.9.1/wp-includes/class-http.php#L150-L164
14
	 * @return string
15
	 */
16
	public function pre_http_request( $preempt, $request, $url ) {
17
		$response = file_get_contents( dirname( dirname( __FILE__ ) ) . '/Mock/ideal-issuers-response.http' );
18
19
		$processed_response = WP_Http::processResponse( $response );
20
21
		$processed_headers = WP_Http::processHeaders( $processed_response['headers'], $url );
22
23
		$processed_headers['body'] = $processed_response['body'];
24
25
		return $processed_headers;
26
	}
27
28
	public function test_init() {
29
		// Mock HTTP request
30
		//add_action( 'http_api_debug', array( $this, 'http_api_debug' ), 10, 5 );
31
		add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 );
32
33
		// Other
34
		$config = new Config();
35
36
		$config->mode       = getenv( 'MULTISAFEPAY_MODE' );
37
		$config->account_id = getenv( 'MULTISAFEPAY_ACCOUNT_ID' );
38
		$config->site_id    = getenv( 'MULTISAFEPAY_SITE_ID' );
39
		$config->site_code  = getenv( 'MULTISAFEPAY_SECURE_CODE' );
40
41
		if ( Gateway::MODE_TEST === $config->mode ) {
42
			$config->api_url = MultiSafepay::API_TEST_URL;
43
		} else {
44
			$config->api_url = MultiSafepay::API_PRODUCTION_URL;
45
		}
46
47
		$gateway = new Gateway( $config );
48
49
		try {
50
			$issuers = $gateway->get_issuers();
51
		} catch ( \Pronamic\WordPress\Pay\GatewayException $e ) {
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\GatewayException was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
52
			$issuers = null;
53
		}
54
55
		$expected = array(
56
			array(
57
				'options' => array(
58
					'3151' => 'Test bank',
59
				),
60
			),
61
		);
62
63
		$this->assertEquals( $expected, $issuers );
64
	}
65
}
66