简体   繁体   English

使用Laravel和Lang :: get()进行代码接收“ ErrorException数组到字符串的转换”

[英]Codeception “ErrorException array to string conversion” with Laravel and Lang::get()

I've already opened an issue on Codeception Github Repository so if you want to stay update on there you're welcome. 我已经在Codeception Github存储库上打开了一个问题,因此,如果您想在那里保持最新状态,欢迎您。

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). 基本上,当您使用Laravel4模块在Codeception中编写功能测试时,似乎无法使用Lang::get()语句或其中的trans()帮助器“解析”任何类型的视图(两者都做相同的工作)。

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. 我发现这个错误的原因是使用Bootstrap构建了一个简单的注册表单(用于CSS和其他东西),并且使用Lang::get()进行本地化,因此这个未来的Web应用程序必须是多语言的,因此我需要它。

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 这是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'
        ],
    ]

];

And this is the login.blade.php part that use the lang file. 这是使用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>

Is there anyone who solved this trouble? 有谁解决了这个麻烦?

Maybe, and I repeat MAYBE , I found the solution to the problem 也许,然后我重复MAYBE ,我找到了解决问题的方法

It seems that you MUST specify all the parameters when you write down {{ Lang::get() }} 写下{{ 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') }} {{ trans('common.date.days.1') }}{{ 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 只需将其放入tests/functional/_bootstrap.php

App::setLocale('en');

:D :d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ErrorException 数组到字符串的转换 Laravel 8 - ErrorException Array to string conversion Laravel 8 带有转发器字段的 Laravel 表单提交中的 ErrorException 数组到字符串转换 - ErrorException Array to string conversion in Laravel form submission with repeater fields ErrorException 数组到字符串的转换 Laravel - 将 JSON 导入到 MySQL - ErrorException Array to string conversion Laravel - Importing JSON to MySQL Laravel 中的 ErrorException (E_NOTICE) 数组到字符串的转换 - ErrorException (E_NOTICE) Array to string conversion in Laravel 在 laravel 中上传图像时数组到字符串转换 ErrorException - Array to string conversion ErrorException while uploading image in laravel 7 ErrorException:PHP中的数组到字符串的转换 - ErrorException : Array to string conversion in PHP 迁移--seed时将ErrorException数组转换为字符串 - ErrorException array to string conversion on migrate --seed ErrorException 数组到 Controller 文件中的字符串转换 - ErrorException Array to string conversion in Controller file ErrorException [注意]:数组到字符串转换PHP表单 - ErrorException [Notice]:Array to string conversion PHP Form 提交表单时出现“ErrorException 数组到字符串的转换” - "ErrorException Array to string conversion" when submitting a form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM