Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit 744e0f9

Browse files
committed
Writing documentation.w
1 parent 873cbc6 commit 744e0f9

1 file changed

Lines changed: 54 additions & 3 deletions

File tree

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Install the package using Composer. Edit your project's `composer.json` file to
1919
```
2020

2121
## 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):
2323

2424
in tests/fixtures/soul_reapers.php
2525
```php
@@ -31,11 +31,15 @@ in tests/fixtures/soul_reapers.php
3131
'Renji' => array (
3232
'first_name' => 'Renji',
3333
'last_name' => 'Abarai'
34+
),
35+
'Genryusai' => array(
36+
'first_name' => 'Genryusai',
37+
'last_name' => 'Yammamoto'
3438
)
3539
);
3640
```
3741

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:
3943

4044
in tests/fixtures/zanpakutos.php
4145
```php
@@ -47,8 +51,55 @@ in tests/fixtures/zanpakutos.php
4751
'Zabimaru' => array (
4852
'soul_reaper_id' => 'Renji',
4953
'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'
50102
)
51103
);
52104
```
53105

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

Comments
 (0)