Skip to content

Commit 46dc49e

Browse files
author
George Borges
committed
Adding placeholders explanation to README
1 parent 1d54300 commit 46dc49e

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
THE ICONIC Database Fixtures
22
========
3-
[![Build Status](https://travis-ci.org/theiconic/fixtures.png?branch=v1.2.7)](https://travis-ci.org/theiconic/fixtures) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/theiconic/fixtures/badges/quality-score.png?s=334ddfb53b2b286b443ff745b4458d61d9a1ac15)](https://scrutinizer-ci.com/g/theiconic/fixtures/) [![Coverage Status](https://coveralls.io/repos/theiconic/fixtures/badge.png?branch=master)](https://coveralls.io/r/theiconic/fixtures?branch=master) [![Latest Stable Version](https://poser.pugx.org/theiconic/fixtures/v/stable.png)](https://packagist.org/packages/theiconic/fixtures) [![License](https://poser.pugx.org/theiconic/fixtures/license.png)](https://packagist.org/packages/theiconic/fixtures)
3+
[![Build Status](https://travis-ci.org/theiconic/fixtures.png?branch=v1.3)](https://travis-ci.org/theiconic/fixtures) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/theiconic/fixtures/badges/quality-score.png?s=334ddfb53b2b286b443ff745b4458d61d9a1ac15)](https://scrutinizer-ci.com/g/theiconic/fixtures/) [![Coverage Status](https://coveralls.io/repos/theiconic/fixtures/badge.png?branch=master)](https://coveralls.io/r/theiconic/fixtures?branch=master) [![Latest Stable Version](https://poser.pugx.org/theiconic/fixtures/v/stable.png)](https://packagist.org/packages/theiconic/fixtures) [![License](https://poser.pugx.org/theiconic/fixtures/license.png)](https://packagist.org/packages/theiconic/fixtures)
44

55
## Description
66

@@ -14,6 +14,8 @@ And it currently supports the following databases:
1414

1515
* MySQL
1616

17+
The fixture manager also allows you to replace placeholders in your fixtures programatically. See examples below.
18+
1719
## Usage
1820

1921
Suppose that you have two fixtures for your country and employee tables called country.xml and employee.yml, respectively. You load them into a MySQL database with a few lines of code:
@@ -50,14 +52,48 @@ $fixtureManager
5052
->persist();
5153
```
5254

55+
In the values for your fixtures files, you can put placeholders for the values. This allows you to change the values dynamically, such as, place the current date.
56+
57+
To do this, when creating the Fixture Manager pass an array with the keys in the form "fx:placeholder:<my_name>". For example:
58+
59+
```php
60+
use TheIconic\Fixtures\FixtureManager\FixtureManager;
61+
62+
// Declare an array with the path to your fixtures
63+
$fixtures = ['./fixtures/employee.yml'];
64+
65+
// Create a new Fixture Manager passing such array
66+
$fixtureManager = FixtureManager::create($fixtures, ['fx:placeholder:age' => 33]);
67+
68+
```
69+
70+
And the employee.xml file would be (notice the value of "age" field):
71+
72+
```xml
73+
<?xml version="1.0"?>
74+
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
75+
<database name="my_database">
76+
<table_data name="employee">
77+
<row>
78+
<field name="id">1</field>
79+
<field name="name">John Smith</field>
80+
<field name="age"/>fx:placeholder:age</field>
81+
</row>
82+
</table_data>
83+
</database>
84+
</mysqldump>
85+
```
86+
87+
You can pass any value you want, just calculate it before passing it to the create static method.
88+
5389
## Installation
5490

5591
Use Composer to install this package.
5692

5793
```json
5894
{
5995
"require": {
60-
"theiconic/fixtures": "~1.2"
96+
"theiconic/fixtures": "~1.3"
6197
}
6298
}
6399
```

0 commit comments

Comments
 (0)