ErrorTest::test()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 9.9666
1
<?php
2
/**
3
 * Error Test
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2022 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
 * Error Test
15
 *
16
 * @author  Remco Tolsma
17
 * @version 1.1.0
18
 * @since   1.0.0
19
 */
20
class ErrorTest extends \WP_UnitTestCase {
21
	/**
22
	 * Test.
23
	 */
24
	public function test() {
25
		$error = new Error(
26
			1004,
27
			'Property not found in request: body.card.number.',
28
			'Property not found in request: body.card.number.'
29
		);
30
31
		$this->assertInstanceOf( Error::class, $error );
32
		$this->assertEquals( 1004, $error->getCode() );
33
		$this->assertEquals( 1004, $error->get_code() );
34
		$this->assertEquals( 'Property not found in request: body.card.number.', $error->getMessage() );
35
		$this->assertEquals( 'Property not found in request: body.card.number.', $error->get_message() );
36
	}
37
38
	/**
39
	 * Test from JSON.
40
	 */
41
	public function test_from_json() {
42
		$json = \file_get_contents( __DIR__ . '/../json/error.json', true );
43
44
		$data = \json_decode( $json );
45
46
		$error = Error::from_json( $data );
47
48
		$this->assertEquals( 1004, $error->getCode() );
49
		$this->assertEquals( 'Property not found in request: body.card.number.', $error->getMessage() );
50
	}
51
}
52