使用phpunit在mysql中测试二进制类型的数据库 [英] testing database with binary type in mysql using phpunit
问题描述
我尝试使用php编写数据库测试.我有一个表,将密码的哈希存储为二进制. 如何在xml数据集中设置测试数据,例如,这是我的数据的十六进制,而我得到的错误数据太长而无法列. 谢谢.
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.
<dataset>
<table name="subscription_ips">
<column>password</column>
<row>
<value>0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C</value>
</row>
</table>
</dataset>
但是看起来phpunit无法使用
But it looks like phpunit can't insert it, using
0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C
而不是0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C
试图将测试数据插入表中.
0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C
instead of 0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C
trying to insert test data to table.
推荐答案
我现在看到使用替换装饰器的这样的决定:
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;
}
在flatXML中: 它似乎不可靠,不方便且不可扩展.我们尝试用必要的哈希替换某些文本.我希望任何人都可以对这个问题提出更适当的决定.
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.
这篇关于使用phpunit在mysql中测试二进制类型的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!