You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+63-7Lines changed: 63 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,25 +85,81 @@ The framework itself knows which columns are not NULL-able in the table and inse
85
85
Also, there might be various foreign key constraints going on in the background. Test-Db-Acle temporarily disables foreign key checks, so we do not have to worry about this, or in which order we insert the test data.
86
86
87
87
###What about an actual test.....?###
88
+
First, if you use PHP5.4, you can use the traits version:
89
+
```php
90
+
class ExampleTest extends \PHPUnit_Framework_TestCase implements \TestDbAcle\PhpUnit\AbstractTestCaseInterface
91
+
{
92
+
use \TestDbAcle\PhpUnit\Traits\DatabaseHelperTrait;
93
+
94
+
/**
95
+
* This method needs to be implemented, it should return the PDO object that is to be used in the database fixtures
96
+
*
97
+
* @return \Pdo
98
+
*/
99
+
public function providePdo()
100
+
{
101
+
return new \Pdo("mysql:dbname=my_db_tests;host=localhost",'myTestUser', 'myTestPassword');
102
+
}
103
+
104
+
/*
105
+
* An example test
106
+
*/
107
+
public function test_AddressService()
108
+
{
109
+
$this->setupTables("
110
+
[address]
111
+
address_id |company
112
+
1 |me
113
+
3 |you
114
+
115
+
[user]
116
+
user_id |name
117
+
10 |John
118
+
20 |Mary
119
+
120
+
");
121
+
122
+
$this->setAutoIncrement('address', 100);
123
+
124
+
$this->addressService->addEntry("them");
125
+
126
+
$this->assertTableStateContains("
127
+
[address]
128
+
address_id |company
129
+
1 |me
130
+
3 |you
131
+
100 |them
132
+
133
+
[user]
134
+
user_id |name
135
+
10 |John
136
+
20 |Mary
137
+
", array(), "Stuff works");
138
+
}
139
+
}
140
+
```
141
+
142
+
If you don't use traits, you can use ```AbstractTestCase```, however you won't be able to use your own base test classes in that case.
88
143
89
144
```php
90
145
class ExampleTest extends \TestDbAcle\PhpUnit\AbstractTestCase
91
146
{
92
-
protected $pdo;
147
+
93
148
protected $addressService;
94
149
95
150
function Setup(){
96
151
parent::Setup();
97
152
$this->addressService = new \Services\AddressService();
98
153
}
99
154
100
-
function getPdo()
155
+
/**
156
+
* This method needs to be implemented, it should return the PDO object that is to be used in the database fixtures
157
+
*
158
+
* @return \Pdo
159
+
*/
160
+
public function providePdo()
101
161
{
102
-
if (!isset($this->pdo)){
103
-
$config = include(__DIR__."/config.php");
104
-
$this->pdo = new \Pdo("mysql:dbname={$config['db_name']};host={$config['db_host']}",$config['db_user'],$config['db_password']);
105
-
}
106
-
return $this->pdo;
162
+
return new \Pdo("mysql:dbname=my_db_tests;host=localhost",'myTestUser', 'myTestPassword');
0 commit comments