PDA

Vollständige Version anzeigen : POST testen


SRIT
21.07.2009, 13:56
Hallo,

hat schon mal jemand rausgefunden, wie man mit Zend_Test_PHPUnit_ControllerTestCase POST Requests testen kann?

class ClientsLogControllerTest extends ControllerTestCase {
public function testShowLoginForm() {
$this->dispatch ( '/clients/log/login' );
$this->assertAction ( 'login' );
$this->assertController ( 'log' );
$this->assertModule ( 'clients' );
}
public function testLogin() {
$this->getRequest ()->setMethod ( 'POST' );
$_POST ['username'] = 'riedel';
$_POST ['password'] = 'xxx';
$this->dispatch ( '/clients/log/login' );
}
}


Der erste Test läuft ohne Probleme, nur der zweite Test verhällt sich wie der erste (GET). Bevor gefragt wird hier noch meine ControllerTestCase:

<?php
require_once 'Zend/Application.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';

abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public $application;

public function setUp()
{
$this->application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);

$this->bootstrap = array($this, 'appBootstrap');
parent::setUp();
}

public function appBootstrap()
{
$this->application->bootstrap();
}
}


Jemand ne Ahnung, was ich falsch mache?

ice-breaker
21.07.2009, 14:24
class ClientsLogControllerTest extends ControllerTestCase {
// ...
public function testLogin() {
$this->getRequest()->setMethod('POST');
$this->getRequest()->setPost('username', 'riedel');
$this->getRequest()->setPost('password'], 'xxx');
$this->dispatch('/clients/log/login');
}
}
so sollte es denke ich gehen

SRIT
21.07.2009, 17:57
Jo thx dat läuft, doof wenn manchmal die Code Vervollständigung nicht Vervollständigt... :D