TypableTest::tearDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Fwk\Db;
3
4
5
use Fwk\Db\Listeners\Typable;
6
7
class User4 extends \stdClass implements EventSubscriberInterface
8
{
9
    public $created_at;
0 ignored issues
show
Coding Style introduced by
$created_at does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
10
11
    public $updated_at;
0 ignored issues
show
Coding Style introduced by
$updated_at does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
12
13
    /**
14
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use Typable[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
15
     */
16
    public function getListeners()
17
    {
18
        return array(
19
            new Typable()
20
        );
21
    }
22
}
23
24
/**
25
 * Test class for Accessor.
26
 * Generated by PHPUnit on 2012-05-27 at 17:46:42.
27
 */
28
class TypableTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
29
{
30
    /**
31
     *
32
     * @var \Fwk\Db\Connection
33
     */
34
    protected $connection;
35
36
    /**
37
     * Sets up the fixture, for example, opens a network connection.
38
     * This method is called before a test is executed.
39
     */
40
    protected function setUp()
41
    {
42
        $this->connection = new Connection(array(
43
            'memory'    => true,
44
            'driver'    => 'pdo_sqlite'
45
        ));
46
47
        \FwkDbTestUtil::createTestDb($this->connection);
48
    }
49
50
    protected function tearDown()
51
    {
52
        \FwkDbTestUtil::dropTestDb($this->connection);
53
    }
54
55
    public function testTypedValues()
56
    {
57
        $obj = new User4();
58
        $obj->username = "joeBar";
59
        $obj->created_at = new \DateTime();
60
61
        $this->connection->table("fwkdb_test_users")->save($obj);
62
63
        $newInst = $this->connection->table("fwkdb_test_users")->finder('Fwk\Db\User4')->one(1);
64
        $this->assertNotEquals($obj, $newInst);
65
        $this->assertTrue(is_object($newInst));
66
        $this->assertTrue(($newInst->created_at instanceof \DateTime));
67
    }
68
69
    public function testUpdate()
70
    {
71
        $obj = new User4();
72
        $obj->username = "joeBarUpdated";
73
        $obj->created_at = new \DateTime();
74
75
        $this->connection->table("fwkdb_test_users")->save($obj);
76
77
        $obj->updated_at = new \DateTime();
78
        $this->connection->table("fwkdb_test_users")->save($obj);
79
80
        $newInst = $this->connection->table("fwkdb_test_users")->finder('Fwk\Db\User4')->one(1);
81
        $this->assertNotEquals($obj, $newInst);
82
        $this->assertTrue(is_object($newInst));
83
        $this->assertTrue(($newInst->updated_at instanceof \DateTime));
84
    }
85
}
86