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; |
|
|
|
|
10
|
|
|
|
11
|
|
|
public $updated_at; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @return array |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
|
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.