Test Failed
Push — develop ( e9d4b5...08d3b2 )
by Remco
04:40
created

tests/src/GatewaysTest.php (2 issues)

Labels
Severity
1
<?php
2
/**
3
 * Gateways test.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay
9
 */
10
11
namespace Pronamic\WordPress\Pay;
12
13
/**
14
 * Gateways test.
15
 *
16
 * @author Reüel van der Steege
17
 * @version 1.0.0
18
 */
19
class GatewaysTest extends \PHPUnit_Framework_TestCase {
20
	/**
21
	 * Test for gateway integrations array.
22
	 */
23
	public function test_gateway_integrations_type() {
24
		$integrations = pronamic_pay_gateway_integrations();
0 ignored issues
show
The function pronamic_pay_gateway_integrations 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

24
		$integrations = /** @scrutinizer ignore-call */ pronamic_pay_gateway_integrations();
Loading history...
25
26
		$is_array = is_array( $integrations );
27
28
		$this->assertTrue( $is_array );
29
	}
30
31
	/**
32
	 * Test for valid gateway integrations.
33
	 *
34
	 * @param string|array $gateway Fully qualified gateway class name or array with class name and callback.
35
	 *
36
	 * @dataProvider gateways_provider
37
	 * @depends test_gateway_integrations_type
38
	 */
39
	public function test_valid_gateway_integrations( $gateway ) {
40
		// Assert type.
41
		$valid_types = array( 'string', 'array' );
42
43
		$this->assertContains( gettype( $gateway ), $valid_types );
44
45
		// Assert required array keys and callback closure.
46
		if ( is_array( $gateway ) ) {
47
			$this->assertArrayHasKey( 'class', $gateway );
48
			$this->assertArrayHasKey( 'callback', $gateway );
49
50
			$actual = ( isset( $gateway['callback'] ) ? $gateway['callback'] : null );
51
52
			$this->assertInstanceOf( 'Closure', $actual );
53
		}
54
	}
55
56
	/**
57
	 * Test gateway integrations callbacks.
58
	 *
59
	 * @param string|array $gateway Fully qualified gateway class name or array with class name and callback.
60
	 *
61
	 * @dataProvider gateways_provider
62
	 * @depends test_gateway_integrations_type
63
	 */
64
	public function test_gateway_integrations_callback( $gateway ) {
65
		if ( ! is_array( $gateway ) ) {
66
			return;
67
		}
68
69
		if ( ! isset( $gateway['class'], $gateway['callback'] ) ) {
70
			return;
71
		}
72
73
		$integration = new $gateway['class']();
74
75
		$this->assertInstanceOf( __NAMESPACE__ . '\Gateways\Common\AbstractIntegration', $integration );
76
77
		call_user_func( $gateway['callback'], $integration );
78
79
		$this->assertNotEmpty( $integration->get_id() );
80
		$this->assertNotEmpty( $integration->get_name() );
81
	}
82
83
	/**
84
	 * Gateways data provider.
85
	 *
86
	 * @return array
87
	 */
88
	public function gateways_provider() {
89
		$data = array();
90
91
		$gateways = pronamic_pay_gateway_integrations();
0 ignored issues
show
The function pronamic_pay_gateway_integrations 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

91
		$gateways = /** @scrutinizer ignore-call */ pronamic_pay_gateway_integrations();
Loading history...
92
93
		foreach ( $gateways as $gateway ) {
94
			$data[] = array( $gateway );
95
		}
96
97
		return $data;
98
	}
99
}
100