Question

I'm trying to get into using codeception for my acceptance testing.

I have the following for one of my tests:

<?php
use Codeception\Util\Stub;

class SomeTest extends \Codeception\TestCase\Test
{

    protected $webGuy;

    /**
     * @test
     */
    public function incorrect_login_should_redirect_back()
    {
        $I = $this->webGuy;
        $I->wantTo('fail at logging in');
        $I->amOnPage('/'); // <-- This is the line that is failing
        $I->fillField('email','info@tntstudio.hr');
        $I->fillField('password','pass');
        $I->click('Login');
        $I->see('email', 'input');
        $I->seeCurrentUrlEquals('/login');
    }

}

Initially the tests ran OK, however after adding Laravel4 to the acceptance.suite.yml file and running build, the test now fails with the following:

1) SomeTest::incorrect_login_should_redirect_back
Symfony\Component\HttpKernel\Exception\NotFoundHttpException: 

#1  /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1021
#2  /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Routing/Router.php:989
#3  /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Routing/Router.php:968
#4  /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:738
#5  /Applications/MAMP/htdocs/hired/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:708
#6  /Applications/MAMP/htdocs/hired/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Client.php:81
#7  /Applications/MAMP/htdocs/hired/vendor/symfony/browser-kit/Symfony/Component/BrowserKit/Client.php:325
#8  /Applications/MAMP/htdocs/hired/app/tests/acceptance/WebGuy.php:476
#9  /Applications/MAMP/htdocs/hired/app/tests/acceptance/SomeTest.php:16

I'm running my app in a virtual environment using vagrant, at http://localhost:3030/

I have set this to the url for the PhpBrowser config in acceptance.suite.yml as below:

class_name: WebGuy
modules:
    enabled:
        - PhpBrowser
        - WebHelper
        - Laravel4
    config:
        PhpBrowser:
            url: 'http://localhost:3030/'

I'm wondering if anybody else has come across this, or has any ideas on how to get around this, I've been tearing my hair out for hours on this.

Was it helpful?

Solution 3

Was not able to find a solution to this, so for now am going to just go without the Laravel4 module, sadly.

OTHER TIPS

Laravel4 module will cause Codeception to use the "testing" environment in Laravel.

Laravel will disable all route filters in "testing" environment - so your filters are not working correctly and its probably calling the wrong route, causing your app to die and your test to fail.

I dont think using the Laravel4 module with "acceptance" tests is correct - it should only be for functional tests? Edit: I just found that the Codeception Laravel4 module docs actually say "This module allows you to run functional tests for Laravel 4" - so I guess it was not actually designed for Acceptance tests?

But with all the changes in Codeception 2.x - you are better off using PhpBrowser module for your acceptance tests, and Laravel4 module for your functional tests.

If you are using Homestead, I do this in my start.php file to detect if Codeception is running, and specifically put it into a 'codeception' environment, otherwise I let it run my environment detection normally

if ((gethostname() === 'homestead') && (isset($_SERVER['REMOTE_ADDR'])) && ($_SERVER['REMOTE_ADDR'] === '127.0.0.1'))
{
    $env = $app->detectEnvironment(['codeception' => ['homestead']]);
}
else
{
    $env = $app->detectEnvironment(['dev' => ['homestead']]);
}

Then in my 'codeception' environment, I setup a SQLite file database, and run acceptance tests against that (which is faster than mySQL testing).

You don't even have to change your start.php. You can set the environment for codecption in the laravel4 Module config. So in your acceptance.suite.yml it will look like this:

modules: enabled: [PhpBrowser, WebHelper, Laravel4] config: Laravel4: environment : 'codeception' filters : true

Now, when you execute php codecept run acceptance in your terminal, the Laravel4 Module will use the configuration files from app/config/codeception.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top