Symfony test entity
<p>I have entity service and I create controller and action get, create, edit and deleted. I look for test and I don't know why I have error? I can enter for this rout and have data, and work fine, but if create client and get status code have 302</p>

<p>But when I comment in security.yml </p>

<pre><code>    access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    #- { path: ^/admin, roles: ROLE_ADMIN }
</code></pre>

<p>test passed almost all only in the late fall</p>

<p>How to create client with <strong>ROLE_ADMIN</strong> ??
and this test</p>

<pre><code> public function testCompleteScenario()
{
    // Create a new client to browse the application
    $client = static::createClient();

    // Create a new entry in the database
    $crawler = $client-&gt;request('GET', '/admin/services/');
    $this-&gt;assertEquals(200, $client-&gt;getResponse()-&gt;getStatusCode(), "Unexpected HTTP status code for GET /admin/services/");
    $crawler = $client-&gt;click($crawler-&gt;selectLink('Create a new entry')-&gt;link());

    // Fill in the form and submit it
    $form = $crawler-&gt;selectButton('Create')-&gt;form(array(
        'artel_profilebundle_services[services]'  =&gt; 'Test',
        // ... other fields to fill
    ));

    $client-&gt;submit($form);
    $crawler = $client-&gt;followRedirect();

    // Check data in the show view
    $this-&gt;assertGreaterThan(0, $crawler-&gt;filter('td:contains("Test")')-&gt;count(), 'Missing element td:contains("Test")');

    // Edit the entity
    $crawler = $client-&gt;click($crawler-&gt;selectLink('Edit')-&gt;link());

    $form = $crawler-&gt;selectButton('Update')-&gt;form(array(
        'artel_profilebundle_services[services]'  =&gt; 'Foo',
        // ... other fields to fill
    ));

    $client-&gt;submit($form);
    $crawler = $client-&gt;followRedirect();

    // Check the element contains an attribute with value equals "Foo"
    $this-&gt;assertGreaterThan(0, $crawler-&gt;filter('[value="Foo"]')-&gt;count(), 'Missing element [value="Foo"]');

    // Delete the entity
    $client-&gt;submit($crawler-&gt;selectButton('Delete')-&gt;form());
    $crawler = $client-&gt;followRedirect();

    // Check the entity has been delete on the list
    // **this is 51 line**
    $this-&gt;assertNotRegExp('/Foo/', $client-&gt;getResponse()-&gt;getContent());
}
</code></pre>

<p>and I have </p>

<pre><code>' does not match PCRE pattern "/Foo/".

  /home/ivan/host/test/src/Artel/AdminBundle/Tests/Controller/ServicesControllerTest.php:51
</code></pre>

<p>where error ? </p>

<p><strong>UPDATE</strong> </p>

<p>change</p>

<pre><code>class ServicesControllerTest extends WebTestCase
{
private $client = null;

public function setUp()
{
    $this-&gt;client = static::createClient();
}

public function logIn()
{
    $session = $this-&gt;client-&gt;getContainer()-&gt;get('session');

    $firewall = 'default';
    $token = new UsernamePasswordToken('admin', null, $firewall, array('ROLE_ADMIN'));
    $session-&gt;set('_security_'.$firewall, serialize($token));
    $session-&gt;save();

    $cookie = new Cookie($session-&gt;getName(), $session-&gt;getId());
    $this-&gt;client-&gt;getCookieJar()-&gt;set($cookie);
}

public function testCompleteScenario()
{
    // Create a new client to browse the application
    $this-&gt;logIn();

    // Create a new entry in the database
    $crawler = $this-&gt;client-&gt;request('GET', '/admin/services/');
    $this-&gt;assertEquals(200, $this-&gt;client-&gt;getResponse()-&gt;getStatusCode(), "Unexpected HTTP status code for GET /admin/services/");
    $crawler = $this-&gt;client-&gt;click($crawler-&gt;selectLink('Create a new entry')-&gt;link());

    // Fill in the form and submit it
    $form = $crawler-&gt;selectButton('Create')-&gt;form(array(
        'artel_profilebundle_services[services]'  =&gt; 'Test',
        // ... other fields to fill
    ));

    $this-&gt;client-&gt;submit($form);
    $crawler = $this-&gt;client-&gt;followRedirect();

    // Check data in the show view
    $this-&gt;assertGreaterThan(0, $crawler-&gt;filter('td:contains("Test")')-&gt;count(), 'Missing element td:contains("Test")');

    // Edit the entity
    $crawler = $this-&gt;client-&gt;click($crawler-&gt;selectLink('Edit')-&gt;link());

    $form = $crawler-&gt;selectButton('Update')-&gt;form(array(
        'artel_profilebundle_services[services]'  =&gt; 'Foo',
        // ... other fields to fill
    ));

    $this-&gt;client-&gt;submit($form);
    $crawler = $this-&gt;client-&gt;followRedirect();

    // Check the element contains an attribute with value equals "Foo"
    $this-&gt;assertGreaterThan(0, $crawler-&gt;filter('[value="Foo"]')-&gt;count(), 'Missing element [value="Foo"]');

    // Delete the entity
    $this-&gt;client-&gt;submit($crawler-&gt;selectButton('Delete')-&gt;form());
    $crawler = $this-&gt;client-&gt;followRedirect();

    // this is line 73
    $this-&gt;assertNotRegExp('/Foo/', $this-&gt;client-&gt;getResponse()-&gt;getContent());
}
</code></pre>

<p>}</p>

<p>in this step I have error </p>

<pre><code>$this-&gt;assertNotRegExp('/Foo/', $this-&gt;client-&gt;getResponse()-&gt;getContent());
</code></pre>

<p>after deleted test service function assertNotRegExp try to find in content but error something with regular I dint know. After test I have all html my page /admin/services/ and error </p>

<pre><code>' does not match PCRE pattern "/Foo/".

    /home/ivan/host/test/src/Artel/AdminBundle/Tests/Controller/ServicesControllerTest.php:73
</code></pre>

<p>where error ? </p>