我刚刚使用常规的composer命令创建了一个新的Symfony 2.5项目:
php composer.phar create-project symfony/framework-standard-edition path/ 2.5.0
Run Code Online (Sandbox Code Playgroud)
终端问我:
你想使用Symfony 3目录结构吗?
这个Symfony 3目录结构是什么?我以前从未见过它......自2.5以来它是新的吗?
使用它有什么好处?
有没有办法复制这个目录结构?
我的DoctrineFixturesBundle已安装,我可以通过命令行加载夹具但是,如何从功能测试中加载夹具?
我正在尝试在功能测试中测试电子邮件...
控制器:
public function sendEmailAction($name)
{
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('send@example.com')
->setTo('recipient@example.com')
->setBody('You should see me from the profiler!')
;
$this->get('mailer')->send($message);
return $this->render(...);
}
Run Code Online (Sandbox Code Playgroud)
而且测试:
// src/Acme/DemoBundle/Tests/Controller/MailControllerTest.php
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class MailControllerTest extends WebTestCase
{
public function testMailIsSentAndContentIsOk()
{
$client = static::createClient();
// Enable the profiler for the next request (it does nothing if the profiler is not available)
$client->enableProfiler();
$crawler = $client->request('POST', '/path/to/above/action');
$mailCollector = $client->getProfile()->getCollector('swiftmailer');
// Check that an e-mail was sent
$this->assertEquals(1, …Run Code Online (Sandbox Code Playgroud) 我正在使用KnpGaufretteBundle在Amazon S3上存储图片,我可以使用以下代码轻松创建文件:
public function s3CreatFileAction(Request $request) {
$filesystem = $this->get('knp_gaufrette.filesystem_map')->get('profile_photos');
$filesystem->write('test.txt', 'hello world');
[...]
}
Run Code Online (Sandbox Code Playgroud)
问题是我无法访问该文件...
$filesystem = $this->get('knp_gaufrette.filesystem_map')->get('profile_photos');
$file = $filesystem->get('test.txt');
Run Code Online (Sandbox Code Playgroud)
我收到以下消息:
找不到文件"test.txt".
我认为这是因为"test.txt"文件是使用"私有"acl创建的(当我将其公开时,我可以访问它的S3控制台).
所以我的问题是如何在创建对象时定义公共acl?
我想检索实体中具有注释 @Translatable 的所有字段,例如:
class WonderfulClass
{
/**
* @var string
* @Gedmo\Translatable
*/
private $aField;
/**
* @var string
* @Gedmo\Translatable
*/
private $otherField;
/**
* @var string
*/
private $lastField;
Run Code Online (Sandbox Code Playgroud)
在本例中,我想检索具有 @Gedmo\Translatable 注释的字段($aField 和 $otherField)。
有人知道该怎么做吗?
我在我的 Symfony heroku 应用程序中添加了一个 heroku/nodejs buildpack,并且我能够安装我的纱线依赖项。
但是我无法运行
$ yarn run encore production
Run Code Online (Sandbox Code Playgroud)
Command "encore" not found无论我在 composer.json 中运行命令,我总是有同样的错误:
// composer.json
"compile": [
"node_modules/.bin/encore production",
[•••]
Run Code Online (Sandbox Code Playgroud)
或在 package.json
//package.json
"scripts": {
"heroku-postbuild" : "yarn run encore production"
[•••]
Run Code Online (Sandbox Code Playgroud) 我对如何在 symfony 4 中为测试环境设置数据库感到困惑。我曾经在 symfony 3 及以下版本的config_test.yml文件中处理它。
最佳做法是什么?我应该在config/packages/test 中重新创建一个dotric.yaml文件吗?
该文档提到了如何通过编辑 phpunit 配置使用数据库运行功能测试:
<phpunit>
<php>
<!-- the value is the Doctrine connection string in DSN format -->
<env name="DATABASE_URL" value="mysql://USERNAME:PASSWORD@127.0.0.1/DB_NAME" />
</php>
<!-- ... -->
</phpunit>
Run Code Online (Sandbox Code Playgroud)
但是它不能满足我的需求,因为我需要能够将架构/加载装置更新到测试环境。
我在一个简单的过程中被困了 2 个小时,因为我对 bash 脚本和正则表达式感到不舒服:(
我想使用 bash 脚本下载文件。可通过具有以下名称模式的 url 访问目标文件:
https://domain-name.com/JAWSDB_xxxxxxxxxxxxxxxxx.sql.gz?AWSAccessKeyId=XXXXXXXXXXXXXXXX&Expires=xxxxxx&Signature=%2XXXXXXXXXXXXXXXXXXXX
Run Code Online (Sandbox Code Playgroud)
我的第一个想法是使用curl -O,但它会创建非常脏的文件名,包括url参数,所以我只想保留以下部分JAWSDB_xxxxxxxxxxxxxxxxx.sql.gz(并删除尾随url参数)。
我发现一个正则表达式.+?(?=\?)似乎删除了 url prams,但我不知道如何使其与该curl -O命令一起使用。
多谢。
(Ps:我正在osx上开发,打算在linux上运行脚本)
我正在使用 Heroku 以默认配置部署我的 Symfony2 应用程序,但不会转储资产。
我已经添加到 composer.json :
...
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"php app/console --env=prod assetic:dump"
]
},
...
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?
在 Procfile 中,不起作用。与 :
heroku run php app/console --env=prod assetic:dump
Run Code Online (Sandbox Code Playgroud)
也不起作用。
谢谢,
参考:https : //devcenter.heroku.com/articles/getting-started-with-symfony2