diff --git a/composer.json b/composer.json index bde1996..d7211eb 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ ], "require": { "php": ">=5.3", - "eloquent/confetti": "~0.1.0", + "eloquent/confetti": "~0.2.0", "evenement/evenement": ">=1,<3", "icecave/isolator": "~2", "react/stream": ">=0.3,<0.5" diff --git a/src/Base16/Base16DecodeTransform.php b/src/Base16/Base16DecodeTransform.php index 1cfd15e..b5cd594 100644 --- a/src/Base16/Base16DecodeTransform.php +++ b/src/Base16/Base16DecodeTransform.php @@ -14,7 +14,6 @@ use Eloquent\Confetti\AbstractTransform; use Eloquent\Confetti\TransformInterface; use Eloquent\Endec\Exception\InvalidEncodedDataException; -use Exception; /** * Decodes data using base16 (hexadecimal) encoding. @@ -56,22 +55,25 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { $consume = $this->blocksSize(strlen($data), 2, $isEnd); if (!$consume) { - return array('', 0); + return array('', 0, null); } $consumedData = substr($data, 0, $consume); if (!preg_match('/^([[:xdigit:]]{2})+$/', $consumedData)) { - throw new InvalidEncodedDataException('base16', $consumedData); + return array( + '', + 0, + new InvalidEncodedDataException('base16', $consumedData) + ); } - return array(pack('H*', $consumedData), $consume); + return array(pack('H*', $consumedData), $consume, null); } private static $instance; diff --git a/src/Base16/Base16EncodeTransform.php b/src/Base16/Base16EncodeTransform.php index 6d8dec7..03586fc 100644 --- a/src/Base16/Base16EncodeTransform.php +++ b/src/Base16/Base16EncodeTransform.php @@ -12,7 +12,6 @@ namespace Eloquent\Endec\Base16; use Eloquent\Confetti\TransformInterface; -use Exception; /** * Encodes data using base16 (hexadecimal) encoding. @@ -54,12 +53,11 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { - return array(strtoupper(bin2hex($data)), strlen($data)); + return array(strtoupper(bin2hex($data)), strlen($data), null); } private static $instance; diff --git a/src/Base32/AbstractBase32DecodeTransform.php b/src/Base32/AbstractBase32DecodeTransform.php index 76806a2..c2ca5f6 100644 --- a/src/Base32/AbstractBase32DecodeTransform.php +++ b/src/Base32/AbstractBase32DecodeTransform.php @@ -14,7 +14,6 @@ use Eloquent\Confetti\TransformInterface; use Eloquent\Endec\Exception\EncodingExceptionInterface; use Eloquent\Endec\Exception\InvalidEncodedDataException; -use Exception; /** * An abstract base class for implementing base32 decode transforms. @@ -42,71 +41,78 @@ abstract class AbstractBase32DecodeTransform implements TransformInterface * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { $paddedLength = strlen($data); $data = rtrim($data, '='); $length = strlen($data); - $consumedBytes = intval($length / 8) * 8; + $consumed = intval($length / 8) * 8; $index = 0; $output = ''; - while ($index < $consumedBytes) { - $output .= $this->map8( - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), - $this->mapByte($data, $index++) - ); - } - - if (($isEnd || $paddedLength > $length) && $consumedBytes !== $length) { - $remaining = $length - $consumedBytes; - $consumedBytes = $length; - - if (2 === $remaining) { - $output .= $this->map2( - $this->mapByte($data, $index++), - $this->mapByte($data, $index) - ); - } elseif (4 === $remaining) { - $output .= $this->map4( - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), - $this->mapByte($data, $index) - ); - } elseif (5 === $remaining) { - $output .= $this->map5( - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), - $this->mapByte($data, $index++), + try { + while ($index < $consumed) { + $output .= $this->map8( $this->mapByte($data, $index++), - $this->mapByte($data, $index) - ); - } elseif (7 === $remaining) { - $output .= $this->map7( $this->mapByte($data, $index++), $this->mapByte($data, $index++), $this->mapByte($data, $index++), $this->mapByte($data, $index++), $this->mapByte($data, $index++), $this->mapByte($data, $index++), - $this->mapByte($data, $index) + $this->mapByte($data, $index++) ); - } else { - throw new InvalidEncodedDataException($this->key(), $data); } + + if (($isEnd || $paddedLength > $length) && $consumed !== $length) { + $remaining = $length - $consumed; + $consumed = $length; + + if (2 === $remaining) { + $output .= $this->map2( + $this->mapByte($data, $index++), + $this->mapByte($data, $index) + ); + } elseif (4 === $remaining) { + $output .= $this->map4( + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index) + ); + } elseif (5 === $remaining) { + $output .= $this->map5( + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index) + ); + } elseif (7 === $remaining) { + $output .= $this->map7( + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index++), + $this->mapByte($data, $index) + ); + } else { + return array( + '', + 0, + new InvalidEncodedDataException($this->key(), $data) + ); + } + } + } catch (EncodingExceptionInterface $error) { + return array('', 0, $error); } - return array($output, $consumedBytes + $paddedLength - $length); + return array($output, $consumed + $paddedLength - $length, null); } private function map2($a, $b) diff --git a/src/Base32/AbstractBase32EncodeTransform.php b/src/Base32/AbstractBase32EncodeTransform.php index 0dab068..8fb6a8d 100644 --- a/src/Base32/AbstractBase32EncodeTransform.php +++ b/src/Base32/AbstractBase32EncodeTransform.php @@ -12,7 +12,6 @@ namespace Eloquent\Endec\Base32; use Eloquent\Confetti\TransformInterface; -use Exception; /** * An abstract base class for implementing base32 encode transforms. @@ -50,17 +49,16 @@ protected function __construct(array $alphabet) * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { $length = strlen($data); - $consumedBytes = intval($length / 5) * 5; + $consumed = intval($length / 5) * 5; $index = 0; $output = ''; - while ($index < $consumedBytes) { + while ($index < $consumed) { $output .= $this->map5( ord($data[$index++]), ord($data[$index++]), @@ -70,9 +68,9 @@ public function transform($data, &$context, $isEnd = false) ); } - if ($isEnd && $consumedBytes !== $length) { - $remaining = $length - $consumedBytes; - $consumedBytes = $length; + if ($isEnd && $consumed !== $length) { + $remaining = $length - $consumed; + $consumed = $length; if (1 === $remaining) { $output .= $this->map1( @@ -99,7 +97,7 @@ public function transform($data, &$context, $isEnd = false) } } - return array($output, $consumedBytes); + return array($output, $consumed, null); } private function map1($a) diff --git a/src/Base64/Base64DecodeTransform.php b/src/Base64/Base64DecodeTransform.php index a514dfa..293777f 100644 --- a/src/Base64/Base64DecodeTransform.php +++ b/src/Base64/Base64DecodeTransform.php @@ -14,7 +14,6 @@ use Eloquent\Confetti\AbstractTransform; use Eloquent\Confetti\TransformInterface; use Eloquent\Endec\Exception\InvalidEncodedDataException; -use Exception; /** * Decodes data using base64 encoding. @@ -56,27 +55,34 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { $consume = $this->blocksSize(strlen($data), 4, $isEnd); if (!$consume) { - return array('', 0); + return array('', 0, null); } $consumedData = substr($data, 0, $consume); if (1 === strlen(rtrim($consumedData, '=')) % 4) { - throw new InvalidEncodedDataException('base64', $consumedData); + return array( + '', + 0, + new InvalidEncodedDataException('base64', $consumedData), + ); } $outputBuffer = base64_decode($consumedData, true); if (false === $outputBuffer) { - throw new InvalidEncodedDataException('base64', $consumedData); + return array( + '', + 0, + new InvalidEncodedDataException('base64', $consumedData), + ); } - return array($outputBuffer, $consume); + return array($outputBuffer, $consume, null); } private static $instance; diff --git a/src/Base64/Base64EncodeTransform.php b/src/Base64/Base64EncodeTransform.php index 0380e84..794d0cf 100644 --- a/src/Base64/Base64EncodeTransform.php +++ b/src/Base64/Base64EncodeTransform.php @@ -13,7 +13,6 @@ use Eloquent\Confetti\AbstractTransform; use Eloquent\Confetti\TransformInterface; -use Exception; /** * Encodes data using base64 encoding. @@ -55,17 +54,16 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { $consume = $this->blocksSize(strlen($data), 3, $isEnd); if (!$consume) { - return array('', 0); + return array('', 0, null); } - return array(base64_encode(substr($data, 0, $consume)), $consume); + return array(base64_encode(substr($data, 0, $consume)), $consume, null); } private static $instance; diff --git a/src/Base64/Base64MimeDecodeTransform.php b/src/Base64/Base64MimeDecodeTransform.php index 317709d..a67ce7a 100644 --- a/src/Base64/Base64MimeDecodeTransform.php +++ b/src/Base64/Base64MimeDecodeTransform.php @@ -12,9 +12,7 @@ namespace Eloquent\Endec\Base64; use Eloquent\Confetti\TransformInterface; -use Eloquent\Endec\Exception\EncodingExceptionInterface; use Eloquent\Endec\Exception\InvalidEncodedDataException; -use Exception; /** * Decodes data using base64 encoding suitable for MIME message bodies. @@ -56,23 +54,29 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { if ($isEnd) { - try { - list($output) = parent::transform( - preg_replace('{[^[:alnum:]+/=]+}', '', $data), - $context, - true + list($output, $consumed, $error) = parent::transform( + preg_replace('{[^[:alnum:]+/=]+}', '', $data), + $context, + true + ); + + if (null !== $error) { + return array( + '', + 0, + new InvalidEncodedDataException( + 'base64mime', + $error->data() + ), ); - } catch (EncodingExceptionInterface $e) { - throw new InvalidEncodedDataException('base64mime', $e->data()); } - return array($output, strlen($data)); + return array($output, strlen($data), $error); } $chunks = preg_split( @@ -86,33 +90,38 @@ public function transform($data, &$context, $isEnd = false) $buffer = ''; $output = ''; $lastFullyConsumed = -1; - $consumedBytes = 0; + $consumed = 0; for ($i = 0; $i < $numChunks; $i ++) { $buffer .= $chunks[$i][0]; - list($thisOutput, $consumedBytes) = parent::transform( + list($thisOutput, $consumed, $error) = parent::transform( $buffer, $context ); + + if (null !== $error) { + return array('', 0, $error); + } + $output .= $thisOutput; - if ($consumedBytes === strlen($buffer)) { + if ($consumed === strlen($buffer)) { $buffer = ''; $lastFullyConsumed = $i; } else { - $buffer = substr($buffer, $consumedBytes); + $buffer = substr($buffer, $consumed); } } if ($lastFullyConsumed > -1) { if ($lastFullyConsumed < $numChunks - 1) { - $consumedBytes = $chunks[$lastFullyConsumed + 1][1]; + $consumed = $chunks[$lastFullyConsumed + 1][1]; } else { - $consumedBytes = $chunks[$lastFullyConsumed][1] + + $consumed = $chunks[$lastFullyConsumed][1] + strlen($chunks[$lastFullyConsumed][0]); } } - return array($output, $consumedBytes); + return array($output, $consumed, null); } private static $instance; diff --git a/src/Base64/Base64MimeEncodeTransform.php b/src/Base64/Base64MimeEncodeTransform.php index aed34b9..ce8a9e8 100644 --- a/src/Base64/Base64MimeEncodeTransform.php +++ b/src/Base64/Base64MimeEncodeTransform.php @@ -13,7 +13,6 @@ use Eloquent\Confetti\AbstractTransform; use Eloquent\Confetti\TransformInterface; -use Exception; /** * Encodes data using base64 encoding suitable for MIME message bodies. @@ -55,8 +54,7 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { @@ -80,7 +78,7 @@ public function transform($data, &$context, $isEnd = false) } } - return array($output, strlen($data)); + return array($output, strlen($data), null); } private static $instance; diff --git a/src/Base64/Base64UrlDecodeTransform.php b/src/Base64/Base64UrlDecodeTransform.php index b82fb8e..8a32880 100644 --- a/src/Base64/Base64UrlDecodeTransform.php +++ b/src/Base64/Base64UrlDecodeTransform.php @@ -14,7 +14,6 @@ use Eloquent\Confetti\AbstractTransform; use Eloquent\Confetti\TransformInterface; use Eloquent\Endec\Exception\InvalidEncodedDataException; -use Exception; /** * Decodes data using base64url encoding. @@ -56,19 +55,22 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { $consume = $this->blocksSize(strlen($data), 4, $isEnd); if (!$consume) { - return array('', 0); + return array('', 0, null); } $consumedData = substr($data, 0, $consume); if (1 === $consume % 4) { - throw new InvalidEncodedDataException('base64url', $consumedData); + return array( + '', + 0, + new InvalidEncodedDataException('base64url', $consumedData), + ); } $outputBuffer = base64_decode( @@ -81,10 +83,14 @@ public function transform($data, &$context, $isEnd = false) true ); if (false === $outputBuffer) { - throw new InvalidEncodedDataException('base64url', $consumedData); + return array( + '', + 0, + new InvalidEncodedDataException('base64url', $consumedData), + ); } - return array($outputBuffer, $consume); + return array($outputBuffer, $consume, null); } private static $instance; diff --git a/src/Base64/Base64UrlEncodeTransform.php b/src/Base64/Base64UrlEncodeTransform.php index a674382..1e6ebb8 100644 --- a/src/Base64/Base64UrlEncodeTransform.php +++ b/src/Base64/Base64UrlEncodeTransform.php @@ -13,7 +13,6 @@ use Eloquent\Confetti\AbstractTransform; use Eloquent\Confetti\TransformInterface; -use Exception; /** * Encodes data using base64url encoding. @@ -55,14 +54,13 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { $consume = $this->blocksSize(strlen($data), 3, $isEnd); if (!$consume) { - return array('', 0); + return array('', 0, null); } return array( @@ -74,7 +72,8 @@ public function transform($data, &$context, $isEnd = false) ), '=' ), - $consume + $consume, + null ); } diff --git a/src/Codec.php b/src/Codec.php index 4132c5b..8a6770d 100644 --- a/src/Codec.php +++ b/src/Codec.php @@ -64,9 +64,13 @@ public function decodeTransform() */ public function encode($data) { - list($data) = $this->encodeTransform() + list($data, $consumed, $error) = $this->encodeTransform() ->transform($data, $context, true); + if (null !== $error) { + throw $error; + } + return $data; } @@ -80,9 +84,13 @@ public function encode($data) */ public function decode($data) { - list($data) = $this->decodeTransform() + list($data, $consumed, $error) = $this->decodeTransform() ->transform($data, $context, true); + if (null !== $error) { + throw $error; + } + return $data; } diff --git a/src/Decoder.php b/src/Decoder.php index e850a33..398ee86 100644 --- a/src/Decoder.php +++ b/src/Decoder.php @@ -50,9 +50,13 @@ public function decodeTransform() */ public function decode($data) { - list($data) = $this->decodeTransform() + list($data, $consumed, $error) = $this->decodeTransform() ->transform($data, $context, true); + if (null !== $error) { + throw $error; + } + return $data; } diff --git a/src/Encoder.php b/src/Encoder.php index 1b282dc..8742c44 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -50,9 +50,13 @@ public function encodeTransform() */ public function encode($data) { - list($data) = $this->encodeTransform() + list($data, $consumed, $error) = $this->encodeTransform() ->transform($data, $context, true); + if (null !== $error) { + throw $error; + } + return $data; } diff --git a/src/Uri/UriDecodeTransform.php b/src/Uri/UriDecodeTransform.php index 7f9fe19..59d9ac3 100644 --- a/src/Uri/UriDecodeTransform.php +++ b/src/Uri/UriDecodeTransform.php @@ -13,7 +13,6 @@ use Eloquent\Confetti\AbstractTransform; use Eloquent\Confetti\TransformInterface; -use Exception; /** * Decodes data using URI percent encoding. @@ -55,35 +54,35 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { if ($isEnd) { - $consumedBytes = strlen($data); + $consumed = strlen($data); } else { $lastPercentIndex = strrpos($data, '%'); if (false === $lastPercentIndex) { - $consumedBytes = strlen($data); + $consumed = strlen($data); } else { $length = strlen($data); if ($lastPercentIndex < $length - 2) { - $consumedBytes = $length; + $consumed = $length; } else { - $consumedBytes = $lastPercentIndex; + $consumed = $lastPercentIndex; } } } - if (!$consumedBytes) { - return array('', 0); + if (!$consumed) { + return array('', 0, null); } return array( - rawurldecode(substr($data, 0, $consumedBytes)), - $consumedBytes + rawurldecode(substr($data, 0, $consumed)), + $consumed, + null ); } diff --git a/src/Uri/UriEncodeTransform.php b/src/Uri/UriEncodeTransform.php index da34a6b..c278fed 100644 --- a/src/Uri/UriEncodeTransform.php +++ b/src/Uri/UriEncodeTransform.php @@ -12,7 +12,6 @@ namespace Eloquent\Endec\Uri; use Eloquent\Confetti\TransformInterface; -use Exception; /** * Encodes data using URI percent encoding. @@ -54,12 +53,11 @@ public static function instance() * @param mixed &$context An arbitrary context value. * @param boolean $isEnd True if all supplied data must be transformed. * - * @return tuple A 2-tuple of the transformed data, and the number of bytes consumed. - * @throws Exception If the data cannot be transformed. + * @return tuple A 3-tuple of the transformed data, the number of bytes consumed, and any resulting error. */ public function transform($data, &$context, $isEnd = false) { - return array(rawurlencode($data), strlen($data)); + return array(rawurlencode($data), strlen($data), null); } private static $instance; diff --git a/test/src/Rot13Transform.php b/test/src/Rot13Transform.php index 1ebb2d4..db42e74 100644 --- a/test/src/Rot13Transform.php +++ b/test/src/Rot13Transform.php @@ -15,6 +15,6 @@ class Rot13Transform implements TransformInterface { public function transform($data, &$context, $isEnd = false) { - return array(str_rot13($data), strlen($data)); + return array(str_rot13($data), strlen($data), null); } } diff --git a/test/suite/Base16/Base16DecodeTransformTest.php b/test/suite/Base16/Base16DecodeTransformTest.php index 26834d7..b0058da 100644 --- a/test/suite/Base16/Base16DecodeTransformTest.php +++ b/test/suite/Base16/Base16DecodeTransformTest.php @@ -25,44 +25,44 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 bytes' => array('6', '', 0, null), - '2 bytes' => array('66', 'f', 2, null), - '3 bytes' => array('666', 'f', 2, null), - '4 bytes' => array('666f', 'fo', 4, null), - '5 bytes' => array('666f6', 'fo', 4, null), - '6 bytes' => array('666f6f', 'foo', 6, null), + 'Empty' => array('', '', 0, null), + '1 bytes' => array('6', '', 0, null), + '2 bytes' => array('66', 'f', 2, null), + '3 bytes' => array('666', 'f', 2, null), + '4 bytes' => array('666f', 'fo', 4, null), + '5 bytes' => array('666f6', 'fo', 4, null), + '6 bytes' => array('666f6f', 'foo', 6, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '2 bytes' => array('66', 'f', 2, null), - '4 bytes' => array('666f', 'fo', 4, null), - '6 bytes' => array('666f6f', 'foo', 6, null), + 'Empty' => array('', '', 0, null), + '2 bytes' => array('66', 'f', 2, null), + '4 bytes' => array('666f', 'fo', 4, null), + '6 bytes' => array('666f6f', 'foo', 6, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } @@ -82,11 +82,15 @@ public function invalidTransformEndData() */ public function testTransformFailure($input) { + list($output, $consumed, $error) = $this->transform->transform($input, $context, true); + + $this->assertSame('', $output); + $this->assertSame(0, $consumed); $this->setExpectedException( 'Eloquent\Endec\Exception\InvalidEncodedDataException', 'The supplied data is not valid for base16 encoding.' ); - $this->transform->transform($input, $context, true); + throw $error; } public function testInstance() diff --git a/test/suite/Base16/Base16EncodeTransformTest.php b/test/suite/Base16/Base16EncodeTransformTest.php index 44ae0c0..0190db4 100644 --- a/test/suite/Base16/Base16EncodeTransformTest.php +++ b/test/suite/Base16/Base16EncodeTransformTest.php @@ -25,33 +25,33 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('f', '66', 1, null), - '2 bytes' => array('fo', '666F', 2, null), - '3 bytes' => array('foo', '666F6F', 3, null), - '4 bytes' => array('foob', '666F6F62', 4, null), - '5 bytes' => array('fooba', '666F6F6261', 5, null), - '6 bytes' => array('foobar', '666F6F626172', 6, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('f', '66', 1, null), + '2 bytes' => array('fo', '666F', 2, null), + '3 bytes' => array('foo', '666F6F', 3, null), + '4 bytes' => array('foob', '666F6F62', 4, null), + '5 bytes' => array('fooba', '666F6F6261', 5, null), + '6 bytes' => array('foobar', '666F6F626172', 6, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } /** * @dataProvider transformData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } diff --git a/test/suite/Base32/Base32DecodeTransformTest.php b/test/suite/Base32/Base32DecodeTransformTest.php index 546e851..21dc5ac 100644 --- a/test/suite/Base32/Base32DecodeTransformTest.php +++ b/test/suite/Base32/Base32DecodeTransformTest.php @@ -29,7 +29,7 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( 'Empty' => array('', '', 0, null), '1 byte' => array('M', '', 0, null), @@ -55,15 +55,15 @@ public function transformData() /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( 'Empty' => array('', '', 0, null), '2 bytes' => array('MY', 'f', 2, null), @@ -84,9 +84,9 @@ public function transformEndData() /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } @@ -106,11 +106,15 @@ public function invalidTransformEndData() */ public function testTransformFailure($input) { + list($output, $consumed, $error) = $this->transform->transform($input, $context, true); + + $this->assertSame('', $output); + $this->assertSame(0, $consumed); $this->setExpectedException( 'Eloquent\Endec\Exception\InvalidEncodedDataException', 'The supplied data is not valid for base32 encoding.' ); - $this->transform->transform($input, $context, true); + throw $error; } public function testInstance() diff --git a/test/suite/Base32/Base32EncodeTransformTest.php b/test/suite/Base32/Base32EncodeTransformTest.php index 5c79f6f..ab3129e 100644 --- a/test/suite/Base32/Base32EncodeTransformTest.php +++ b/test/suite/Base32/Base32EncodeTransformTest.php @@ -29,55 +29,55 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('f', '', 0, null), - '2 bytes' => array('fo', '', 0, null), - '3 bytes' => array('foo', '', 0, null), - '4 bytes' => array('foob', '', 0, null), - '5 bytes' => array('fooba', 'MZXW6YTB', 5, null), - '6 bytes' => array('foobar', 'MZXW6YTB', 5, null), - '7 bytes' => array('foobarb', 'MZXW6YTB', 5, null), - '8 bytes' => array('foobarba', 'MZXW6YTB', 5, null), - '9 bytes' => array('foobarbaz', 'MZXW6YTB', 5, null), - '10 bytes' => array('foobarbazq', 'MZXW6YTBOJRGC6TR', 10, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('f', '', 0, null), + '2 bytes' => array('fo', '', 0, null), + '3 bytes' => array('foo', '', 0, null), + '4 bytes' => array('foob', '', 0, null), + '5 bytes' => array('fooba', 'MZXW6YTB', 5, null), + '6 bytes' => array('foobar', 'MZXW6YTB', 5, null), + '7 bytes' => array('foobarb', 'MZXW6YTB', 5, null), + '8 bytes' => array('foobarba', 'MZXW6YTB', 5, null), + '9 bytes' => array('foobarbaz', 'MZXW6YTB', 5, null), + '10 bytes' => array('foobarbazq', 'MZXW6YTBOJRGC6TR', 10, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('f', 'MY======', 1, null), - '2 bytes' => array('fo', 'MZXQ====', 2, null), - '3 bytes' => array('foo', 'MZXW6===', 3, null), - '4 bytes' => array('foob', 'MZXW6YQ=', 4, null), - '5 bytes' => array('fooba', 'MZXW6YTB', 5, null), - '6 bytes' => array('foobar', 'MZXW6YTBOI======', 6, null), - '7 bytes' => array('foobarb', 'MZXW6YTBOJRA====', 7, null), - '8 bytes' => array('foobarba', 'MZXW6YTBOJRGC===', 8, null), - '9 bytes' => array('foobarbaz', 'MZXW6YTBOJRGC6Q=', 9, null), - '10 bytes' => array('foobarbazq', 'MZXW6YTBOJRGC6TR', 10, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('f', 'MY======', 1, null), + '2 bytes' => array('fo', 'MZXQ====', 2, null), + '3 bytes' => array('foo', 'MZXW6===', 3, null), + '4 bytes' => array('foob', 'MZXW6YQ=', 4, null), + '5 bytes' => array('fooba', 'MZXW6YTB', 5, null), + '6 bytes' => array('foobar', 'MZXW6YTBOI======', 6, null), + '7 bytes' => array('foobarb', 'MZXW6YTBOJRA====', 7, null), + '8 bytes' => array('foobarba', 'MZXW6YTBOJRGC===', 8, null), + '9 bytes' => array('foobarbaz', 'MZXW6YTBOJRGC6Q=', 9, null), + '10 bytes' => array('foobarbazq', 'MZXW6YTBOJRGC6TR', 10, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } diff --git a/test/suite/Base32/Base32HexDecodeTransformTest.php b/test/suite/Base32/Base32HexDecodeTransformTest.php index e4193c5..a6e5212 100644 --- a/test/suite/Base32/Base32HexDecodeTransformTest.php +++ b/test/suite/Base32/Base32HexDecodeTransformTest.php @@ -29,64 +29,64 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('C', '', 0, null), - '2 bytes' => array('CP', '', 0, null), - '3 bytes' => array('CPN', '', 0, null), - '4 bytes' => array('CPNM', '', 0, null), - '5 bytes' => array('CPNMU', '', 0, null), - '6 bytes' => array('CPNMUO', '', 0, null), - '7 bytes' => array('CPNMUOJ', '', 0, null), - '8 bytes' => array('CPNMUOJ1', 'fooba', 8, null), - '9 bytes' => array('CPNMUOJ1E', 'fooba', 8, null), - '10 bytes' => array('CPNMUOJ1E9', 'fooba', 8, null), - '11 bytes' => array('CPNMUOJ1E9H', 'fooba', 8, null), - '12 bytes' => array('CPNMUOJ1E9H6', 'fooba', 8, null), - '13 bytes' => array('CPNMUOJ1E9H62', 'fooba', 8, null), - '14 bytes' => array('CPNMUOJ1E9H62U', 'fooba', 8, null), - '15 bytes' => array('CPNMUOJ1E9H62UJ', 'fooba', 8, null), - '16 bytes' => array('CPNMUOJ1E9H62UJH', 'foobarbazq', 16, null), - '16 bytes with padding' => array('CPNMUOJ1E8======', 'foobar', 16, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('C', '', 0, null), + '2 bytes' => array('CP', '', 0, null), + '3 bytes' => array('CPN', '', 0, null), + '4 bytes' => array('CPNM', '', 0, null), + '5 bytes' => array('CPNMU', '', 0, null), + '6 bytes' => array('CPNMUO', '', 0, null), + '7 bytes' => array('CPNMUOJ', '', 0, null), + '8 bytes' => array('CPNMUOJ1', 'fooba', 8, null), + '9 bytes' => array('CPNMUOJ1E', 'fooba', 8, null), + '10 bytes' => array('CPNMUOJ1E9', 'fooba', 8, null), + '11 bytes' => array('CPNMUOJ1E9H', 'fooba', 8, null), + '12 bytes' => array('CPNMUOJ1E9H6', 'fooba', 8, null), + '13 bytes' => array('CPNMUOJ1E9H62', 'fooba', 8, null), + '14 bytes' => array('CPNMUOJ1E9H62U', 'fooba', 8, null), + '15 bytes' => array('CPNMUOJ1E9H62UJ', 'fooba', 8, null), + '16 bytes' => array('CPNMUOJ1E9H62UJH', 'foobarbazq', 16, null), + '16 bytes with padding' => array('CPNMUOJ1E8======', 'foobar', 16, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '2 bytes' => array('CO', 'f', 2, null), - '4 bytes' => array('CPNG', 'fo', 4, null), - '5 bytes' => array('CPNMU', 'foo', 5, null), - '7 bytes' => array('CPNMUOG', 'foob', 7, null), - '8 bytes' => array('CPNMUOJ1', 'fooba', 8, null), - '8 bytes with padding' => array('CO======', 'f', 8, null), - '10 bytes' => array('CPNMUOJ1E8', 'foobar', 10, null), - '12 bytes' => array('CPNMUOJ1E9H0', 'foobarb', 12, null), - '13 bytes' => array('CPNMUOJ1E9H62', 'foobarba', 13, null), - '15 bytes' => array('CPNMUOJ1E9H62UG', 'foobarbaz', 15, null), - '16 bytes' => array('CPNMUOJ1E9H62UJH', 'foobarbazq', 16, null), - '16 bytes with padding' => array('CPNMUOJ1E8======', 'foobar', 16, null), + 'Empty' => array('', '', 0, null), + '2 bytes' => array('CO', 'f', 2, null), + '4 bytes' => array('CPNG', 'fo', 4, null), + '5 bytes' => array('CPNMU', 'foo', 5, null), + '7 bytes' => array('CPNMUOG', 'foob', 7, null), + '8 bytes' => array('CPNMUOJ1', 'fooba', 8, null), + '8 bytes with padding' => array('CO======', 'f', 8, null), + '10 bytes' => array('CPNMUOJ1E8', 'foobar', 10, null), + '12 bytes' => array('CPNMUOJ1E9H0', 'foobarb', 12, null), + '13 bytes' => array('CPNMUOJ1E9H62', 'foobarba', 13, null), + '15 bytes' => array('CPNMUOJ1E9H62UG', 'foobarbaz', 15, null), + '16 bytes' => array('CPNMUOJ1E9H62UJH', 'foobarbazq', 16, null), + '16 bytes with padding' => array('CPNMUOJ1E8======', 'foobar', 16, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } @@ -106,11 +106,15 @@ public function invalidTransformEndData() */ public function testTransformFailure($input) { + list($output, $consumed, $error) = $this->transform->transform($input, $context, true); + + $this->assertSame('', $output); + $this->assertSame(0, $consumed); $this->setExpectedException( 'Eloquent\Endec\Exception\InvalidEncodedDataException', 'The supplied data is not valid for base32hex encoding.' ); - $this->transform->transform($input, $context, true); + throw $error; } public function testInstance() diff --git a/test/suite/Base32/Base32HexEncodeTransformTest.php b/test/suite/Base32/Base32HexEncodeTransformTest.php index cd31450..5811582 100644 --- a/test/suite/Base32/Base32HexEncodeTransformTest.php +++ b/test/suite/Base32/Base32HexEncodeTransformTest.php @@ -29,55 +29,55 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('f', '', 0, null), - '2 bytes' => array('fo', '', 0, null), - '3 bytes' => array('foo', '', 0, null), - '4 bytes' => array('foob', '', 0, null), - '5 bytes' => array('fooba', 'CPNMUOJ1', 5, null), - '6 bytes' => array('foobar', 'CPNMUOJ1', 5, null), - '7 bytes' => array('foobarb', 'CPNMUOJ1', 5, null), - '8 bytes' => array('foobarba', 'CPNMUOJ1', 5, null), - '9 bytes' => array('foobarbaz', 'CPNMUOJ1', 5, null), - '10 bytes' => array('foobarbazq', 'CPNMUOJ1E9H62UJH', 10, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('f', '', 0, null), + '2 bytes' => array('fo', '', 0, null), + '3 bytes' => array('foo', '', 0, null), + '4 bytes' => array('foob', '', 0, null), + '5 bytes' => array('fooba', 'CPNMUOJ1', 5, null), + '6 bytes' => array('foobar', 'CPNMUOJ1', 5, null), + '7 bytes' => array('foobarb', 'CPNMUOJ1', 5, null), + '8 bytes' => array('foobarba', 'CPNMUOJ1', 5, null), + '9 bytes' => array('foobarbaz', 'CPNMUOJ1', 5, null), + '10 bytes' => array('foobarbazq', 'CPNMUOJ1E9H62UJH', 10, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('f', 'CO======', 1, null), - '2 bytes' => array('fo', 'CPNG====', 2, null), - '3 bytes' => array('foo', 'CPNMU===', 3, null), - '4 bytes' => array('foob', 'CPNMUOG=', 4, null), - '5 bytes' => array('fooba', 'CPNMUOJ1', 5, null), - '6 bytes' => array('foobar', 'CPNMUOJ1E8======', 6, null), - '7 bytes' => array('foobarb', 'CPNMUOJ1E9H0====', 7, null), - '8 bytes' => array('foobarba', 'CPNMUOJ1E9H62===', 8, null), - '9 bytes' => array('foobarbaz', 'CPNMUOJ1E9H62UG=', 9, null), - '10 bytes' => array('foobarbazq', 'CPNMUOJ1E9H62UJH', 10, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('f', 'CO======', 1, null), + '2 bytes' => array('fo', 'CPNG====', 2, null), + '3 bytes' => array('foo', 'CPNMU===', 3, null), + '4 bytes' => array('foob', 'CPNMUOG=', 4, null), + '5 bytes' => array('fooba', 'CPNMUOJ1', 5, null), + '6 bytes' => array('foobar', 'CPNMUOJ1E8======', 6, null), + '7 bytes' => array('foobarb', 'CPNMUOJ1E9H0====', 7, null), + '8 bytes' => array('foobarba', 'CPNMUOJ1E9H62===', 8, null), + '9 bytes' => array('foobarbaz', 'CPNMUOJ1E9H62UG=', 9, null), + '10 bytes' => array('foobarbazq', 'CPNMUOJ1E9H62UJH', 10, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } diff --git a/test/suite/Base64/Base64DecodeTransformTest.php b/test/suite/Base64/Base64DecodeTransformTest.php index 623b706..8918198 100644 --- a/test/suite/Base64/Base64DecodeTransformTest.php +++ b/test/suite/Base64/Base64DecodeTransformTest.php @@ -25,50 +25,50 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('Z', '', 0, null), - '2 bytes' => array('Zm', '', 0, null), - '3 bytes' => array('Zm9', '', 0, null), - '4 bytes' => array('Zm9v', 'foo', 4, null), - '5 bytes' => array('Zm9vY', 'foo', 4, null), - '6 bytes' => array('Zm9vYm', 'foo', 4, null), - '7 bytes' => array('Zm9vYmF', 'foo', 4, null), - '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('Z', '', 0, null), + '2 bytes' => array('Zm', '', 0, null), + '3 bytes' => array('Zm9', '', 0, null), + '4 bytes' => array('Zm9v', 'foo', 4, null), + '5 bytes' => array('Zm9vY', 'foo', 4, null), + '6 bytes' => array('Zm9vYm', 'foo', 4, null), + '7 bytes' => array('Zm9vYmF', 'foo', 4, null), + '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '2 bytes' => array('Zm', 'f', 2, null), - '3 bytes' => array('Zm9', 'fo', 3, null), - '4 bytes' => array('Zm9v', 'foo', 4, null), - '6 bytes' => array('Zm9vYm', 'foob', 6, null), - '7 bytes' => array('Zm9vYmF', 'fooba', 7, null), - '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), - '8 bytes with padding' => array('Zm9vYg==', 'foob', 8, null), + 'Empty' => array('', '', 0, null), + '2 bytes' => array('Zm', 'f', 2, null), + '3 bytes' => array('Zm9', 'fo', 3, null), + '4 bytes' => array('Zm9v', 'foo', 4, null), + '6 bytes' => array('Zm9vYm', 'foob', 6, null), + '7 bytes' => array('Zm9vYmF', 'fooba', 7, null), + '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), + '8 bytes with padding' => array('Zm9vYg==', 'foob', 8, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } @@ -88,11 +88,15 @@ public function invalidTransformEndData() */ public function testTransformFailure($input) { + list($output, $consumed, $error) = $this->transform->transform($input, $context, true); + + $this->assertSame('', $output); + $this->assertSame(0, $consumed); $this->setExpectedException( 'Eloquent\Endec\Exception\InvalidEncodedDataException', 'The supplied data is not valid for base64 encoding.' ); - $this->transform->transform($input, $context, true); + throw $error; } public function testInstance() diff --git a/test/suite/Base64/Base64EncodeTransformTest.php b/test/suite/Base64/Base64EncodeTransformTest.php index 09171a4..79d37d1 100644 --- a/test/suite/Base64/Base64EncodeTransformTest.php +++ b/test/suite/Base64/Base64EncodeTransformTest.php @@ -25,47 +25,47 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('f', '', 0, null), - '2 bytes' => array('fo', '', 0, null), - '3 bytes' => array('foo', 'Zm9v', 3, null), - '4 bytes' => array('foob', 'Zm9v', 3, null), - '5 bytes' => array('fooba', 'Zm9v', 3, null), - '6 bytes' => array('foobar', 'Zm9vYmFy', 6, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('f', '', 0, null), + '2 bytes' => array('fo', '', 0, null), + '3 bytes' => array('foo', 'Zm9v', 3, null), + '4 bytes' => array('foob', 'Zm9v', 3, null), + '5 bytes' => array('fooba', 'Zm9v', 3, null), + '6 bytes' => array('foobar', 'Zm9vYmFy', 6, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('f', 'Zg==', 1, null), - '2 bytes' => array('fo', 'Zm8=', 2, null), - '3 bytes' => array('foo', 'Zm9v', 3, null), - '4 bytes' => array('foob', 'Zm9vYg==', 4, null), - '5 bytes' => array('fooba', 'Zm9vYmE=', 5, null), - '6 bytes' => array('foobar', 'Zm9vYmFy', 6, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('f', 'Zg==', 1, null), + '2 bytes' => array('fo', 'Zm8=', 2, null), + '3 bytes' => array('foo', 'Zm9v', 3, null), + '4 bytes' => array('foob', 'Zm9vYg==', 4, null), + '5 bytes' => array('fooba', 'Zm9vYmE=', 5, null), + '6 bytes' => array('foobar', 'Zm9vYmFy', 6, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } diff --git a/test/suite/Base64/Base64MimeDecodeTransformTest.php b/test/suite/Base64/Base64MimeDecodeTransformTest.php index da3b1df..697fdb7 100644 --- a/test/suite/Base64/Base64MimeDecodeTransformTest.php +++ b/test/suite/Base64/Base64MimeDecodeTransformTest.php @@ -25,86 +25,86 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - - '1 byte' => array('Z', '', 0, null), - '2 bytes' => array('Zm', '', 0, null), - '3 bytes' => array('Zm9', '', 0, null), - '4 bytes' => array('Zm9v', 'foo', 4, null), - '5 bytes' => array('Zm9vY', 'foo', 4, null), - '6 bytes' => array('Zm9vYm', 'foo', 4, null), - '7 bytes' => array('Zm9vYmF', 'foo', 4, null), - '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), - - '1 bytes with skips' => array("!", '', 1, null), - '2 bytes with skips' => array("!Z", '', 1, null), - '3 bytes with skips' => array("!Z!", '', 1, null), - '4 bytes with skips' => array("!Z!m", '', 1, null), - '5 bytes with skips' => array("!Z!m!", '', 1, null), - '6 bytes with skips' => array("!Z!m!9", '', 1, null), - '7 bytes with skips' => array("!Z!m!9!", '', 1, null), - '8 bytes with skips' => array("!Z!m!9!v", 'foo', 8, null), - '9 bytes with skips' => array("!Z!m!9!v\r", 'foo', 9, null), - '10 bytes with skips' => array("!Z!m!9!v\r\n", 'foo', 10, null), - '11 bytes with skips' => array("!Z!m!9!v\r\nY", 'foo', 10, null), - '12 bytes with skips' => array("!Z!m!9!v\r\nY!", 'foo', 10, null), - '13 bytes with skips' => array("!Z!m!9!v\r\nY!m", 'foo', 10, null), - '14 bytes with skips' => array("!Z!m!9!v\r\nY!m!", 'foo', 10, null), - '15 bytes with skips' => array("!Z!m!9!v\r\nY!m!F", 'foo', 10, null), - '16 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!", 'foo', 10, null), - '17 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!y", 'foobar', 17, null), - '18 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!y!", 'foobar', 18, null), + 'Empty' => array('', '', 0, null), + + '1 byte' => array('Z', '', 0, null), + '2 bytes' => array('Zm', '', 0, null), + '3 bytes' => array('Zm9', '', 0, null), + '4 bytes' => array('Zm9v', 'foo', 4, null), + '5 bytes' => array('Zm9vY', 'foo', 4, null), + '6 bytes' => array('Zm9vYm', 'foo', 4, null), + '7 bytes' => array('Zm9vYmF', 'foo', 4, null), + '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), + + '1 bytes with skips' => array("!", '', 1, null), + '2 bytes with skips' => array("!Z", '', 1, null), + '3 bytes with skips' => array("!Z!", '', 1, null), + '4 bytes with skips' => array("!Z!m", '', 1, null), + '5 bytes with skips' => array("!Z!m!", '', 1, null), + '6 bytes with skips' => array("!Z!m!9", '', 1, null), + '7 bytes with skips' => array("!Z!m!9!", '', 1, null), + '8 bytes with skips' => array("!Z!m!9!v", 'foo', 8, null), + '9 bytes with skips' => array("!Z!m!9!v\r", 'foo', 9, null), + '10 bytes with skips' => array("!Z!m!9!v\r\n", 'foo', 10, null), + '11 bytes with skips' => array("!Z!m!9!v\r\nY", 'foo', 10, null), + '12 bytes with skips' => array("!Z!m!9!v\r\nY!", 'foo', 10, null), + '13 bytes with skips' => array("!Z!m!9!v\r\nY!m", 'foo', 10, null), + '14 bytes with skips' => array("!Z!m!9!v\r\nY!m!", 'foo', 10, null), + '15 bytes with skips' => array("!Z!m!9!v\r\nY!m!F", 'foo', 10, null), + '16 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!", 'foo', 10, null), + '17 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!y", 'foobar', 17, null), + '18 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!y!", 'foobar', 18, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - - '2 bytes' => array('Zm', 'f', 2, null), - '3 bytes' => array('Zm9', 'fo', 3, null), - '4 bytes' => array('Zm9v', 'foo', 4, null), - '6 bytes' => array('Zm9vYm', 'foob', 6, null), - '7 bytes' => array('Zm9vYmF', 'fooba', 7, null), - '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), - '8 bytes with padding' => array('Zm9vYg==', 'foob', 8, null), - - '1 bytes with skips' => array("!", '', 1, null), - '4 bytes with skips' => array("!Z!m", 'f', 4, null), - '5 bytes with skips' => array("!Z!m!", 'f', 5, null), - '6 bytes with skips' => array("!Z!m!9", 'fo', 6, null), - '7 bytes with skips' => array("!Z!m!9!", 'fo', 7, null), - '8 bytes with skips' => array("!Z!m!9!v", 'foo', 8, null), - '9 bytes with skips' => array("!Z!m!9!v\r", 'foo', 9, null), - '10 bytes with skips' => array("!Z!m!9!v\r\n", 'foo', 10, null), - '13 bytes with skips' => array("!Z!m!9!v\r\nY!m", 'foob', 13, null), - '14 bytes with skips' => array("!Z!m!9!v\r\nY!m!", 'foob', 14, null), - '15 bytes with skips' => array("!Z!m!9!v\r\nY!m!F", 'fooba', 15, null), - '16 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!", 'fooba', 16, null), - '17 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!y", 'foobar', 17, null), - '18 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!y!", 'foobar', 18, null), + 'Empty' => array('', '', 0, null), + + '2 bytes' => array('Zm', 'f', 2, null), + '3 bytes' => array('Zm9', 'fo', 3, null), + '4 bytes' => array('Zm9v', 'foo', 4, null), + '6 bytes' => array('Zm9vYm', 'foob', 6, null), + '7 bytes' => array('Zm9vYmF', 'fooba', 7, null), + '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), + '8 bytes with padding' => array('Zm9vYg==', 'foob', 8, null), + + '1 bytes with skips' => array("!", '', 1, null), + '4 bytes with skips' => array("!Z!m", 'f', 4, null), + '5 bytes with skips' => array("!Z!m!", 'f', 5, null), + '6 bytes with skips' => array("!Z!m!9", 'fo', 6, null), + '7 bytes with skips' => array("!Z!m!9!", 'fo', 7, null), + '8 bytes with skips' => array("!Z!m!9!v", 'foo', 8, null), + '9 bytes with skips' => array("!Z!m!9!v\r", 'foo', 9, null), + '10 bytes with skips' => array("!Z!m!9!v\r\n", 'foo', 10, null), + '13 bytes with skips' => array("!Z!m!9!v\r\nY!m", 'foob', 13, null), + '14 bytes with skips' => array("!Z!m!9!v\r\nY!m!", 'foob', 14, null), + '15 bytes with skips' => array("!Z!m!9!v\r\nY!m!F", 'fooba', 15, null), + '16 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!", 'fooba', 16, null), + '17 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!y", 'foobar', 17, null), + '18 bytes with skips' => array("!Z!m!9!v\r\nY!m!F!y!", 'foobar', 18, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } @@ -122,11 +122,15 @@ public function invalidTransformEndData() */ public function testTransformFailure($input) { + list($output, $consumed, $error) = $this->transform->transform($input, $context, true); + + $this->assertSame('', $output); + $this->assertSame(0, $consumed); $this->setExpectedException( 'Eloquent\Endec\Exception\InvalidEncodedDataException', 'The supplied data is not valid for base64mime encoding.' ); - $this->transform->transform($input, $context, true); + throw $error; } public function testInstance() diff --git a/test/suite/Base64/Base64MimeEncodeTransformTest.php b/test/suite/Base64/Base64MimeEncodeTransformTest.php index 62b8f22..77bab7f 100644 --- a/test/suite/Base64/Base64MimeEncodeTransformTest.php +++ b/test/suite/Base64/Base64MimeEncodeTransformTest.php @@ -25,11 +25,11 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, ''), - '1 byte' => array('f', '', 1, 'f'), - '56 bytes' => array('12345678901234567890123456789012345678901234567890123456', '', 56, '12345678901234567890123456789012345678901234567890123456'), + 'Empty' => array('', '', 0, ''), + '1 byte' => array('f', '', 1, 'f'), + '56 bytes' => array('12345678901234567890123456789012345678901234567890123456', '', 56, '12345678901234567890123456789012345678901234567890123456'), '57 bytes' => array( '123456789012345678901234567890123456789012345678901234567', @@ -50,23 +50,23 @@ public function transformData() /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, ''), - '1 byte' => array('f', "Zg==\r\n", 1, ''), - '2 bytes' => array('fo', "Zm8=\r\n", 2, ''), - '3 bytes' => array('foo', "Zm9v\r\n", 3, ''), - '4 bytes' => array('foob', "Zm9vYg==\r\n", 4, ''), - '5 bytes' => array('fooba', "Zm9vYmE=\r\n", 5, ''), - '6 bytes' => array('foobar', "Zm9vYmFy\r\n", 6, ''), + 'Empty' => array('', '', 0, ''), + '1 byte' => array('f', "Zg==\r\n", 1, ''), + '2 bytes' => array('fo', "Zm8=\r\n", 2, ''), + '3 bytes' => array('foo', "Zm9v\r\n", 3, ''), + '4 bytes' => array('foob', "Zm9vYg==\r\n", 4, ''), + '5 bytes' => array('fooba', "Zm9vYmE=\r\n", 5, ''), + '6 bytes' => array('foobar', "Zm9vYmFy\r\n", 6, ''), '56 bytes' => array( '12345678901234567890123456789012345678901234567890123456', @@ -95,9 +95,9 @@ public function transformEndData() /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } diff --git a/test/suite/Base64/Base64UrlDecodeTransformTest.php b/test/suite/Base64/Base64UrlDecodeTransformTest.php index dc4015a..a02d002 100644 --- a/test/suite/Base64/Base64UrlDecodeTransformTest.php +++ b/test/suite/Base64/Base64UrlDecodeTransformTest.php @@ -25,49 +25,49 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('Z', '', 0, null), - '2 bytes' => array('Zm', '', 0, null), - '3 bytes' => array('Zm9', '', 0, null), - '4 bytes' => array('Zm9v', 'foo', 4, null), - '5 bytes' => array('Zm9vY', 'foo', 4, null), - '6 bytes' => array('Zm9vYm', 'foo', 4, null), - '7 bytes' => array('Zm9vYmF', 'foo', 4, null), - '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('Z', '', 0, null), + '2 bytes' => array('Zm', '', 0, null), + '3 bytes' => array('Zm9', '', 0, null), + '4 bytes' => array('Zm9v', 'foo', 4, null), + '5 bytes' => array('Zm9vY', 'foo', 4, null), + '6 bytes' => array('Zm9vYm', 'foo', 4, null), + '7 bytes' => array('Zm9vYmF', 'foo', 4, null), + '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '2 bytes' => array('Zm', 'f', 2, null), - '3 bytes' => array('Zm9', 'fo', 3, null), - '4 bytes' => array('Zm9v', 'foo', 4, null), - '6 bytes' => array('Zm9vYm', 'foob', 6, null), - '7 bytes' => array('Zm9vYmF', 'fooba', 7, null), - '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), + 'Empty' => array('', '', 0, null), + '2 bytes' => array('Zm', 'f', 2, null), + '3 bytes' => array('Zm9', 'fo', 3, null), + '4 bytes' => array('Zm9v', 'foo', 4, null), + '6 bytes' => array('Zm9vYm', 'foob', 6, null), + '7 bytes' => array('Zm9vYmF', 'fooba', 7, null), + '8 bytes' => array('Zm9vYmFy', 'foobar', 8, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } @@ -87,11 +87,15 @@ public function invalidTransformEndData() */ public function testTransformFailure($input) { + list($output, $consumed, $error) = $this->transform->transform($input, $context, true); + + $this->assertSame('', $output); + $this->assertSame(0, $consumed); $this->setExpectedException( 'Eloquent\Endec\Exception\InvalidEncodedDataException', 'The supplied data is not valid for base64url encoding.' ); - $this->transform->transform($input, $context, true); + throw $error; } public function testInstance() diff --git a/test/suite/Base64/Base64UrlEncodeTransformTest.php b/test/suite/Base64/Base64UrlEncodeTransformTest.php index 912d1b6..e182dac 100644 --- a/test/suite/Base64/Base64UrlEncodeTransformTest.php +++ b/test/suite/Base64/Base64UrlEncodeTransformTest.php @@ -25,47 +25,47 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('f', '', 0, null), - '2 bytes' => array('fo', '', 0, null), - '3 bytes' => array('foo', 'Zm9v', 3, null), - '4 bytes' => array('foob', 'Zm9v', 3, null), - '5 bytes' => array('fooba', 'Zm9v', 3, null), - '6 bytes' => array('foobar', 'Zm9vYmFy', 6, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('f', '', 0, null), + '2 bytes' => array('fo', '', 0, null), + '3 bytes' => array('foo', 'Zm9v', 3, null), + '4 bytes' => array('foob', 'Zm9v', 3, null), + '5 bytes' => array('fooba', 'Zm9v', 3, null), + '6 bytes' => array('foobar', 'Zm9vYmFy', 6, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - '1 byte' => array('f', 'Zg', 1, null), - '2 bytes' => array('fo', 'Zm8', 2, null), - '3 bytes' => array('foo', 'Zm9v', 3, null), - '4 bytes' => array('foob', 'Zm9vYg', 4, null), - '5 bytes' => array('fooba', 'Zm9vYmE', 5, null), - '6 bytes' => array('foobar', 'Zm9vYmFy', 6, null), + 'Empty' => array('', '', 0, null), + '1 byte' => array('f', 'Zg', 1, null), + '2 bytes' => array('fo', 'Zm8', 2, null), + '3 bytes' => array('foo', 'Zm9v', 3, null), + '4 bytes' => array('foob', 'Zm9vYg', 4, null), + '5 bytes' => array('fooba', 'Zm9vYmE', 5, null), + '6 bytes' => array('foobar', 'Zm9vYmFy', 6, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } diff --git a/test/suite/CodecTest.php b/test/suite/CodecTest.php index e07b0e2..ec28e39 100644 --- a/test/suite/CodecTest.php +++ b/test/suite/CodecTest.php @@ -26,7 +26,7 @@ protected function setUp() $this->codec = new Codec($this->encodeTransform, $this->decodeTransform); $transformCallback = function ($data, $isEnd = false) { - return array(str_rot13($data), strlen($data)); + return array(str_rot13($data), strlen($data), null); }; Phake::when($this->encodeTransform)->transform(Phake::anyParameters()) ->thenGetReturnByLambda($transformCallback); diff --git a/test/suite/DecoderTest.php b/test/suite/DecoderTest.php index a9b7e2d..bf57d23 100644 --- a/test/suite/DecoderTest.php +++ b/test/suite/DecoderTest.php @@ -25,7 +25,7 @@ protected function setUp() $this->codec = new Decoder($this->decodeTransform); $transformCallback = function ($data, $isEnd = false) { - return array(str_rot13($data), strlen($data)); + return array(str_rot13($data), strlen($data), null); }; Phake::when($this->decodeTransform)->transform(Phake::anyParameters()) ->thenGetReturnByLambda($transformCallback); diff --git a/test/suite/EncoderTest.php b/test/suite/EncoderTest.php index 1c51caa..7232910 100644 --- a/test/suite/EncoderTest.php +++ b/test/suite/EncoderTest.php @@ -25,7 +25,7 @@ protected function setUp() $this->codec = new Encoder($this->encodeTransform); $transformCallback = function ($data, $isEnd = false) { - return array(str_rot13($data), strlen($data)); + return array(str_rot13($data), strlen($data), null); }; Phake::when($this->encodeTransform)->transform(Phake::anyParameters()) ->thenGetReturnByLambda($transformCallback); diff --git a/test/suite/Uri/UriDecodeTransformTest.php b/test/suite/Uri/UriDecodeTransformTest.php index a3a3ba6..2aef4c7 100644 --- a/test/suite/Uri/UriDecodeTransformTest.php +++ b/test/suite/Uri/UriDecodeTransformTest.php @@ -25,99 +25,99 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - - '1 byte safe' => array('f', 'f', 1, null), - '2 bytes safe' => array('fo', 'fo', 2, null), - '3 bytes safe' => array('foo', 'foo', 3, null), - '4 bytes safe' => array('foob', 'foob', 4, null), - '5 bytes safe' => array('fooba', 'fooba', 5, null), - '6 bytes safe' => array('foobar', 'foobar', 6, null), - - '1 bytes encoded' => array('%', '', 0, null), - '2 bytes encoded' => array('%2', '', 0, null), - '3 bytes encoded' => array('%21', '!', 3, null), - '4 bytes encoded' => array('%21%', '!', 3, null), - '5 bytes encoded' => array('%21%4', '!', 3, null), - '6 bytes encoded' => array('%21%40', '!@', 6, null), - - '1 byte unsafe' => array('!', '!', 1, null), - '2 bytes unsafe' => array('!@', '!@', 2, null), - '3 bytes unsafe' => array('!@#', '!@#', 3, null), - '4 bytes unsafe' => array('!@#$', '!@#$', 4, null), - '5 bytes unsafe' => array('!@#$&', '!@#$&', 5, null), - '6 bytes unsafe' => array('!@#$&^', '!@#$&^', 6, null), - - '1 bytes mixed' => array('f', 'f', 1, null), - '2 bytes mixed' => array('f%', 'f', 1, null), - '3 bytes mixed' => array('f%2', 'f', 1, null), - '4 bytes mixed' => array('f%21', 'f!', 4, null), - '5 bytes mixed' => array('f%21o', 'f!o', 5, null), - '6 bytes mixed' => array('f%21o%', 'f!o', 5, null), - '7 bytes mixed' => array('f%21o%4', 'f!o', 5, null), - '8 bytes mixed' => array('f%21o%40', 'f!o@', 8, null), - '9 bytes mixed' => array('f%21o%40o', 'f!o@o', 9, null), - '10 bytes mixed' => array('f%21o%40o%', 'f!o@o', 9, null), - '11 bytes mixed' => array('f%21o%40o%2', 'f!o@o', 9, null), - '12 bytes mixed' => array('f%21o%40o%23', 'f!o@o#', 12, null), + 'Empty' => array('', '', 0, null), + + '1 byte safe' => array('f', 'f', 1, null), + '2 bytes safe' => array('fo', 'fo', 2, null), + '3 bytes safe' => array('foo', 'foo', 3, null), + '4 bytes safe' => array('foob', 'foob', 4, null), + '5 bytes safe' => array('fooba', 'fooba', 5, null), + '6 bytes safe' => array('foobar', 'foobar', 6, null), + + '1 bytes encoded' => array('%', '', 0, null), + '2 bytes encoded' => array('%2', '', 0, null), + '3 bytes encoded' => array('%21', '!', 3, null), + '4 bytes encoded' => array('%21%', '!', 3, null), + '5 bytes encoded' => array('%21%4', '!', 3, null), + '6 bytes encoded' => array('%21%40', '!@', 6, null), + + '1 byte unsafe' => array('!', '!', 1, null), + '2 bytes unsafe' => array('!@', '!@', 2, null), + '3 bytes unsafe' => array('!@#', '!@#', 3, null), + '4 bytes unsafe' => array('!@#$', '!@#$', 4, null), + '5 bytes unsafe' => array('!@#$&', '!@#$&', 5, null), + '6 bytes unsafe' => array('!@#$&^', '!@#$&^', 6, null), + + '1 bytes mixed' => array('f', 'f', 1, null), + '2 bytes mixed' => array('f%', 'f', 1, null), + '3 bytes mixed' => array('f%2', 'f', 1, null), + '4 bytes mixed' => array('f%21', 'f!', 4, null), + '5 bytes mixed' => array('f%21o', 'f!o', 5, null), + '6 bytes mixed' => array('f%21o%', 'f!o', 5, null), + '7 bytes mixed' => array('f%21o%4', 'f!o', 5, null), + '8 bytes mixed' => array('f%21o%40', 'f!o@', 8, null), + '9 bytes mixed' => array('f%21o%40o', 'f!o@o', 9, null), + '10 bytes mixed' => array('f%21o%40o%', 'f!o@o', 9, null), + '11 bytes mixed' => array('f%21o%40o%2', 'f!o@o', 9, null), + '12 bytes mixed' => array('f%21o%40o%23', 'f!o@o#', 12, null), ); } /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } public function transformEndData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), - - '1 byte safe' => array('f', 'f', 1, null), - '2 bytes safe' => array('fo', 'fo', 2, null), - '3 bytes safe' => array('foo', 'foo', 3, null), - '4 bytes safe' => array('foob', 'foob', 4, null), - '5 bytes safe' => array('fooba', 'fooba', 5, null), - '6 bytes safe' => array('foobar', 'foobar', 6, null), - - '3 bytes encoded' => array('%21', '!', 3, null), - '6 bytes encoded' => array('%21%40', '!@', 6, null), - - '1 byte unsafe' => array('!', '!', 1, null), - '2 bytes unsafe' => array('!@', '!@', 2, null), - '3 bytes unsafe' => array('!@#', '!@#', 3, null), - '4 bytes unsafe' => array('!@#$', '!@#$', 4, null), - '5 bytes unsafe' => array('!@#$&', '!@#$&', 5, null), - '6 bytes unsafe' => array('!@#$&^', '!@#$&^', 6, null), - - '1 bytes mixed' => array('f', 'f', 1, null), - '2 bytes mixed' => array('f%', 'f%', 2, null), - '3 bytes mixed' => array('f%2', 'f%2', 3, null), - '4 bytes mixed' => array('f%21', 'f!', 4, null), - '5 bytes mixed' => array('f%21o', 'f!o', 5, null), - '6 bytes mixed' => array('f%21o%', 'f!o%', 6, null), - '7 bytes mixed' => array('f%21o%4', 'f!o%4', 7, null), - '8 bytes mixed' => array('f%21o%40', 'f!o@', 8, null), - '9 bytes mixed' => array('f%21o%40o', 'f!o@o', 9, null), - '10 bytes mixed' => array('f%21o%40o%', 'f!o@o%', 10, null), - '11 bytes mixed' => array('f%21o%40o%2', 'f!o@o%2', 11, null), - '12 bytes mixed' => array('f%21o%40o%23', 'f!o@o#', 12, null), + 'Empty' => array('', '', 0, null), + + '1 byte safe' => array('f', 'f', 1, null), + '2 bytes safe' => array('fo', 'fo', 2, null), + '3 bytes safe' => array('foo', 'foo', 3, null), + '4 bytes safe' => array('foob', 'foob', 4, null), + '5 bytes safe' => array('fooba', 'fooba', 5, null), + '6 bytes safe' => array('foobar', 'foobar', 6, null), + + '3 bytes encoded' => array('%21', '!', 3, null), + '6 bytes encoded' => array('%21%40', '!@', 6, null), + + '1 byte unsafe' => array('!', '!', 1, null), + '2 bytes unsafe' => array('!@', '!@', 2, null), + '3 bytes unsafe' => array('!@#', '!@#', 3, null), + '4 bytes unsafe' => array('!@#$', '!@#$', 4, null), + '5 bytes unsafe' => array('!@#$&', '!@#$&', 5, null), + '6 bytes unsafe' => array('!@#$&^', '!@#$&^', 6, null), + + '1 bytes mixed' => array('f', 'f', 1, null), + '2 bytes mixed' => array('f%', 'f%', 2, null), + '3 bytes mixed' => array('f%2', 'f%2', 3, null), + '4 bytes mixed' => array('f%21', 'f!', 4, null), + '5 bytes mixed' => array('f%21o', 'f!o', 5, null), + '6 bytes mixed' => array('f%21o%', 'f!o%', 6, null), + '7 bytes mixed' => array('f%21o%4', 'f!o%4', 7, null), + '8 bytes mixed' => array('f%21o%40', 'f!o@', 8, null), + '9 bytes mixed' => array('f%21o%40o', 'f!o@o', 9, null), + '10 bytes mixed' => array('f%21o%40o%', 'f!o@o%', 10, null), + '11 bytes mixed' => array('f%21o%40o%2', 'f!o@o%2', 11, null), + '12 bytes mixed' => array('f%21o%40o%23', 'f!o@o#', 12, null), ); } /** * @dataProvider transformEndData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); } diff --git a/test/suite/Uri/UriEncodeTransformTest.php b/test/suite/Uri/UriEncodeTransformTest.php index 1bd5e37..759cc3f 100644 --- a/test/suite/Uri/UriEncodeTransformTest.php +++ b/test/suite/Uri/UriEncodeTransformTest.php @@ -25,25 +25,25 @@ protected function setUp() public function transformData() { - // input output bytesConsumed context + // input output consumed context return array( - 'Empty' => array('', '', 0, null), + 'Empty' => array('', '', 0, null), - '1 byte safe' => array('f', 'f', 1, null), - '2 bytes safe' => array('fo', 'fo', 2, null), - '3 bytes safe' => array('foo', 'foo', 3, null), - '4 bytes safe' => array('foob', 'foob', 4, null), - '5 bytes safe' => array('fooba', 'fooba', 5, null), - '6 bytes safe' => array('foobar', 'foobar', 6, null), + '1 byte safe' => array('f', 'f', 1, null), + '2 bytes safe' => array('fo', 'fo', 2, null), + '3 bytes safe' => array('foo', 'foo', 3, null), + '4 bytes safe' => array('foob', 'foob', 4, null), + '5 bytes safe' => array('fooba', 'fooba', 5, null), + '6 bytes safe' => array('foobar', 'foobar', 6, null), - '1 byte unsafe' => array('!', '%21', 1, null), - '2 bytes unsafe' => array('!@', '%21%40', 2, null), - '3 bytes unsafe' => array('!@#', '%21%40%23', 3, null), - '4 bytes unsafe' => array('!@#$', '%21%40%23%24', 4, null), - '5 bytes unsafe' => array('!@#$%', '%21%40%23%24%25', 5, null), - '6 bytes unsafe' => array('!@#$%^', '%21%40%23%24%25%5E', 6, null), + '1 byte unsafe' => array('!', '%21', 1, null), + '2 bytes unsafe' => array('!@', '%21%40', 2, null), + '3 bytes unsafe' => array('!@#', '%21%40%23', 3, null), + '4 bytes unsafe' => array('!@#$', '%21%40%23%24', 4, null), + '5 bytes unsafe' => array('!@#$%', '%21%40%23%24%25', 5, null), + '6 bytes unsafe' => array('!@#$%^', '%21%40%23%24%25%5E', 6, null), - 'Mixed safety' => array('f!o@o#', 'f%21o%40o%23', 6, null), + 'Mixed safety' => array('f!o@o#', 'f%21o%40o%23', 6, null), 'All reserved characters' => array( ':/?#\[\]@!$&\'()*+,;=', @@ -63,18 +63,18 @@ public function transformData() /** * @dataProvider transformData */ - public function testTransform($input, $output, $bytesConsumed, $context) + public function testTransform($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext)); $this->assertSame($context, $actualContext); } /** * @dataProvider transformData */ - public function testTransformEnd($input, $output, $bytesConsumed, $context) + public function testTransformEnd($input, $output, $consumed, $context) { - $this->assertSame(array($output, $bytesConsumed), $this->transform->transform($input, $actualContext, true)); + $this->assertSame(array($output, $consumed, null), $this->transform->transform($input, $actualContext, true)); $this->assertSame($context, $actualContext); }