TimestampableTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
cbo 4
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A tearDown() 0 4 1
A testTimestampable() 0 18 1
1
<?php
2
namespace Fwk\Db;
3
4
use Fwk\Db\Listeners\Timestampable;
5
6
class User3 extends \stdClass implements EventSubscriberInterface
7
{
8
    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...
9
10
    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...
11
12
    /**
13
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use Timestampable[].

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...
14
     */
15
    public function getListeners()
16
    {
17
        return array(
18
            new Timestampable()
19
        );
20
    }
21
}
22
23
/**
24
 * Test class for Accessor.
25
 * Generated by PHPUnit on 2012-05-27 at 17:46:42.
26
 */
27
class TimestampableTest 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...
28
{
29
    /**
30
     *
31
     * @var \Fwk\Db\Connection
32
     */
33
    protected $connection;
34
35
    /**
36
     * Sets up the fixture, for example, opens a network connection.
37
     * This method is called before a test is executed.
38
     */
39
    protected function setUp()
40
    {
41
        $this->connection = new Connection(array(
42
            'memory'    => true,
43
            'driver'    => 'pdo_sqlite'
44
        ));
45
46
        \FwkDbTestUtil::createTestDb($this->connection);
47
    }
48
49
    protected function tearDown()
50
    {
51
        \FwkDbTestUtil::dropTestDb($this->connection);
52
    }
53
54
    public function testTimestampable()
55
    {
56
        $obj = new User3();
57
        $obj->username = "joeBar";
58
        $this->assertNull($obj->created_at);
59
60
        $this->connection->table("fwkdb_test_users")->save($obj);
61
62
        $this->assertNotNull($obj->created_at);
63
        $creation = $obj->created_at;
64
65
        $this->assertNull($obj->updated_at);
66
        $obj->username = "joeBarUpdated";
67
        $this->connection->table("fwkdb_test_users")->save($obj);
68
69
        $this->assertEquals($creation, $obj->created_at);
70
        $this->assertNotNull($obj->updated_at);
71
    }
72
}
73