Passed
Push — main ( 061772...28b955 )
by Remco
07:49 queued 12s
created

IntegrationTest::test_config_post()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
1
<?php
2
/**
3
 * Integration test
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Payvision
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Payvision;
12
13
/**
14
 * Integration test
15
 *
16
 * @author  Remco Tolsma
17
 * @version 1.0.0
18
 * @since   1.0.0
19
 */
20
class IntegrationTest extends \WP_UnitTestCase {
21
	/**
22
	 * Integration.
23
	 *
24
	 * @var Integration
25
	 */
26
	private $integration;
27
28
	/**
29
	 * Setup.
30
	 */
31
	public function setUp() {
32
		parent::setUp();
33
34
		$this->integration = new Integration();
35
	}
36
37
	/**
38
	 * Test settings fields.
39
	 */
40
	public function test_settings_fields() {
41
		$fields = $this->integration->get_settings_fields();
42
43
		$this->assertCount( 4, $fields );
44
	}
45
46
	/**
47
	 * Test config / gateway.
48
	 */
49
	public function test_config_post() {
50
		$post_id = $this->factory->post->create();
0 ignored issues
show
Documentation introduced by
The property factory does not exist on object<Pronamic\WordPres...vision\IntegrationTest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
51
52
		\update_post_meta( $post_id, '_pronamic_gateway_mode', Gateway::MODE_TEST );
53
		\update_post_meta( $post_id, '_pronamic_gateway_payvision_business_id', '123456' );
54
		\update_post_meta( $post_id, '_pronamic_gateway_payvision_username', 'Test' );
55
		\update_post_meta( $post_id, '_pronamic_gateway_payvision_password', '●●●●●●●●' );
56
		\update_post_meta( $post_id, '_pronamic_gateway_payvision_store_id', '1' );
57
58
		$config = $this->integration->get_config( $post_id );
59
60
		$this->assertInstanceOf( Config::class, $config );
61
		$this->assertEquals( '123456', $config->get_business_id() );
62
		$this->assertEquals( '1', $config->get_store_id() );
63
		$this->assertEquals(
64
			'{"mode":"test","business_id":"123456","username":"Test","password":"\u25cf\u25cf\u25cf\u25cf\u25cf\u25cf\u25cf\u25cf","store_id":"1"}',
65
			\wp_json_encode( $config )
66
		);
67
68
		$gateway = $this->integration->get_gateway( $post_id );
69
70
		$this->assertInstanceOf( Gateway::class, $gateway );
71
	}
72
}
73