我已经在Codeception Github Repository上打开了一个问题,所以如果你想在那里保持更新,欢迎你。
顺便说一下,即使在这里我也会解释我的问题,也许有人已经得到了解决方案。
基本上,当您使用Laravel4模块在Codeception中编写功能测试时,您似乎无法使用Lang::get()
语句或其中的trans()
帮助程序“解析”任何类型的视图(两者都执行同样的工作)。
例如这个
@extends('layout.main')
@section('container')
<div>
{{ Lang::get('path.to.lang.file') }}
</div>
@stop
如果您尝试使用codeception进行测试,则会引发异常。我发现这个错误是使用Bootstrap构建的简单注册表单(用于CSS和东西),并使用Lang::get()
进行本地化,这个未来的Web应用程序必须是多语言,所以我需要它。
我在这里粘贴了完整的堆栈错误,但您甚至可以在问题链接上找到它。
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}
login.blade.php
使用的文件非常非常简单,位于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'
],
]
];
这是使用lang文件的login.blade.php
部分。
<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>
有没有人解决了这个问题?
答案 0 :(得分:1)
也许,我重复 MAYBE ,我找到了问题的解决方案
您写下{{ Lang::get() }}
例如,回答我的问题,我要纠正
中的所有陈述 {{ trans('common.date.days.1') }}
或{{ Lang::get('common.date.days.1') }}
到
{{ trans('common.date.days.1', [], 'en') }}
但显然这是最诚实的解决方案。
编辑: 实际上,我找到了真正的解决方案,并不像上面的混乱......
只需将tests/functional/_bootstrap.php
放在此内
App::setLocale('en');
:d