I've already opened an issue on Codeception Github Repository so if you want to stay update on there you're welcome.
By the way I'll explain my problem even here, maybe someone has got the solution.
Basically when you write a functional test in Codeception with the Laravel4 module it seems that you cannot "parse" any kind of view with the Lang::get()
statement or the trans()
helper inside it (both do the same job).
For example this
@extends('layout.main')
@section('container')
<div>
{{ Lang::get('path.to.lang.file') }}
</div>
@stop
Will raise an exception if you try to test with codeception. I found this bug with a simple registration form built with Bootstrap (for CSS and stuff) and with the use of Lang::get()
for the localization, this future web app must be multilanguage so I need it.
I paste the full stack error here but you can find it even on the issue link.
1) Failed to edit a bunch of data from an actual company in LoginAndEditDataCept (/Users
/Ludo237/Projects/L4/app/tests/functional/LoginAndEditDataCept.php)
Can't be on page "/auth/login":
ErrorException: Array to string conversion (View: /Users/Ludo237/Project/L4/app/views/public/auth/login.blade.php)
Scenario Steps:
2. I am on page "/auth/login"
1. As a An authenticated user
[ErrorException] Array to string conversion (View: /Users/Ludo237/Projects/L4/app/views/public/auth/login.blade.php)
#0 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(41): Illuminate\View\Engines\CompilerEngine->handleViewException(Object(ErrorException))
#1 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(56): Illuminate\View\Engines\PhpEngine->evaluatePath('/Users/Ludo237/...', Array)
#2 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/View/View.php(134): Illuminate\View\Engines\CompilerEngine->get('/Users/Ludo237/...', Array)
#3 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/View/View.php(102): Illuminate\View\View->getContents()
#4 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/View/View.php(76): Illuminate\View\View->renderContents()
#5 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/Http/Response.php(43): Illuminate\View\View->render()
#6 /Users/Ludo237/Projects/L4/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php(202): Illuminate\Http\Response->setContent(Object(Illuminate\View\View))
#7 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1437): Symfony\Component\HttpFoundation\Response->__construct(Object(Illuminate\View\View))
#8 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/Routing/Router.php(999): Illuminate\Routing\Router->prepareResponse(Object(Illuminate\Http\Request), Object(Illuminate\View\View))
#9 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/Routing/Router.php(964): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#10 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(738): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#11 /Users/Ludo237/Projects/L4/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(708): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#12 /Users/Ludo237/Projects/L4/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Client.php(81): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request))
#13 /Users/Ludo237/Projects/L4/vendor/symfony/browser-kit/Symfony/Component/BrowserKit/Client.php(332): Symfony\Component\HttpKernel\Client->doRequest(Object(Illuminate\Http\Request))
#14 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/Lib/InnerBrowser.php(68): Symfony\Component\BrowserKit\Client->request('GET', '/auth/login')
#15 [internal function]: Codeception\Lib\InnerBrowser->amOnPage('/auth/login')
#16 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/Step.php(125): call_user_func_array(Array, Array)
#17 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/TestCase/Shared/Actor.php(67): Codeception\Step->run()
#18 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/Scenario.php(93): Codeception\TestCase\Cept->runStep(Object(Codeception\Step\Condition))
#19 /Users/Ludo237/Projects/L4/app/tests/functional/FunctionalTester.php(523): Codeception\Scenario->runStep(Object(Codeception\Step\Condition))
#20 /Users/Ludo237/Projects/L4/app/tests/functional/LoginAndEditACompanyDataCept.php(7): FunctionalTester->amOnPage('/auth/login')
#21 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/TestCase/Cept.php(64): require('/Users/Ludo237/...')
#22 [internal function]: Codeception\TestCase\Cept->testCodecept()
#23 /Users/Ludo237/Projects/L4/vendor/phpunit/phpunit/src/Framework/TestCase.php(951): ReflectionMethod->invokeArgs(Object(Codeception\TestCase\Cept), Array)
#24 /Users/Ludo237/Projects/L4/vendor/phpunit/phpunit/src/Framework/TestCase.php(817): PHPUnit_Framework_TestCase->runTest()
#25 /Users/Ludo237/Projects/L4/vendor/phpunit/phpunit/src/Framework/TestResult.php(686): PHPUnit_Framework_TestCase->runBare()
#26 /Users/Ludo237/Projects/L4/vendor/phpunit/phpunit/src/Framework/TestCase.php(753): PHPUnit_Framework_TestResult->run(Object(Codeception\TestCase\Cept))
#27 /Users/Ludo237/Projects/L4/vendor/phpunit/phpunit/src/Framework/TestSuite.php(675): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#28 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php(100): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#29 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/SuiteManager.php(153): Codeception\PHPUnit\Runner->doEnhancedRun(Object(PHPUnit_Framework_TestSuite), Object(PHPUnit_Framework_TestResult), Array)
#30 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/Codecept.php(162): Codeception\SuiteManager->run(Object(Codeception\PHPUnit\Runner), Object(PHPUnit_Framework_TestResult), Array)
#31 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/Codecept.php(145): Codeception\Codecept->runSuite(Array, 'functional', 'LoginAndEditACo...')
#32 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/src/Codeception/Command/Run.php(149): Codeception\Codecept->run('functional', 'LoginAndEditACo...')
#33 /Users/Ludo237/Projects/L4/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(252): Codeception\Command\Run->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /Users/Ludo237/Projects/L4/vendor/symfony/console/Symfony/Component/Console/Application.php(887): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /Users/Ludo237/Projects/L4/vendor/symfony/console/Symfony/Component/Console/Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(Codeception\Command\Run), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /Users/Ludo237/Projects/L4/vendor/symfony/console/Symfony/Component/Console/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /Users/Ludo237/Projects/L4/vendor/codeception/codeception/codecept(27): Symfony\Component\Console\Application->run()
#38 {main}
This is the file used by login.blade.php
is very very very simple and it is located under app/lang/en/common.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Common Language Lines
|--------------------------------------------------------------------------
|
|
*/
'date' => [
'days' => [
'1' => 'Monday',
'2' => 'Tuesday',
'3' => 'Wednesday',
'4' => 'Thursday',
'5' => 'Friday',
'6' => 'Saturday',
'7' => 'Sunday'
],
]
];
And this is the login.blade.php
part that use the lang file.
<div class="row">
<div class="auth-box col-xs-12 col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">{{ trans('common.date.days.1') }}</div>
</div>
Is there anyone who solved this trouble?
Maybe, and I repeat MAYBE, I found the solution to the problem
It seems that you MUST specify all the parameters when you write down {{ Lang::get() }}
For example, taking my question, I've to correct all the statement from
{{ trans('common.date.days.1') }}
or {{ Lang::get('common.date.days.1') }}
to
{{ trans('common.date.days.1', [], 'en') }}
but obviously this is the worst solution ever to be honest.
EDIT: Actually I've found the real solution and is not like the mess above...
Simply put inside tests/functional/_bootstrap.php
this
App::setLocale('en');
:D