[英]testing database with binary type in mysql using phpunit
I try to write tests using php for database. 我尝试使用php编写数据库测试。 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.
如何在xml数据集中设置测试数据,例如,这是我的数据的十六进制,并且我得到的错误数据太长而无法列。 Thank you.
谢谢。
<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
试图测试数据插入到表。
That's a literal binary string that MySQL understands. 这是MySQL可以理解的文字二进制字符串。 I suspect that PHPUnit doesn't understand it.
我怀疑PHPUnit无法理解。 You could try using the equivalent for XML using entity references or maybe you'll luck out and the parser PHPUnit uses supports
base64Binary
. 您可以尝试使用实体引用为XML使用等效项,否则可能会碰运气,而PHPUnit所使用的解析器则支持
base64Binary
。
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. 在flatXML中:它似乎不可靠,不方便且不可扩展。 We try to replace some text with neccessary hash.
我们尝试用必要的哈希替换一些文本。 I hope anybody could propose more appropriate decision of the problem.
我希望任何人都可以对这个问题提出更适当的决定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.