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
+52-2Lines changed: 52 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ Install the package using Composer. Edit your project's `composer.json` file to
19
19
```
20
20
21
21
## Quickstart
22
+
### Step 1 - Fixture setup
22
23
Inside your application test folder, create a folder named fixtures. Next, create a couple of fixture files inside this folder. Fixture files are written using native php array syntax. To create one, simply create a new file named after the table that the fixture corresponds to and have it return an array of data. As an example of this, let's create some fixture data for a hypothetical 'soul_reapers' table (bear with me, I'm a huge Bleach fan):
23
24
24
25
in tests/fixtures/soul_reapers.php
@@ -53,7 +54,7 @@ in tests/fixtures/zanpakutos.php
53
54
'name' => 'Zabimaru',
54
55
),
55
56
'Ryujin Jakka' => array(
56
-
'soul_reaper_id' => 'Yammamoto',
57
+
'soul_reaper_id' => 'Genryusai',
57
58
'name' => 'Ryujin Jakka',
58
59
)
59
60
);
@@ -90,7 +91,7 @@ in tests/fixtures/ranks_soul_reapers.php
90
91
),
91
92
'CaptainYammamoto' => array (
92
93
'soul_reaper_id' => 'Yammamoto',
93
-
'rank_id' => 'Captain'
94
+
'rank_id' => 'Captain'
94
95
),
95
96
'LieutenantAbari' => array (
96
97
'soul_reaper_id' => 'Renji',
@@ -103,3 +104,52 @@ in tests/fixtures/ranks_soul_reapers.php
103
104
);
104
105
```
105
106
107
+
Notice that we have both a 'CommanderYammamoto' and a 'CaptainYammamoto' entry inside our ranks_soul_reapers join table; That's because Genryusai Yammamoto was the Captain Commander (he had both the commander role and was also captain level as well) of the Gotei 13.
108
+
109
+
### Step 2 - Initialize an instance of the fixture class.
110
+
Now that the fixture files have been created, the next step is to create an instance of the fixture library inside of our unit tests. Consider the following test (we're using PHPUnit here, but the testing framework doesn't matter; SimpleTest would work just as well):
111
+
112
+
in tests/exampleTest.php
113
+
```php
114
+
<?php
115
+
116
+
use Codesleeve\Fixture\Fixture;
117
+
use Codesleeve\Fixture\Repositories\StandardRepository;
118
+
119
+
class ExampleTest extends PHPUnit_Framework_TestCase {
* We're creating an instance of 'Codesleeve\Fixture\Repositories\StandardRepository' and caching it as a property on the test class.
148
+
** This is the most basic repository avaialble for this package. It requires no ORM and has no concept of relationships.
149
+
** In order to create a new repository we first need to instantiate a PDO database connection object and pass it as a parameter to the StandardRepository constructor.
150
+
* We're creating a new instance of fixture via the getInstance() method (this is a singleton pattern).
151
+
* We're injecting the stnadardRepository object into the fixture instance via the setRepository() method.
152
+
* We're injecting in a configuration array with a location parameter that contains the file system location of the folder we want to load our fixtures from.
153
+
* We're invoking the up() method on the fixture object. This method seeds the database and caches the inserted records as php standard objects on the fixture object.
154
+
** Invoking the up method with no params will seed all fixtures.
155
+
** Invoking the up method with an array of fixture names will seed only those fixtures (e.g $this->fixture->up(['soul_reapers']) would seed the soul_reapers table only).
0 commit comments