AddressTest::testSaveOnEmptyDB()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
require_once 'Intraface/Error.php';
3
require_once 'Intraface/Validator.php';
4
require_once 'Intraface/Address.php';
5
6
class AddressTest extends PHPUnit_Framework_TestCase
7
{
8
9
    private $kernel;
0 ignored issues
show
Unused Code introduced by
The property $kernel is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
11
    function setUp()
12
    {
13
        $db = MDB2::singleton(DB_DSN);
14
        $db->query('TRUNCATE address');
15
    }
16
17
    function getValidAddress()
18
    {
19
        return array('name' => 'test', 'address' => 'road 1', 'postcode' => '0123', 'city' => 'Mycity', 'country' => '', 'email' => '[email protected]', 'cvr' => '', 'website' => '', 'phone' => '', 'ean' => '');
20
    }
21
22
    function testValidateWithValidAddress()
23
    {
24
25
        $address = Intraface_Address::factory('intranet', 1);
0 ignored issues
show
Deprecated Code introduced by
The method Intraface_Address::factory() has been deprecated.

This method has been deprecated.

Loading history...
26
        $this->assertTrue($address->validate($this->getValidAddress()));
27
    }
28
29
    function testValidateWithInvalidAddress()
30
    {
31
        $address = Intraface_Address::factory('intranet', 1);
0 ignored issues
show
Deprecated Code introduced by
The method Intraface_Address::factory() has been deprecated.

This method has been deprecated.

Loading history...
32
        $this->assertFalse($address->validate(array()));
33
    }
34
35
    function testSaveOnEmptyDB()
36
    {
37
        $address = Intraface_Address::factory('intranet', 1);
0 ignored issues
show
Deprecated Code introduced by
The method Intraface_Address::factory() has been deprecated.

This method has been deprecated.

Loading history...
38
        $this->assertTrue($address->save($this->getValidAddress()));
39
        $this->assertEquals(1, $address->get('address_id')); // on empty database this must be 1
40
    }
41
42
    function testSaveWithSaveTwoTimeWithSameData()
43
    {
44
        $address = Intraface_Address::factory('intranet', 1);
0 ignored issues
show
Deprecated Code introduced by
The method Intraface_Address::factory() has been deprecated.

This method has been deprecated.

Loading history...
45
        $address->save($this->getValidAddress());
46
47
48
        // we repeat the save, this should automatically determine that nothing should be done. Can we determine whether this is true?
49
        $this->assertTrue($address->save($this->getValidAddress()));
50
        $this->assertEquals(1, $address->get('address_id')); // on empty database this must be 1
51
    }
52
53
    function testSaveWithChangeInName()
54
    {
55
        $address = Intraface_Address::factory('intranet', 1);
0 ignored issues
show
Unused Code introduced by
$address is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Deprecated Code introduced by
The method Intraface_Address::factory() has been deprecated.

This method has been deprecated.

Loading history...
56
57
        $address_array = $this->getValidAddress();
58
59
        $address = Intraface_Address::factory('intranet', 1);
0 ignored issues
show
Deprecated Code introduced by
The method Intraface_Address::factory() has been deprecated.

This method has been deprecated.

Loading history...
60
        $address->save($address_array);
61
62
        $address_array['name'] = 'test 2';
63
        $this->assertTrue($address->save($address_array));
64
        $this->assertEquals(2, $address->get('address_id')); // on empty database this must be 1
65
    }
66
67
    function testUpdate()
68
    {
69
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
        Da metoden er fjernet fra klassen er testen ogs� fjernet.
71
        $address = Address::factory('intranet', 1);
72
        $address->save($this->getValidAddress());
73
        $this->assertTrue($address->update($this->getValidAddress()));
74
        $this->assertEquals(1, $address->get('address_id')); // on empty database this must be 1
75
        */
76
    }
77
78
    function testLoad()
79
    {
80
        $address = Intraface_Address::factory('intranet', 1);
0 ignored issues
show
Deprecated Code introduced by
The method Intraface_Address::factory() has been deprecated.

This method has been deprecated.

Loading history...
81
        $address->save($this->getValidAddress());
82
83
        $address = new Intraface_Address(1);
84
        $this->assertEquals(1, $address->get('address_id'));
85
    }
86
}
87