I try to write tests using php for database. I have a table that stores hash of password as binary. How can I set test data in xml dataset, for example here is hex of my data and I get an error data too long to column. Thank you.
我尝试使用php编写测试数据库。我有一个表将密码的哈希值存储为二进制。如何在xml数据集中设置测试数据,例如,这里是我的数据的十六进制,我得到的错误数据太长了。谢谢。
<dataset>
<table name="subscription_ips">
<column>password</column>
<row>
<value>0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C</value>
</row>
</table>
</dataset>
But it looks like phpunit can't insert it, using
但它看起来像phpunit无法插入它,使用
0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C
instead of 0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C
trying to insert test data to table.
0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C而不是0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C试图测试数据插入到表。
2 个解决方案
#1
2
That's a literal binary string that MySQL understands. I suspect that PHPUnit doesn't understand it. You could try using the equivalent for XML using entity references or maybe you'll luck out and the parser PHPUnit uses supports base64Binary
.
这是MySQL理解的文字二进制字符串。我怀疑PHPUnit不理解它。你可以尝试使用实体引用来使用XML的等价物,或者你可能运气好,解析器PHPUnit使用支持base64Binary。
#2
1
I see now a decision like this, using replacement decorator:
我现在看到这样的决定,使用替换装饰器:
public function getDataSet($pFileName=null)
{
if ($pFileName===null) {
$vFileName = $this->_fixturesDir.'init_flat.xml';
} else {
$vFileName = $pFileName;
}
$ds = $this->createFlatXmlDataSet($vFileName);
$rds = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($ds);
$rds->addSubStrReplacement('##HASH_wince4_1318143535##', hash('sha512', 'wince4' . '1318143535', true));
$rds->addFullReplacement('##NULL##', null);
return $rds;
}
In flatXML: It doesn't seem reliable, convinient and scalable. We try to replace some text with neccessary hash. I hope anybody could propose more appropriate decision of the problem.
在flatXML中:它似乎不可靠,方便和可扩展。我们尝试用必要的哈希替换一些文本。我希望任何人都可以提出更合适的问题决定。
#1
2
That's a literal binary string that MySQL understands. I suspect that PHPUnit doesn't understand it. You could try using the equivalent for XML using entity references or maybe you'll luck out and the parser PHPUnit uses supports base64Binary
.
这是MySQL理解的文字二进制字符串。我怀疑PHPUnit不理解它。你可以尝试使用实体引用来使用XML的等价物,或者你可能运气好,解析器PHPUnit使用支持base64Binary。
#2
1
I see now a decision like this, using replacement decorator:
我现在看到这样的决定,使用替换装饰器:
public function getDataSet($pFileName=null)
{
if ($pFileName===null) {
$vFileName = $this->_fixturesDir.'init_flat.xml';
} else {
$vFileName = $pFileName;
}
$ds = $this->createFlatXmlDataSet($vFileName);
$rds = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($ds);
$rds->addSubStrReplacement('##HASH_wince4_1318143535##', hash('sha512', 'wince4' . '1318143535', true));
$rds->addFullReplacement('##NULL##', null);
return $rds;
}
In flatXML: It doesn't seem reliable, convinient and scalable. We try to replace some text with neccessary hash. I hope anybody could propose more appropriate decision of the problem.
在flatXML中:它似乎不可靠,方便和可扩展。我们尝试用必要的哈希替换一些文本。我希望任何人都可以提出更合适的问题决定。