问题
I'm struggling a bit with codeception right now. I work on a laravel 4 project. From now on we used PhpUnit to uni test normally but we have too much Javascript in our pages to do acceptance tests with a simple DomCrawler it's a non sense. First i installed selenium + chrome on a vagrant VM. Took me some times but i managed to get it to work, meaning i can browse the Webdriver webpage (/wd/hub) then create a new session using chrome with success.
Next i installed codeception via composer I did
codecept bootstrap
I added Laravel4 as a module to acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- AcceptanceHelper
- Laravel4
config:
WebDriver:
url: 'https://192.168.33.10/'
browser: 'chrome'
I did a codecept build. Then i wrote a very simple acceptanceTest just to check if everything works :
$I = new AcceptanceTester($scenario);
$I->am('a member');
$I->wantTo('connect');
$I->amOnRoute('login');
$I->see('someText');
When i do a codecept run it raises an error on screen :
[LogicException] You must call one of in() or append() methods before iterating over a Finder.
In the Selenium WebDriver Page , it says a chrome session has been created.
I made some searches about thet error. It comes from the Finder component of Symfony.
Can someone helps me ?
回答1:
You'll have to choose if you want WebDriver or Laravel4 as your "browser", unfortunately you cannot have both and this might be the source of your problems. If you need Javascript, you probably will need to keep WebDriver and loose some Laravel functionalities, but not much, in my opinion. And if you really need Laravel, this is a helper I created to get it inside _support/FunctionalHelper:
public function getLaravel4()
{
if ( ! isset($this->laravel4))
{
$this->laravel4 = (new \Codeception\Module\Laravel4());
$this->laravel4->kernel = app();
}
return $this->laravel4;
}
So in your test you just need to:
$L = $I->getLaravel4();
But, remember, since Laravel is not your browser, things like:
$L->amOnRoute('login');
Will not work, but you'll be able to do things not related to browsing, like:
$L->seeRecord('users', [
'email' => 'a@b.com',
'first_name' => 'a',
'last_name' => 'b'
]);
Also, you can boot laravel on your _bootstrap file:
include __DIR__ . '/../vendor/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/start.php';
$app->boot();
And have direct access to the IoC container:
$app = app();
$app['config']->get('...');
Or even Facades:
DB::table('users')->...
来源:https://stackoverflow.com/questions/26017882/working-with-codeception-and-laravel