1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Feature ;
6+
7+ use PHPUnit \Framework \Attributes \Test ;
8+ use Vanilo \Adjustments \Adjusters \SimpleTax ;
9+ use Vanilo \Adjustments \Adjusters \SimpleTaxDeduction ;
10+ use Vanilo \Adjustments \Tests \Examples \Order ;
11+ use Vanilo \Adjustments \Tests \TestCase ;
12+
13+ class SimpleTaxTest extends TestCase
14+ {
15+ #[Test] public function a_simple_non_included_tax_can_be_added_to_an_adjustable_order ()
16+ {
17+ $ order = Order::create (['items_total ' => 100 ]);
18+ $ order ->adjustments ()->create (new SimpleTax (20 , false ));
19+
20+ $ this ->assertCount (1 , $ order ->adjustments ());
21+ $ this ->assertEquals (20 , $ order ->adjustments ()->total ());
22+ $ this ->assertEquals (120 , $ order ->total ());
23+ }
24+
25+ #[Test] public function an_included_tax_gets_calculated_correctly_based_on_the_rate_and_order_items_total ()
26+ {
27+ $ order = Order::create (['items_total ' => 119 ]);
28+ $ order ->adjustments ()->create (new SimpleTax (19 , true ));
29+
30+ $ this ->assertEquals (119 , $ order ->total ());
31+ $ this ->assertTrue ($ order ->adjustments ()->first ()->isCharge ());
32+ $ this ->assertCount (1 , $ order ->adjustments ());
33+ $ this ->assertEquals (19 , $ order ->adjustments ()->first ()->getAmount ());
34+ }
35+
36+ #[Test] public function a_simple_non_included_tax_deductaion_can_be_added_to_an_adjustable_order ()
37+ {
38+ $ order = Order::create (['items_total ' => 100 ]);
39+ $ order ->adjustments ()->create (new SimpleTaxDeduction (20 , false ));
40+
41+ $ this ->assertCount (1 , $ order ->adjustments ());
42+ $ this ->assertEquals (-20 , $ order ->adjustments ()->total ());
43+ $ this ->assertEquals (80 , $ order ->total ());
44+ }
45+
46+ #[Test] public function an_included_tax_deducation_gets_calculated_correctly_based_on_the_rate_and_order_items_total ()
47+ {
48+ $ order = Order::create (['items_total ' => 119 ]);
49+ $ order ->adjustments ()->create (new SimpleTaxDeduction (19 , true ));
50+
51+ $ this ->assertEquals (119 , $ order ->total ());
52+ $ this ->assertTrue ($ order ->adjustments ()->first ()->isCredit ());
53+ $ this ->assertCount (1 , $ order ->adjustments ());
54+ $ this ->assertEquals (-19 , $ order ->adjustments ()->first ()->getAmount ());
55+ }
56+ }
0 commit comments