Test Failed
Push — develop ( 6098b1...78195a )
by Reüel
02:46
created

GatewaysTest::http_api_debug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 5
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect;
4
5
use WP_Http;
0 ignored issues
show
Bug introduced by
The type WP_Http 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...
6
use WP_UnitTestCase;
0 ignored issues
show
Bug introduced by
The type WP_UnitTestCase 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...
7
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\MultiSafepay;
8
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Config;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Pronamic\WordPress\Pay\G...iSafepay\Connect\Config. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
10
class GatewaysTest extends WP_UnitTestCase {
11
	/**
12
	 * Pre HTTP request
13
	 *
14
	 * @link https://github.com/WordPress/WordPress/blob/3.9.1/wp-includes/class-http.php#L150-L164
15
	 * @return string
16
	 */
17
	public function pre_http_request( $preempt, $request, $url ) {
18
		$response = file_get_contents( dirname( __FILE__ ) . '/Mock/gateways-response.http' );
19
20
		$processed_response = WP_Http::processResponse( $response );
21
22
		$processed_headers = WP_Http::processHeaders( $processed_response['headers'], $url );
23
24
		$processed_headers['body'] = $processed_response['body'];
25
26
		return $processed_headers;
27
	}
28
29
	public function http_api_debug( $response, $context, $class, $args, $url ) {
30
31
	}
32
33
	public function test_init() {
34
		// Mock HTTP request
35
		//add_action( 'http_api_debug', array( $this, 'http_api_debug' ), 10, 5 );
36
		add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 );
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
		/** @scrutinizer ignore-call */ 
37
  add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 );
Loading history...
37
38
		// Config
39
		$config = new Config();
40
41
		$config->mode       = getenv( 'MULTISAFEPAY_MODE' );
42
		$config->account_id = getenv( 'MULTISAFEPAY_ACCOUNT_ID' );
43
		$config->site_id    = getenv( 'MULTISAFEPAY_SITE_ID' );
44
		$config->site_code  = getenv( 'MULTISAFEPAY_SECURE_CODE' );
45
46
		if ( Gateway::MODE_TEST === $config->mode ) {
47
			$config->api_url = MultiSafepay::API_TEST_URL;
48
		} else {
49
			$config->api_url = MultiSafepay::API_PRODUCTION_URL;
50
		}
51
52
		// Client
53
		$client = new Client();
54
55
		$client->api_url = $config->api_url;
56
57
		// Merchant
58
		$merchant = new Merchant();
59
60
		$merchant->account          = $config->account_id;
61
		$merchant->site_id          = $config->site_id;
62
		$merchant->site_secure_code = $config->site_code;
63
64
		// Customer
65
		$customer = new Customer();
66
67
		$customer->locale = get_locale();
0 ignored issues
show
Bug introduced by
The function get_locale was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
		$customer->locale = /** @scrutinizer ignore-call */ get_locale();
Loading history...
68
69
		// Gateways
70
		$gateways = $client->get_gateways( $merchant, $customer );
71
72
		$expected = array(
73
			'VISA'       => 'Visa',
74
			'GIROPAY'    => 'Giropay',
75
			'PAYAFTER'   => 'Pay After Delivery',
76
			'IDEAL'      => 'iDEAL',
77
			'DIRECTBANK' => 'SOFORT Banking',
78
			'BANKTRANS'  => 'Wire Transfer',
79
			'MASTERCARD' => 'MasterCard',
80
		);
81
82
		$this->assertEquals( $expected, $gateways );
83
	}
84
}
85