在使用Symfony 3.3时,我在配置PhpStorm IDE以使用http://symfony.com/doc/current/components/phpunit_bridge.html时遇到了问题.
我决定只下载phpunit.phar
到bin
,并用它来代替.
Symfony 3.4(和Symfony 4)甚至没有phpunit.xml.dist
开箱即用,因此使用起来phpunit.phar
很容易.
我使用flex安装了PHPUnit:
composer req phpunit
Run Code Online (Sandbox Code Playgroud)
这创建了phpunit.xml.dist,我能够通过命令行运行测试:
php bin/phpunit
Run Code Online (Sandbox Code Playgroud)
但我再次无法让PhpStorm使用它.
所以我下载了phpunit.phar
它,它可以与提供的phpunit.xml.dist一起使用.
问题1: PhpStorm IDE有没有办法使用phpunit-bridge?
问题2: Symfony 4(phpunit-bridge或vanilla phpunit.phar)的最佳实践是什么?
我有以下表格:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', ChoiceType::class, array(
'expanded' => true,
'multiple' => false,
'choices' => array(
'Friend' => 'friend',
'Guide' => 'guide'
)
));
}
Run Code Online (Sandbox Code Playgroud)
如何在呈现表单时默认选中"朋友"复选框?
我正在将Symfony 3.2项目移植到Symfony 3.3,我想使用DI新功能.我已经阅读了文档,但到目前为止我可以使这个工作.请参阅以下类定义:
use Http\Adapter\Guzzle6\Client;
use Http\Message\MessageFactory;
abstract class AParent
{
protected $message;
protected $client;
protected $api_count_url;
public function __construct(MessageFactory $message, Client $client, string $api_count_url)
{
$this->message = $message;
$this->client = $client;
$this->api_count_url = $api_count_url;
}
public function getCount(string $source, string $object, MessageFactory $messageFactory, Client $client): ?array
{
// .....
}
abstract public function execute(string $source, string $object, int $qty, int $company_id): array;
abstract protected function processDataFromApi(array $entities, int $company_id): array;
abstract protected function executeResponse(array $rows …
Run Code Online (Sandbox Code Playgroud) 我在Ubuntu 14.04服务器中部署了symfony 3应用程序。
当我在命令窗口中执行“ date”时,服务器会回复“ Fri May 11 10:02:30 CEST 2018”,但是当我在树枝中将日期时间转储为“ {{dump(“ now” | date)}}“时,响应为“ May 11,2018 04:04”。
如果输入控制器函数(路由)的标题,则为“ date_default_timezone_set(“ Europe / Madrid”);“ 它工作正常,但我不想在所有控制器的所有功能中都复制此行。
然后,我想知道在哪里可以为所有控制器全局设置时区作为Symfony的配置,或者在哪里可以全局设置此PHP命令(date_default_timezone_set(“ Europe / Madrid”))。
谢谢
[编辑]
一种解决方案可能是将此代码放在控制器的标头中,但我想将其设置为一个,而不是在所有控制器,服务等中……
public function __construct(){
date_default_timezone_set("Europe/Madrid");
}
Run Code Online (Sandbox Code Playgroud) 我在上传文件时遇到问题...我在Symfony表单(要约)中手动添加了一些输入,以允许用户创建新公司(如果他不想使用已经存在的公司),它可以工作非常适合text / textarea字段,但是我的文件Input不能正常工作。它的内容显示在请求参数中,而不是在我的请求的文件参数中,请参阅下面的我在dump($ request)时得到的内容:
OfferController.php on line 173:
Request {#86 ?
+attributes: ParameterBag {#70 ?}
+request: ParameterBag {#69 ?
#parameters: array:2 [?
"offer" => array:15 [?]
"company" => array:6 [?
"name" => "entreprise"
"pic_logo" => "ah.png" //THIS SHOULD NOT BE HERE BUT IN THE FILEBAG
"sector" => "2"
"status" => "fdsfds"
"revenues" => "sdfsdf"
"content" => "<p>sdfdsf</p>\r\n"
]
]
}
+query: ParameterBag {#49 ?}
+server: ServerBag {#73 ?}
+files: FileBag {#63 ?
#parameters: [] //NO FILE HERE :'(
}
Run Code Online (Sandbox Code Playgroud)
这是产生此代码的代码:View: …
在我的 Symfony 3.4 中。应用程序我配置了一个自定义记录器:
monolog:
handlers:
my_channel:
level: debug
type: stream
path: '%kernel.logs_dir%/my_channel.log'
max_files: 10
channels: [my_channel]
Run Code Online (Sandbox Code Playgroud)
当我在代码中使用此记录器时,我已使用通道“my_channel”正确注入了该记录器。
$this->logger->error('error message', $data = ['my context here']);
Run Code Online (Sandbox Code Playgroud)
在屏幕上我正确显示了 $data 信息:
09:00:08 ERROR [my_channel] error message ["my context here"]
Run Code Online (Sandbox Code Playgroud)
但在我的日志中,上下文不是空的:
09:00:08 ERROR [my_channel] error message []
Run Code Online (Sandbox Code Playgroud)
问题:如何将上下文也记录到我的日志文件中?
symfony ×6
symfony3.x ×6
php ×3
logging ×1
monolog ×1
phpstorm ×1
symfony-3.3 ×1
symfony-3.4 ×1
timezone ×1