Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Laravel] Testowanie Codeception - problem z Artisan
Pyton_000
post 13.09.2014, 06:29:19
Post #1





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


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?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 12:38