BasicEntityMovesTest::testCreateAndUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
namespace Fwk\Db;
4
5
/**
6
 * Test class for Accessor.
7
 * Generated by PHPUnit on 2012-05-27 at 17:46:42.
8
 */
9
class BasicEntityMovesTest extends \PHPUnit_Framework_TestCase
10
{
11
    protected $connection;
12
13
    /**
14
     * Sets up the fixture, for example, opens a network connection.
15
     * This method is called before a test is executed.
16
     */
17
    protected function setUp()
18
    {
19
        $this->connection = new Connection(array(
20
            'memory'    => true,
21
            'driver'    => 'pdo_sqlite'
22
        ));
23
24
        \FwkDbTestUtil::createTestDb($this->connection);
25
    }
26
27
    protected function tearDown()
28
    {
29
        \FwkDbTestUtil::dropTestDb($this->connection);
30
    }
31
32
    public function testCreateAndInsert()
33
    {
34
        $this->assertEquals(0, count($this->connection->table("fwkdb_test_users")->finder()->all()));
35
        $obj = new \stdClass;
36
        $obj->username = "joeBar";
37
38
        $this->connection->table("fwkdb_test_users")->save($obj);
39
        $this->assertEquals(1, count($this->connection->table("fwkdb_test_users")->finder()->all()));
40
    }
41
42
    public function testCreateAndUpdate()
43
    {
44
        $this->assertEquals(0, count($this->connection->table("fwkdb_test_users")->finder()->all()));
45
        $obj = new \stdClass;
46
        $obj->username = "joeBar";
47
        $this->connection->table("fwkdb_test_users")->save($obj);
48
49
        $my = $this->connection->table('fwkdb_test_users')->finder()->find(array('username' => "joeBar"));
50
        $this->assertEquals(1, count($my));
51
        $obj = $my[0];
52
        $this->assertEquals("joeBar", $obj->username);
53
        $obj->username = "joeBarUPDATED";
54
        $this->connection->table("fwkdb_test_users")->save($obj);
55
56
        $my = $this->connection->table('fwkdb_test_users')->finder()->find(array('username' => "joeBar"));
57
        $this->assertEquals(0, count($my));
58
        $my = $this->connection->table('fwkdb_test_users')->finder()->find(array('username' => "joeBarUPDATED"));
59
        $this->assertEquals(1, count($my));
60
    }
61
62
    public function testCreateAndDelete()
63
    {
64
        $this->assertEquals(0, count($this->connection->table("fwkdb_test_users")->finder()->all()));
65
        $obj = new \stdClass;
66
        $obj->username = "joeBar";
67
68
        $this->connection->table("fwkdb_test_users")->save($obj);
69
        $this->assertEquals(1, count($this->connection->table("fwkdb_test_users")->finder()->all()));
70
71
        $this->connection->table("fwkdb_test_users")->delete($obj);
72
        $this->assertEquals(0, count($this->connection->table("fwkdb_test_users")->finder()->all()));
73
    }
74
}
75