有没有办法确定参数是否是Doctrine已经持久化的对象?类似于实体管理器方法的东西,它检查对象不是普通的旧对象,但实际上已存在于内存中的东西/持久化.
<?php
public function updateStatus(Entity $entity, EntityStatus $entityStatus)
{
$entityManager = $this->getEntityManager();
try {
// checking persisted entity
if (!$entityManager->isPersisted($entity)) {
throw new InvalidArgumentException('Entity is not persisted');
}
// ...
} catch (InvalidArgumentException $e) {
}
}
Run Code Online (Sandbox Code Playgroud) 使用Zend Framework,有没有办法使用quoteInto方法将多个条件传递给更新语句?我发现了一些对这个问题的引用,但我正在寻找一种支持的方式,而不必扩展Zend_Db或没有连接.
$db = $this->getAdapter();
$data = array('profile_value' => $form['profile_value']);
$where = $db->quoteInto('user_id = ?', $form['id'])
. $db->quoteInto(' AND profile_key = ?', $key);
$this->update($data, $where);
Run Code Online (Sandbox Code Playgroud)
参考
这个页面上的信息似乎不那么快了 - https://github.com/kof/node-qunit.我有一个安装nodejs的设置并安装了node-quit模块.我有测试运行器并执行命令node /path/to/runner.js.以下是我的设置示例.关于如何做到这一点的任何想法或例子,或者我使用它的错误.我之前使用Rhino和EnvJs运行qunit测试没有任何问题,但我想我尝试nodejs,因为我将它用于其他事情,包装系统可以在我的构建中编写脚本.也许我错过了一个节点选项,包括Qunit或一些未设置的环境变量 - 这是有道理的.
文件结构
node/
public/
js/
main.js
tests/
js/
testrunner.js
tests.js
Run Code Online (Sandbox Code Playgroud)
安装
cd node
npm install qunit
Run Code Online (Sandbox Code Playgroud)
现在,这将更新文件结构.
node/
node_modules/
qunit/
Run Code Online (Sandbox Code Playgroud)
测试/ JS/testrunner.js
var runner = require("../../node/node_modules/qunit");
runner.run({
code : "/full/path/to/public/js/main.js",
tests : "/full/path/to/tests/js/tests.js"
});
Run Code Online (Sandbox Code Playgroud)
测试/ JS/tests.js
test("Hello World", function() {
ok(true);
});
Run Code Online (Sandbox Code Playgroud)
命令
node tests/js/testrunner.js
Run Code Online (Sandbox Code Playgroud) 响应是JSON,我使用的是定制的MVC框架,我不确定如何生成请求和响应过程.使用以下语法创建服务方法.
public function getSessionsMethod()
{
// data auto encoded as JSON
return array('hello', 'world');
}
Run Code Online (Sandbox Code Playgroud)
JavaScript的请求看起来像这样/svc/api/getSessions.我最初的想法是简单地使用流方法是否有这种形式的测试的最佳实践?
public function testCanGetSessionsForAGivenId()
{
$params = http_build_query(
array(
'id' => 3,
)
);
$options = array(
'http' => array(
'method' => 'GET',
'content' => $params,
)
);
$context = stream_context_create($options);
$response = file_get_contents(
'http://vbates/svc/api/getSessions', false, $context
);
$json = json_decode($response);
$this->assertEquals(3, $json->response);
}
Run Code Online (Sandbox Code Playgroud) 我正在脚本中生成一个shell脚本,它需要root权限才能使用
sudo bash -c "echo 'Hello There!' > '/var/www/cgi-bin/php-cgi-5.3.8'"
Run Code Online (Sandbox Code Playgroud)
如果我尝试输出shebang行并且我不确定如何逃避它,我会收到错误 - 就像我使用其他变量一样.
sudo bash -c "echo '#!/bin/bash
version=\"5.3.8\"
export PHPRC=/etc/php/phpfarm/inst/php-\${version}/lib/php.ini
export PHP_FCGI_CHILDREN=3
export PHP_FCGI_MAX_REQUESTS=5000
exec /etc/php/phpfarm/inst/php-\${version}/bin/php-cgi' > '/var/www/cgi-bin/php-cgi-5.3.8'"
Run Code Online (Sandbox Code Playgroud)
我在哪里错了?