User Tools

Site Tools


php:testguard

Functional test behind sfGuardDoctrinePlugin

03.02.2010

If you implemented sfGuardDoctrinePlugin in your application, it's likely you'd get this when you try to run functional tests:

not ok 3 - status code is 200
#     Failed test (./lib/vendor/symfony/lib/test/sfTesterResponse.class.php at line 398)
#            got: 401
#       expected: 200

That's because in functional test you have

$browser = new sfTestFunctional(new sfBrowser());

Solution: create an extended class to sfTestFunctional.

/lib/sfGuardTestFunctional.php

<?php 
// lib/sfGuardTestFunctional.php
class sfGuardTestFunctional extends sfTestFunctional {  
    public function signin($username = 'admin', $password = 'admin', $click = 'sign in', $signin_url = '/login', $nameFormat = 'signin') {
        return $this->get($signin_url)
            ->click($click, array($nameFormat => array('username' => $username,'password' => $password)));
    }
}

and modify the test:

$browser = new sfGuardTestFunctional(new sfBrowser());
 
$browser
    ->get('/foo/bar')
    ->signin($username, $password)
    ->get('/foo/bar')
    ->with('request')->begin()->
        isParameter('module', 'foo')->
        isParameter('action', 'bar')->
    end()
 

php/testguard.txt · Last modified: 2013/03/16 17:40 (external edit)