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
+54-3Lines changed: 54 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Install the package using Composer. Edit your project's `composer.json` file to
19
19
```
20
20
21
21
## Quickstart
22
-
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):
22
+
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
23
24
24
in tests/fixtures/soul_reapers.php
25
25
```php
@@ -31,11 +31,15 @@ in tests/fixtures/soul_reapers.php
31
31
'Renji' => array (
32
32
'first_name' => 'Renji',
33
33
'last_name' => 'Abarai'
34
+
),
35
+
'Genryusai' => array(
36
+
'first_name' => 'Genryusai',
37
+
'last_name' => 'Yammamoto'
34
38
)
35
39
);
36
40
```
37
41
38
-
Here we're simple returning a nested array containing our fixture data. Notice that there are two fixtures and that they each have a unique name (this is very important as you'll see shortly we can easily reference loaded fixture data from within our tests). Now, we can't have soul reapers without zanpakutos, so let's assume we've also got a fictional zanpakutos table that we need to seed some data into. We'll create the following fixture:
42
+
Here we're simple returning a nested array containing our fixture data. Notice that there are two fixtures and that they each have a unique name (this is very important as you'll see shortly we can easily reference loaded fixture data from within our tests). Now, we can't have soul reapers without zanpakutos, so let's assume we've also got a fictional 'zanpakutos' table that we need to seed some data into. We'll create the following fixture:
39
43
40
44
in tests/fixtures/zanpakutos.php
41
45
```php
@@ -47,8 +51,55 @@ in tests/fixtures/zanpakutos.php
47
51
'Zabimaru' => array (
48
52
'soul_reaper_id' => 'Renji',
49
53
'name' => 'Zabimaru',
54
+
),
55
+
'Ryujin Jakka' => array(
56
+
'soul_reaper_id' => 'Yammamoto',
57
+
'name' => 'Ryujin Jakka',
58
+
)
59
+
);
60
+
```
61
+
62
+
Because a zanpakuto must belong to a soul reaper (it's part of their soul after all) we know that our 'zanpakutos' table will contain a column named 'soul_reaper_id'. In order to tie a zanpakuto to it's owner, we can simply set this foreign key to the name of the corresponding soul reaper it belongs to. There's no need to worry about specific id's, insertion order, etc. It's pretty simple. Moving forward, we've so far been able to easily express our parent/child (1 to 1) relationship between 'soul_reapers' and 'zanpakutos', but what about many to many (join table) relationships? As an example of how this might work, let's now assume that we also have two more tables; 'ranks' and 'ranks_soul_reapers'. Our ranks table fixture will look like this:
63
+
64
+
in tests/fixtures/ranks.php
65
+
```php
66
+
return array (
67
+
'Commander' => array (
68
+
'title' => 'Commander'
69
+
),
70
+
'Captain' => array (
71
+
'title' => 'Captain',
72
+
),
73
+
'Lieutenant' => array (
74
+
'title' => 'Lieutenant',
75
+
),
76
+
'Substitute' => array (
77
+
'title' => 'Substitute Shinigami',
78
+
),
79
+
);
80
+
```
81
+
82
+
The 'ranks_soul_reapers' join table fixture will look like this:
83
+
84
+
in tests/fixtures/ranks_soul_reapers.php
85
+
```php
86
+
return array (
87
+
'CommanderYammamoto' => array (
88
+
'soul_reaper_id' => 'Yammamoto',
89
+
'rank_id' => 'Commander'
90
+
),
91
+
'CaptainYammamoto' => array (
92
+
'soul_reaper_id' => 'Yammamoto',
93
+
'rank_id' => 'Captain'
94
+
),
95
+
'LieutenantAbari' => array (
96
+
'soul_reaper_id' => 'Renji',
97
+
'rank_id' => 'Lieutenant'
98
+
),
99
+
'SubstituteKurosaki' => array (
100
+
'soul_reaper_id' => 'Ichigo',
101
+
'rank_id' => 'Substitute'
50
102
)
51
103
);
52
104
```
53
105
54
-
Because a zanpakuto must belong to a soul reaper (it's part of their soul after all) we know that our zanpakutos table will contain a column named 'soul\_reaper\_id'. In order to tie a zanpakuto to it's owner, we can simply set this foreign key to the name of the corresponding soul reaper it belongs to. There's no need to worry about specific id's, insertion order, etc. It's pretty simple.
0 commit comments