Wziąłem sobie na warsztat Codeception jak narzędzie do testów funkcjonalnych (a może i pozostałych).
Utworzyłem sobie test:
<?php $I = new FunctionalTester($scenario); $I->am('a guest'); $I->wantTo('register new user'); $I->amOnRoute('home'); $I->SeeLink('Register', route('register.create', null, false)); $I->click('Register'); $I->amOnRoute('register.create'); $I->fillField('username', 'Test'); $I->fillField('email', 'test@gmail.com'); $I->fillField('password', 'test'); $I->fillField('password_confirmation', 'test'); $I->click('Register', 'input[type=submit]'); $I->canSeeInDatabase('users', ['username'=>'Test', 'email'=>'test@gmail.com']); $I->amOnRoute('home'); $I->canSeeSessionHasValues(['flash_message']); $I->amLoggedAs(['email'=>'test@gmail.com']); $I->cantSeeLink('Register');
Jednak metoda "canSeeInDatabase" wymaga jak nazwa wskazuje BD i odpowiednich tabelek. Wpadłem na pomysł aby zatroszczył się o artisan:migrate.
W pliku tests/_support/FunctionalHelper.php dodałem sobie takie coś:
<?php namespace Codeception\Module; use Codeception\Module; class FunctionalHelper extends Module { public function _beforeSuite($settings = []) { $I = $this->getModule('Laravel4'); $artisan = $I->grabService('artisan'); $artisan->call('migrate:install'); } }
Niby jest ok, ale nie jest.
dd($artisan->call('migrate:install'));
zwraca Int(0) czyli zero/false/null nie wiem. Żadnego wyjątku, nic a jednak testy dalej krzyczą że nie ma tabeli users.
Mam utworzoną migrację z tą tabelą.
Jak dodam jeszcze
dd(\App::environment()); // string(7) "testing"
Pliki:
functional.suite.yml
Kod
class_name: FunctionalTester
modules:
enabled: [Filesystem, FunctionalHelper, Laravel4, Db, Cli]
modules:
enabled: [Filesystem, FunctionalHelper, Laravel4, Db, Cli]
codeception.yml
Kod
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: 'sqlite:memory'
user: ''
password: ''
dump: tests/_data/dump.sql
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: 'sqlite:memory'
user: ''
password: ''
dump: tests/_data/dump.sql
Jakieś pomysły?