- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
不完全确定是什么导致了这个问题,特别是因为我已经遵循了官方文档。我也在这里阅读了无数 Google Group 讨论和问题,但都无济于事。
所以我一直在 Fabien Potencier 的 Silex Skeleton 之上构建我的应用程序,但是我的单元测试在一个页面上失败了,该页面上有一个使用 FormServiceProvider 的表单。
PHPUnit 3.6.12 by Sebastian Bergmann.
Configuration read from /Users/Adam/Sites/AppEngine/phpunit.xml
..E
Time: 0 seconds, Memory: 10.00Mb
There was 1 error:
1) Acme\AppEngineTest::testAppControllerForm
session_start(): Cannot send session cookie - headers already sent by (output started at /usr/local/php5-20120823-092307/lib/php/PHPUnit/Util/Printer.php:173)
我现在只有一个测试类
namespace Acme;
use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
class AppEngineTest extends WebTestCase
{
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
if (! defined('BASEPATH')) {
define('BASEPATH', __DIR__.'/../..');
}
}
public function createApplication()
{
$app = require BASEPATH.'/src/app.php';
$app['debug'] = true;
$app['exception_handler']->disable();
$app['session.storage'] = $app->share(function() {
return new MockArraySessionStorage();
});
$app['session.test'] = true;
require BASEPATH.'/config/prod.php';
require BASEPATH.'/src/controllers.php';
return $app;
}
public function testIndex()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/');
$this->assertTrue($client->getResponse()->isOk());
}
public function testAppControllerIndex()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/app/');
$this->assertEquals($client->getResponse()->isOk());
$this->assertCount(1, $crawler->filter('p:contains("Please choose an app from the following")'));
}
// This test fails
public function testAppControllerForm()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/app/form');
$this->assertTrue($client->getResponse()->isOk());
}
}
PHP单元配置
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Test Suite">
<directory>tests/Acme</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<php>
<server name="HTTP_USER_AGENT" value="PHPUnit"/>
</php>
</phpunit>
在 controllers.php 中,我安装了一个包含表单的 Controller
use Acme\Controller\FacebookAppControllerProvider;
$app->mount('/app/', new FacebookAppControllerProvider());
看起来像这样
<?php
namespace Acme\Controller;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\Provider\FacebookServiceProvider;
use SlotMachine\Page as PageContainer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Yaml\Yaml;
class FacebookAppControllerProvider implements ControllerProviderInterface
{
public function connect(Application $app)
{
if (! $app['twig']->hasExtension('silex_asset_path')) {
throw new \OutOfBoundsException(
'The `silex_asset_path` Twig extension provided by this library has not been registered.'
);
}
// creates a new controller based on the default route
$controllers = $app['controllers_factory'];
$app->register(new FacebookServiceProvider(), [
'facebook.config' => [
'appId' => '1',
'secret' => '2',
'sharedSession' => true,
'trustForwarded' => true,
'fileUpload' => false
],
'facebook.permissions' => [ 'email' ],
]);
$app['facebook_app.widget_data'] = [
'foo' => [
'name' => 'Foo'
],
'bar' => [
'name' => 'Bar'
]
];
$controllers->match('/', function (Application $app) {
return $app->render("facebook_app/index.html.twig", $app['facebook_app.widget_data']);
})->method('POST|GET');
$controllers->match('/app/{widget}/{tp}', function (Request $request, Application $app, $widget, $tp) {
$slots = new PageContainer(Yaml::parse(BASEPATH.'/src/Acme/Resources/config/'.$widget.'.slots.yml'));
// some default data for when the form is displayed the first time
$formData = [
'forename' => 'First-Name',
'surname' => 'Last-Name',
'telephone' => 'Telephone',
];
$form = $app->form($formData)
->add('forename', 'text', [ 'label' => 'Name' ])
->add('surname', 'text', [ 'label' => false ])
->add('telephone')
->getForm()
; //end
if ('POST' == $request->getMethod()) {
$form->bind($request);
if ($form->isValid()) {
$data = $form->getData();
// do something with the data
// redirect somewhere
return $app->redirect('/');
}
}
$pageData = [
'slot' => $slots->all(),
'template_number' => $tp,
'widget' => [
'slug' => $widget,
'name' => $app['facebook_app.widget_data'][$widget]['name']
],
'form' => $form->createView(),
];
foreach ($pageData['slot'] as $slot => &$card) {
$card = PageContainer::interpolate($card, [
'widget_name' => $pageData['widget']['name']
]);
}
$app['page_data'] = $pageData;
return $app->render(sprintf('templates/%s/template_%d.html.twig', $widget, $tp), $app['page_data']);
})
->method('POST|GET')
->assert('tp', '\d+')
->value('tp', 1)
; // end /app/{publication}/{tp} Controller
return $controllers;
}
}
在 app.php 中,FormServiceProvider 在实例化新的 Silex 应用程序之后以及添加 Twig 扩展之前立即注册。
$app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
// add custom globals, filters, tags, ...
$twig->addExtension(new Acme\Twig\SilexAssetPathExtension($app));
return $twig;
}));
最佳答案
有一个更好的方法,Symfony 允许您启用不使用“session_*”功能的测试 session 模式。我不确定如何在 Silex 中启用此功能,但您必须在 Symfony 中启用模拟文件存储。
storage_id: session.storage.mock_file
Silex 的文档在这里:http://silex.sensiolabs.org/doc/providers/session.html
关于symfony - Silex 网络测试用例 : Cannot send session cookie headers already sent by PHPUnit/Util/Printer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16317646/
我很难理解为什么这段代码无法编译: use std::cell::{Ref, RefCell}; struct St { data: RefCell } impl St { pub f
我从Richard Blum的一本书《 C#网络编程》中读到有关套接字的信息。以下摘录指出,不保证Send()方法可以发送所有传递给它的数据。 byte[] data = new byte[1024]
我有以下程序,它必须一次读取 1MB 的文件,将其发送到服务器(每次总是 1MB)并返回哈希码: #include #include #include #include #include #
代码在底部。 第 207 行的 send() 命令本身可以正常工作。但是,当我在第 218 行添加 send() 命令时,第一个命令失败 - 给出错误“地址错误”。我已经确认第二个 send() 命令
标记包含 !Send 的类型背后的原因是什么?字段(如 Rc 或 NonNull )与 Send特征?例如,标准库的 LinkedList 以这种方式工作:它包含 Option>字段并实现 Send特
我是新手,我正在尝试学习 goroutines 中信号函数的一些基本用法。我在 go 中有一个无限循环。通过这个 for 循环,我通过 channel 将值传递给 goroutine。 我也有一个阈值
如果数据是从另一台计算机(首先)“发送”的,我如何设置我的套接字例程以“发送”(首先)或(切换)“接收”? 谢谢 通用代码: -(void) TcpClient{ char buffer[12
这个问题已经有答案了: Java multiple file transfer over socket (3 个回答) 已关闭 4 年前。 我正在使用 Java Socket 将文件发送到服务器,然后
根据以下示例中的类型,Go编译器似乎将执行两个完全不同的语义操作: chanA <-chanB 如果chanA是类型(chan chan <-字符串),则此操作会将本身类型chanB的类型(chan
我正在尝试在 VBA 中使用 WinSock2 从本地主机 TCP 流发送(以及稍后接收)数据。 目前,我主要尝试从此处复制客户端示例,https://msdn.microsoft.com/en-us
我在我的 Mac OS X Yosemite 控制台中看到了这个: AppleEvents: Send port for process has no send right, port=( port:
我知道Clojure的“代理”是ref,带有“操作”的添加工作队列。 Action 是使用ref的值在第一个位置调用的函数,可以将其传递给其他参数。操作将返回ref的新值。因此,“代理”是一种计算re
我无法将任何对象或数组传递给 IPCRenderer。 通过 ipcs 传递对象或数组时出现错误,我什至尝试通过使用 JSON.stringify 转换为字符串来发送,但它会将其转换为空对象字符串。
我正在使用unix scoket进行数据传输(SOCK_STREAM模式) 我需要发送超过100k个字符的字符串。首先,我发送一个字符串的长度-它是sizeof(int)个字节。 length = s
Clojure API 将这两个函数描述为: (send a f & args) - Dispatch an action to an agent. Returns the agent immedia
def send_Button(): try: myMsg = "ME: " + text.get() msg = text.get() con
Ruby 对象都有一个“发送”方法,但是,我正在尝试使用一个 Java 库 ( netty-tools ),它的一个接口(interface)上有一个“发送”方法。 用法应该是 java_obj.se
Feb 8, 2011 11:56:49 AM com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPC onnection post SEVE
来自 man 2 send: MSG_MORE (since Linux 2.4.4) (…) Since Linux 2.6, this flag is also supported for UDP
我的网页中可以有一个按钮,用于将预填充的消息发送到特定号码吗? 我正在尝试 intent://send/+391234567890#Intent;scheme=smsto;package=com.wh
我是一名优秀的程序员,十分优秀!