Tuesday, 15 February 2011

laravel - Can't run Auth::loginUsingId(1) in Codeception acceptance _bootstrap.php -



laravel - Can't run Auth::loginUsingId(1) in Codeception acceptance _bootstrap.php -

i'm using laravel , codeception acceptance testing. of tests require users logged in, wanted extract behaviours _bootstrap.php file within acceptance folder. understand practice running setup prior tests, in codeception.

i can confirm users table exists (i'm viewing using navicat), , user id of 1 exists. codeception, best of knowledge, configured utilize database. have included laravel4 , db modules acceptance suite. receive next error when seek run acceptance suite, or individual acceptance cept.

console:

[illuminate\database\queryexception] sqlstate[42p01]: undefined table: 7 error: relation "users" not exist line 1: select * "users" "id" = $1 limit 1 ^ (sql: select * "users" "id" = 1 limit 1)

i error regardless of contents of of acceptance cepts. simple $i->amonpage('/'), or $i->comment('test') still results in error. believe error occurs encounters command in _bootstrap.php file. somehow it's able access database. should note i've tried various combinations of enabling , disabling populate , cleanup settings laravel4 , db modules, no avail.

here acceptance/_bootstrap.php file:

<?php auth::loginusingid(1);

codeception.yml:

actor: tester paths: tests: tests log: tests/_output data: tests/_data helpers: tests/_support settings: bootstrap: _bootstrap.php colors: true memory_limit: 1024m modules: config: db: dsn: 'pgsql:host=localhost;dbname=myapp' user: 'someuser' password: 'somepass' dump: tests/_data/dump.sql

acceptance.suite.yml:

class_name: acceptancetester modules: enabled: - acceptancehelper - laravel4 - phpbrowser - db config: phpbrowser: url: 'http://localhost' laravel4: cleanup: false db: populate: true cleanup: false

firstly, should not utilize laravel4 module codeception acceptance tests. functional , unit tests. see reply more info on issue.

to reply specific question automatically logging in user on acceptance tests - how it:

/tests/_support/acceptancehelper.php

<?php namespace codeception\module; utilize \acceptancetester; class acceptancehelper extends \codeception\module { // default user utilize tests public function loginuser(acceptancetester $i) { $this->login($i, 'user@test.com', 'tester'); } // , function lets me login specific user if need else public function login(acceptancetester $i, $email, $password) { $i->amonpage('/login'); $i->fillfield('email', $email); $i->fillfield('password', $password); $i->click('submit'); $i->seecurrenturlequals('/dashboard'); } public function logoutuser(acceptancetester $i) { $i->amonpage('/logout'); $i->seecurrenturlequals('/login'); $i->see('you have been logged out'); } }

/tests/acceptance/examplecest.php

<?php utilize \acceptancetester; class examplecest { public function _before(acceptancetester $i) { $i->loginuser($i); } public function trytoviewdashboard(acceptancetester $i) { // user logged in here $i->amonpage('/dashboard'); } public function tryotherexample(acceptancetester $i) { // user logged in here $i->amonpage('/dashboard'); } public function trymoreinfo(acceptancetester $i) { // user logged in here $i->amonpage('/dashboard'); } }

note: utilize smallcase $i instead of $i - find easier type - might need alter $i $i in code

php laravel codeception

No comments:

Post a Comment