Symfony2 API test POST using YAML/Faker
<p>I'm building a REST API using Symfony2. I am already using <a href="https://github.com/liip/LiipImagineBundle" rel="nofollow">Liip bundle</a> for my functional tests together with <a href="https://github.com/hautelook/AliceBundle" rel="nofollow">Alice</a> and <a href="https://github.com/fzaninotto/Faker" rel="nofollow">Faker</a> to genereate all the fixtures. However, I have little trouble when I want to directly test POST calls themselves as long JSON are included in the POST data, which made my functions quite long, ugly and unreadable.</p>

<p>I decided to move the fake JSON out of the class, converting them to YAML files and then loading them using Symfony's parser:</p>

<pre><code>private function loadYaml($resource){
        $data = Yaml::parse(file_get_contents('src/AppBundle/DataFixtures/YAML/' . $resource . '.yml'));
        return $data;
}
</code></pre>

<p>This seems to work quite well, since I can easily convert them back to JSON objects and then use it in the call:</p>

<pre><code>$postData = json_encode($this-&gt;loadYaml('newapplication'));
$this-&gt;client-&gt;request(
    'POST', 
    '/api/application/save/',
    array('data' =&gt; $postData), // The Request parameters
    array(), // Files
    array(),
    'mybody', // Raw Body Data
    true
);
</code></pre>

<p>My first question is: is this a right approach? Is there any bundle that I have missed which will make my life much easier?</p>

<p>My second question is wheter it will be possible to use Faker within this YAML constructions. On my fixtures, I call Faker functions (e.g. &lt; firstName() >) that when fixtures are loaded automatically fill my entities with random but meaningful values. Would it be possible to use them in these YAML constructions?</p>

<p>Thanks a lot! ;)</p>