Codeception - Laravel 4 - All functional tests fail since running composer update
I have a Laravel 4 application running on my development machine (MacBook Pro, 15-inch, Mid 2010) under a Homestead environment.
My testing environment is setup in the same was as was demonstrated in the 'Build Larabook From Scratch' series.
I have three test suites: functional, integration and unit. Both my integration and unit tests are still working completely fine.
However, since running composer self-update and composer update yesterday when attempting to install 'DOMPDF Wrapper for Laravel 4' ("barryvdh/laravel-dompdf": "0.4.*"), my functional tests have randomly stopped working, with every single test yielding 'Error' instead of 'Pass' or 'Fail'.
I immediately removed this dependancy yet the tests continue to result in 'Error'.
I have tried checking out previous git commits and running the tests however the same errors arise. All tests must pass before a git commit is made so I see no reason why this would not have worked.
I have also tried removing codeception and all tests completely, reinstalling codeception and then copying over a few tests. The same errors occured.
I have also tried explicitly specifying an older version of codeception in my composer.json file and using this instead of using "~2.0".
The application is working perfectly both in development and production, it is only the test suite that is not working. However, no further development can be done until the test suite is working.
All of my functional tests rely on signing in a user, apart from one which registers a user. This is done in the way demonstrated by Jeffrey Way in the online tutorial series I previously mentioned, with a sign in helper method being referenced at the beginning of each test.
This is because all controller actions other than those that facilitate logging in, etc. are protected by an authentication filter.
When running vendor/bin/codecept run functional --debug -vvv the output for each test is as follows:
8) Failed to login to an account in Sessions/SignInCept (tests/functional/Sessions/SignInCept.php)
[ErrorException] Trying to get property of non-object (View: /home/vagrant/insightsa/app/views/pages/home.blade.php)
Scenario Steps:
2. $I->signIn() at tests/functional/Sessions/SignInCept.php:7
1. // As an an Insight member
#1 /home/vagrant/insightsa/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php:41
#2 /home/vagrant/insightsa/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php:56
#3 /home/vagrant/insightsa/vendor/laravel/framework/src/Illuminate/View/View.php:134
#4 /home/vagrant/insightsa/vendor/laravel/framework/src/Illuminate/View/View.php:102
#5 /home/vagrant/insightsa/vendor/laravel/framework/src/Illuminate/View/View.php:76
#6 /home/vagrant/insightsa/vendor/laravel/framework/src/Illuminate/Http/Response.php:43
#7 /home/vagrant/insightsa/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php:202
#8 /home/vagrant/insightsa/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1501
#9 /home/vagrant/insightsa/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1036
#10 /home/vagrant/insightsa/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1001
The test that I have used as an example above, SignInCept.php, is as follows:
<?php
$I = new FunctionalTester($scenario);
$I->am('an Insight member');
$I->wantTo('login to an account');
$I->signIn();
$I->seeCurrentUrlEquals('');
$I->see('Login successful.');
$I->assertTrue(Auth::check());
The signIn function is referenced from a FunctionalHelper class:
class FunctionalHelper extends \Codeception\Module {
/**
* @throws \Codeception\Exception\Module
*/
public function signIn()
{
$I = $this->getModule('Laravel4');
$password = "test";
$user = $this->haveAnAccount(compact('password'));
$I->amOnPage('/login');
$I->fillField('email', $user->email);
$I->fillField('password', $password);
$I->click('Sign In');
}
/**
* @param $model
* @param array $overrides
* @return mixed
*/
public function have($model, $overrides = [])
{
return TestDummy::create($model, $overrides);
}
/**
* @param array $overrides
* @return mixed
*/
public function haveAnAccount($overrides = [])
{
return $this->have('Insight\Users\User', $overrides);
}
...
On logging a user in, a controller renders the view home.blade.php. The only variable that this view makes use of is $currentUser like so:
{{ $currentUser->username }}
and also like so:
@if($currentUser->email == "user@example.com")
...
@endif
This variable is exposed to the view via the BaseController that all other controllers extend:
protected function setupLayout()
{
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
View::share('currentUser', Auth::user());
}
My functional.suite.yml file is as follows:
# Codeception Test Suite Configuration
# suite for functional (integration) tests.
# emulate web requests and make application process them.
# Include one of framework modules (Symfony2, Yii2, Laravel4) to use it.
class_name: FunctionalTester
modules:
enabled: [Filesystem, FunctionalHelper, Laravel4, Asserts, Db]
Any help would be very much appreciated as I cannot continue to work for my client on this project until I get this sorted.
Thank you in advance.
Please or to participate in this conversation.