我真的碰到了这堵砖墙.如何在phpunit中的测试之间传递类值?
测试1 - >设定值,
测试2 - >读取值
这是我的代码:
class JsonRpcBitcoinTest extends PHPUnit_Framework_TestCase
{
public function setUp(){
global $configRpcUser, $configRpcPass, $configRpcHost, $configRpcPort;
$this->bitcoindConn = new JsonRpcBitcoin($configRpcUser, $configRpcPass, $configRpcHost, $configRpcPort);
$this->blockHash = '';
}
/**
* @depends testCanAuthenticateToBitcoindWithGoodCred
*/
public function testCmdGetBlockHash()
{
$result = (array)json_decode($this->bitcoindConn->getblockhash(20));
$this->blockHash = $result['result'];
$this->assertNotNull($result['result']);
}
/**
* @depends testCmdGetBlockHash
*/
public function testCmdGetBlock()
{
$result = (array)json_decode($this->bitcoindConn->getblock($this->blockHash));
$this->assertEquals($result['error'], $this->blockHash);
}
}
Run Code Online (Sandbox Code Playgroud)
testCmdGetBlock()没有得到$this->blockHash应该设置的值testCmdGetBlockHash().
非常感谢帮助理解错误.
我知道这个问题可能已被提出,但我不清楚先前的问题是否足以知道他们是否按照我的意愿行事.
$fruits = array('20' => 'apple', '40' => 'orange', '40' => 'pear');
Run Code Online (Sandbox Code Playgroud)
关键是获取价值的机会的百分比.我想mt_rand()一个0到99之间的数字,并根据这些百分比从$ fruits返回一个值.
很可能我很困惑,因为我不知道如何解释我在寻找什么.
提前感谢您的帮助.
编辑:根据这些机会,想要来自$ fruits的随机值:
我希望有40%的机会获得橘子,40%的机会获得梨,80%的机会获得苹果.
编辑:为了进一步澄清,由于很多答案都错了,(或者我只是不理解他们的代码),无论我选择什么号码,我都需要一个结果,而不仅仅是20,40或40.
我在使用API从Drive获取二进制文件时遇到了问题,我一直在圈子里.
以下是相关的代码位:
// Load client secrets from a local file.
fs.readFile('client_secret.json', function processClientSecrets(err, content) {
if (err) {
console.log('Error loading client secret file: ' + err);
return;
}
// Authorize a client with the loaded credentials, then call the
// Drive API.
oauth.authorize(JSON.parse(content), dasm.init, driveapi.getFile)
});
Run Code Online (Sandbox Code Playgroud)
driveapi.getFile:
function getFile(auth, cb) {
var service = google.drive('v3');
service.files.get({
auth: auth,
pageSize: 20,
fileId: "0B2h-dgPh8_5CZE9WZVM4a3BxV00",
alt: 'media'
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return; …Run Code Online (Sandbox Code Playgroud) 鉴于此对象:
: http://www.w3.org/2005/Atom
gd: http://schemas.google.com/g/2005
openSearch: http://a9.com/-/spec/opensearch/1.1/
app: http://www.w3.org/2007/app;
media: http://search.yahoo.com/mrss/
Run Code Online (Sandbox Code Playgroud)
我如何获得第一个属性的值?我怀疑这是一个简单的过程,但我画了一个空白.提前致谢.
该对象是这样构建的:
服务器端(php):
$namespaces = $feedXML->getNamespaces(true);
$arr = array(
'Status' => 'Success',
'Message' => 'Feed fetched.',
'Namespaces' => $namespaces,
'Feed XML' => $feedXML
);
echo json_encode($arr);
Run Code Online (Sandbox Code Playgroud)
客户端(JS):
var output = '';
for (property in dataj["Namespaces"]) {
output += property + ': ' + dataj["Namespaces"][property] + '; ';
}
alert(output);
Run Code Online (Sandbox Code Playgroud)
我希望能够检查命名空间,看看这是Atom还是RDF.
听起来只是迭代每个属性将是最好的方式.
我需要将一个字符串转换为一组固定长度的数组.
示例:输入: 1111122222333333
我需要输出
[0] =>
[0] => 1
[1] => 1
[2] => 1
[3] => 1
[4] => 1
[1] =>
[0] => 2
[1] => 2
[2] => 2
[3] => 2
[4] => 2
Run Code Online (Sandbox Code Playgroud)
以下代码非常有用:
for ($x = 0; $x < count($codedDataArray) - $colWidthSum + 1; $x += $colWidthSum + 1) {
for ($c = 0; $c <= $colWidthSum; $c++) {
$rows[$j][] = $codedDataArray[$z];
$z++;
}
$j++;
}
Run Code Online (Sandbox Code Playgroud)
但是当我给它提供非常大的字符串时,它会耗尽内存,例如10959字节.
是否有一个内置的PHP函数,我错过了会做同样的事情,或者我只是要处理内存问题?
编辑1:我跑出来的两个内存preg_split和str_split一样,所以我可能做的事情真的错了.一旦我弄清楚我最初的问题是什么,我仍然会回答.
编辑2:字符串长度实际上是745,982字节,我正在查看压缩长度. …
我可能已经在stackoverflow上找到了一个答案,我提前抱歉,我找不到它.
我在我的localhost上运行了一个小型TCP服务器,出于安全原因,它不支持CORS.
我的问题是,如果CORS用于跨域保护,为什么在http://localhost/请求连接页面时请求它http://localhost:xxxx
我知道我可以在浏览器中关闭安全性,但我试图理解为什么localhost到localhost连接被视为跨源连接.
XMLHttpRequest cannot load http://localhost:8000/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 500.
Run Code Online (Sandbox Code Playgroud) 来自https://github.com/karelzak/util-linux/blob/master/disk-utils/mkfs.c#L94-L113
/* Check commandline options. */
opterr = 0;
while ((more == 0)
&& ((i = getopt_long(argc, argv, "Vt:h", longopts, NULL))
!= -1))
switch (i) {
case 'V':
verbose++;
break;
case 't':
fstype = optarg;
break;
case 'h':
usage();
case VERSION_OPTION:
print_version();
default:
optind--;
more = 1;
break; /* start of specific arguments */
Run Code Online (Sandbox Code Playgroud)
mkfs的文档说这-V是版本和详细的短标志.我无法理解这是如何可能的,我正在寻找清晰度.
VERSION_OPTION被定义为enum { VERSION_OPTION = CHAR_MAX + 1 };所以我不确定是什么字符.
我想为魔兽世界开发服务器.我在哪里可以找到这方面的参考? 我已经获得了Mangos源代码.
我有一个多维数组,格式如下:
[0] = (
'id' => '1',
'type' => 'fish',
'owner' => 'bob',
)
[1] = (
'id' => '2',
'type' => 'cat',
'owner' => 'mary',
)
[2] = (
'id' => '3',
'type' => 'dog',
'owner' => 'larry',
)
[3] = (
'id' => '2',
'type' => 'cat',
'owner' => 'fred',
)
Run Code Online (Sandbox Code Playgroud)
我想搜索一个值,它们返回一个包含匹配数组中所有键的数组,在搜索type = cat时看起来像这样:
[0] = (
'id' => '2',
'type' => 'cat',
'owner' => 'mary',
)
[1] = (
'id' => '2',
'type' => 'cat',
'owner' => …Run Code Online (Sandbox Code Playgroud) php ×3
arrays ×2
javascript ×2
binary ×1
c ×1
class ×1
cors ×1
flags ×1
getopt ×1
localhost ×1
optimization ×1
percentage ×1
phpunit ×1
properties ×1
random ×1
string ×1