Failed Conditions
Push — develop ( e1eaf3...e2a320 )
by Remco
04:21
created

TaxedMoneyTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_taxed_money() 0 9 1
A test_tax_value_calculation_from_tax_percentage() 0 4 1
A test_json() 0 13 1
A test_no_tax() 0 6 1
1
<?php
2
/**
3
 * Taxed Money Test
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2021 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Money
9
 */
10
11
namespace Pronamic\WordPress\Money;
12
13
use WP_Locale;
14
use WP_UnitTestCase;
15
16
/**
17
 * Taxed Money Test
18
 *
19
 * @author Remco Tolsma
20
 * @version 1.2.2
21
 * @since   1.0.0
22
 */
23
class TaxedMoneyTest extends WP_UnitTestCase {
24
	/**
25
	 *  Test taxed money.
26
	 */
27
	public function test_taxed_money() {
28
		$money = new TaxedMoney( '121', 'EUR', '21', '21' );
29
30
		$this->assertSame( '21.00', $money->get_tax_amount()->number_format( null, '.', '' ) );
31
		$this->assertSame( '21', $money->get_tax_value() );
32
		$this->assertTrue( $money->has_tax() );
33
		$this->assertSame( '21', $money->get_tax_percentage() );
34
		$this->assertSame( '121.00', $money->get_including_tax()->number_format( null, '.', '' ) );
35
		$this->assertSame( '100.00', $money->get_excluding_tax()->number_format( null, '.', '' ) );
36
	}
37
38
	/**
39
	 *  Test tax percentage calculation from tax value.
40
	 */
41
	public function test_tax_value_calculation_from_tax_percentage() {
42
		$money = new TaxedMoney( '121', 'EUR', null, '21' );
43
44
		$this->assertSame( '21', $money->get_tax_value() );
45
	}
46
47
	/**
48
	 * Test JSON.
49
	 */
50
	public function test_json() {
51
		$money = new TaxedMoney( '121', 'EUR', null, '21' );
52
53
		$this->assertJsonStringEqualsJsonString(
54
			'
55
			{
56
				"value": "121",
57
				"currency": "EUR",
58
				"tax_value": "21",
59
				"tax_percentage": "21"
60
			}
61
			',
62
			\wp_json_encode( $money )
0 ignored issues
show
Bug introduced by
It seems like wp_json_encode($money) can also be of type false; however, parameter $actualJson of PHPUnit\Framework\Assert...tringEqualsJsonString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

62
			/** @scrutinizer ignore-type */ \wp_json_encode( $money )
Loading history...
63
		);
64
	}
65
66
	/**
67
	 * Test no tax.
68
	 */
69
	public function test_no_tax() {
70
		$money = new TaxedMoney( '121', 'EUR' );
71
72
		$this->assertFalse( $money->has_tax() );
73
		$this->assertNull( $money->get_tax_amount() );
74
		$this->assertSame( '121.00', $money->get_excluding_tax()->number_format( null, '.', '' ) );
75
	}
76
}
77