Completed
Pull Request — 2.0 (#461)
by Roman
27:38
created

FlatTaxModifierTest::setUpOnce()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package    shop
5
 * @subpackage tests
6
 *
7
 */
8
class FlatTaxModifierTest extends FunctionalTest
9
{
10
    protected static $fixture_file  = 'silvershop/tests/fixtures/shop.yml';
11
    protected static $disable_theme = true;
12
13
    public function setUpOnce()
14
    {
15
        parent::setUpOnce();
16
        // clear session
17
        ShoppingCart::singleton()->clear();
18
    }
19
20
    public function setUp()
21
    {
22
        parent::setUp();
23
        ShopTest::setConfiguration();
24
        Order::config()->modifiers = array(
25
            "FlatTaxModifier",
26
        );
27
        FlatTaxModifier::config()->name = "GST";
28
        FlatTaxModifier::config()->rate = 0.15;
29
        $this->cart = ShoppingCart::singleton();
0 ignored issues
show
Bug introduced by
The property cart does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
        $this->mp3player = $this->objFromFixture('Product', 'mp3player');
0 ignored issues
show
Bug introduced by
The property mp3player does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
        $this->mp3player->publish('Stage', 'Live');
32
    }
33
34
    public function testInclusiveTax()
35
    {
36
        FlatTaxModifier::config()->exclusive = false;
37
        $this->cart->clear();
38
        $this->cart->add($this->mp3player);
39
        $order = $this->cart->current();
40
        $order->calculate();
41
        $modifier = $order->Modifiers()
42
            ->filter('ClassName', 'FlatTaxModifier')
43
            ->first();
44
        $this->assertEquals(26.09, $modifier->Amount); //remember that 15% tax inclusive is different to exclusive
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<FlatTaxModifierTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
        $this->assertEquals(200, $order->GrandTotal());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<FlatTaxModifierTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
    }
47
48
    public function testExclusiveTax()
49
    {
50
        FlatTaxModifier::config()->exclusive = true;
51
        $this->cart->clear();
52
        $this->cart->add($this->mp3player);
53
        $order = $this->cart->current();
54
        $order->calculate();
55
        $modifier = $order->Modifiers()
56
            ->filter('ClassName', 'FlatTaxModifier')
57
            ->first();
58
        $this->assertEquals(30, $modifier->Amount);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<FlatTaxModifierTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
        $this->assertEquals(230, $order->GrandTotal());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<FlatTaxModifierTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
    }
61
}
62