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

ShopMemberTest::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
 * Test member functionality added via ShopMember extension
5
 */
6
class ShopMemberTest extends FunctionalTest
7
{
8
    public static $fixture_file = array(
9
        'silvershop/tests/fixtures/ShopMembers.yml',
10
        'silvershop/tests/fixtures/shop.yml',
11
    );
12
13
    public function setUpOnce()
14
    {
15
        parent::setUpOnce();
16
        // clear session
17
        ShoppingCart::singleton()->clear();
18
    }
19
20
    public function testGetByIdentifier()
21
    {
22
        Member::config()->unique_identifier_field = 'Email';
23
        $member = ShopMember::get_by_identifier('[email protected]');
24
        $this->assertNotNull($member);
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<ShopMemberTest>.

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...
25
        $this->assertEquals('[email protected]', $member->Email);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShopMemberTest>.

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...
26
        $this->assertEquals('Jeremy', $member->FirstName);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShopMemberTest>.

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...
27
    }
28
29
    public function testCMSFields()
30
    {
31
        singleton("Member")->getCMSFields();
32
        singleton("Member")->getMemberFormFields();
33
    }
34
35
    public function testPastOrders()
36
    {
37
        $member = $this->objFromFixture("Member", "joebloggs");
38
        $pastorders = $member->getPastOrders();
39
        $this->assertEquals(1, $pastorders->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShopMemberTest>.

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...
40
    }
41
42
    public function testLoginJoinsCart()
43
    {
44
        Member::config()->login_joins_cart = true;
45
        $order = $this->objFromFixture("Order", "cart");
46
        ShoppingCart::singleton()->setCurrent($order);
0 ignored issues
show
Documentation introduced by
$order is of type object<DataObject>|null, but the function expects a object<Order>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
        $member = $this->objFromFixture("Member", "jeremyperemy");
48
        $member->logIn();
49
        $this->assertEquals($member->ID, $order->MemberID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShopMemberTest>.

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...
50
51
        $member->logOut();
52
53
        $this->assertFalse(ShoppingCart::curr());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ShopMemberTest>.

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...
54
    }
55
56
    public function testLoginDoesntJoinCart()
57
    {
58
        Member::config()->login_joins_cart = false;
59
        $order = $this->objFromFixture("Order", "cart");
60
        ShoppingCart::singleton()->setCurrent($order);
0 ignored issues
show
Documentation introduced by
$order is of type object<DataObject>|null, but the function expects a object<Order>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
        $member = $this->objFromFixture("Member", "jeremyperemy");
62
        $member->logIn();
63
        $this->assertEquals(0, $order->MemberID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShopMemberTest>.

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...
64
65
        $member->logOut();
66
67
        $this->assertTrue((bool)ShoppingCart::curr());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShopMemberTest>.

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...
68
    }
69
}
70