PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8
GiveWP – Donation Plugin and Fundraising Platform v4.16.8
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / vendor / moneyphp / money / src / PHPUnit / Comparator.php
Comparator.php
64 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Money\PHPUnit;
4
5 use Money\Currencies\AggregateCurrencies;
6 use Money\Currencies\BitcoinCurrencies;
7 use Money\Currencies\ISOCurrencies;
8 use Money\Formatter\IntlMoneyFormatter;
9 use Money\Money;
10 use SebastianBergmann\Comparator\ComparisonFailure;
11
12 /**
13 * The comparator is for comparing Money objects in PHPUnit tests.
14 *
15 * Add this to your bootstrap file:
16 *
17 * \SebastianBergmann\Comparator\Factory::getInstance()->register(new \Money\PHPUnit\Comparator());
18 */
19 final class Comparator extends \SebastianBergmann\Comparator\Comparator
20 {
21 /**
22 * @var IntlMoneyFormatter
23 */
24 private $formatter;
25
26 public function __construct()
27 {
28 parent::__construct();
29
30 $currencies = new AggregateCurrencies([
31 new ISOCurrencies(),
32 new BitcoinCurrencies(),
33 ]);
34
35 $numberFormatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
36 $this->formatter = new IntlMoneyFormatter($numberFormatter, $currencies);
37 }
38
39 public function accepts($expected, $actual)
40 {
41 return $expected instanceof Money && $actual instanceof Money;
42 }
43
44 /**
45 * @param Money $expected
46 * @param Money $actual
47 * @param float $delta
48 * @param bool $canonicalize
49 * @param bool $ignoreCase
50 */
51 public function assertEquals(
52 $expected,
53 $actual,
54 $delta = 0.0,
55 $canonicalize = false,
56 $ignoreCase = false,
57 array &$processed = []
58 ) {
59 if (!$expected->equals($actual)) {
60 throw new ComparisonFailure($expected, $actual, $this->formatter->format($expected), $this->formatter->format($actual), false, 'Failed asserting that two Money objects are equal.');
61 }
62 }
63 }
64