Add $fixture_file to the fixtures docs

Currently no mention of it.
This commit is contained in:
Andrew Aitken-Fincham 2017-06-28 17:24:47 +01:00
parent eec8dfa7ad
commit ef8e04a83e

View File

@ -9,6 +9,42 @@ SilverStripe starts with a fresh database containing no records. `Fixtures` prov
to load into the database. The [api:SapphireTest] class takes care of populating a test database with data from
fixtures - all we have to do is define them.
<div class="info" markdown='1'>
To include your fixture file in your tests, you should define it as your `$fixture_file`:
**mysite/tests/MyNewTest.php**
:::php
<?php
class MyNewTest extends SapphireTest {
protected static $fixture_file = 'fixtures.yml';
}
You can also use an array of fixture files, if you want to use parts of multiple other tests:
**mysite/tests/MyNewTest.php**
:::php
<?php
class MyNewTest extends SapphireTest {
protected static $fixture_file = [
'fixtures.yml',
'otherfixtures.yml'
];
}
</div>
Typically, you'd have a separate fixture file for each class you are testing - although overlap between tests is common.
Fixtures are defined in `YAML`. `YAML` is a markup language which is deliberately simple and easy to read, so it is
ideal for fixture generation. Say we have the following two DataObjects: