Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Laravel] Testowanie Codeception - problem z Artisan
Forum PHP.pl > Forum > PHP > Frameworki
Pyton_000
Witajcie.

Wziąłem sobie na warsztat Codeception jak narzędzie do testów funkcjonalnych (a może i pozostałych).

Utworzyłem sobie test:
  1. <?php
  2. $I = new FunctionalTester($scenario);
  3. $I->am('a guest');
  4.  
  5. $I->wantTo('register new user');
  6.  
  7. $I->amOnRoute('home');
  8. $I->SeeLink('Register', route('register.create', null, false));
  9. $I->click('Register');
  10. $I->amOnRoute('register.create');
  11. $I->fillField('username', 'Test');
  12. $I->fillField('email', 'test@gmail.com');
  13. $I->fillField('password', 'test');
  14. $I->fillField('password_confirmation', 'test');
  15. $I->click('Register', 'input[type=submit]');
  16. $I->canSeeInDatabase('users', ['username'=>'Test', 'email'=>'test@gmail.com']);
  17. $I->amOnRoute('home');
  18. $I->canSeeSessionHasValues(['flash_message']);
  19. $I->amLoggedAs(['email'=>'test@gmail.com']);
  20. $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ś:
  1. <?php
  2. namespace Codeception\Module;
  3.  
  4. use Codeception\Module;
  5.  
  6. class FunctionalHelper extends Module
  7. {
  8. public function _beforeSuite($settings = [])
  9. {
  10. $I = $this->getModule('Laravel4');
  11. $artisan = $I->grabService('artisan');
  12. $artisan->call('migrate:install');
  13.  
  14. }
  15. }


Niby jest ok, ale nie jest.

  1. 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
  1. dd(\App::environment());
  2. // string(7) "testing"


Pliki:
functional.suite.yml
Kod
class_name: FunctionalTester
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


Jakieś pomysły?
ctom
Cytat(Pyton_000 @ 13.09.2014, 07:29:19 ) *
  1. <?php
  2. namespace Codeception\Module;
  3.  
  4. use Codeception\Module;
  5.  
  6. class FunctionalHelper extends Module
  7. {
  8. public function _beforeSuite($settings = [])
  9. {
  10. $I = $this->getModule('Laravel4');
  11. $artisan = $I->grabService('artisan');
  12. $artisan->call('migrate:install');
  13.  
  14. }
  15. }



a nie powinno być jeszcze : $artisan->call('migrate');
Pyton_000
Wcześniej miałem samo "migrate" ale też nie dawało żadnego rezultatu, tzn. rezultat ten sam, brak błędu, i 0 na wyjściu
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.