12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
-
-
- class Swift_Tests_IdenticalBinaryExpectation extends SimpleExpectation
- {
-
-
-
- private $_left;
-
-
-
- public function __construct($left, $message = '%s')
- {
- parent::__construct($message);
- $this->_left = $left;
- }
-
-
-
- public function asHexString($binary)
- {
- $hex = '';
-
- $bytes = unpack('H*', $binary);
-
- foreach ($bytes as &$byte)
- {
- $byte = strtoupper($byte);
- }
-
- return implode('', $bytes);
- }
-
-
-
- public function test($right)
- {
- $aHex = $this->asHexString($this->_left);
- $bHex = $this->asHexString($right);
-
- return $aHex === $bHex;
- }
-
-
-
- public function testMessage($right)
- {
- if ($this->test($right))
- {
- return 'Identical binary expectation [' . $this->asHexString($right) . ']';
- }
- else
- {
- $this->_dumper=new SimpleDumper();
- return 'Identical binary expectation fails ' .
- $this->_dumper->describeDifference(
- $this->asHexString($this->_left),
- $this->asHexString($right)
- );
- }
- }
-
- }
|