2

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>

But it looks like phpunit can't insert it, using

0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C instead of 0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C trying to insert test data to table.

5
  • what is datatype of password field? is it BINARY!!
    – xkeshav
    Commented Oct 10, 2011 at 6:32
  • binary just work as char as mentioned in mysql documentation. so your data will be truncated
    – xkeshav
    Commented Oct 10, 2011 at 6:53
  • it's password binary(64)
    – Oleg
    Commented Oct 10, 2011 at 6:53
  • Could you explain what you mean, please?
    – Oleg
    Commented Oct 10, 2011 at 6:54
  • Binary are stored as bytes. In phpmyadmin I can insert binay for example as: INSERT INTO test (password) VALUES (0x771C87E79B130E3FB966E424D7F1358D8DABBA0A26F288C0C1B5D8E3D95F2942100CA54B6824A7AC0964180A9426A1C37C371BA3FDBB000621FE175608C4B16C)
    – Oleg
    Commented Oct 10, 2011 at 6:58

2 Answers 2

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.

10
  • Could you please, explain what you suggest please? I'll take a look at the link.
    – Oleg
    Commented Oct 10, 2011 at 8:28
  • I'm sory, I don't understand how you suggest to solve the problem.
    – Oleg
    Commented Oct 10, 2011 at 13:26
  • If you're using DbUnit with PHPUnit, see this answer for an example. I am not familiar with DbUnit, but hopefully it will give you enough to go on. Commented Oct 10, 2011 at 20:13
  • Looking at this blog post, it seems that the database extension in PHPUnit is a port of Java's DbUnit. Hopefully that means the base64 support is included. Commented Oct 10, 2011 at 20:16
  • 1
    I suspect that PHPUnit's database extension doesn't have this feature. The other option is as I wrote above: use XML entity references to embed binary values directly. It won't be pretty, but it might work because it depends solely on the XML parser handling standard XML entities. Commented Oct 11, 2011 at 11:22
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.

1
  • You can always create your own version of the ReplacementDataSet decorator. I created a "HexadecimalAwareDataSet" decorator that does something like this but a bit more scalable.
    – Xunnamius
    Commented Jun 13, 2017 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.