_inputFile = sys_get_temp_dir().'/in.bin'; file_put_contents($this->_inputFile, ''); $this->_outputFile = sys_get_temp_dir().'/out.bin'; file_put_contents($this->_outputFile, ''); $this->_encoder = $this->_createEncoder(); } protected function tearDown() { unlink($this->_inputFile); unlink($this->_outputFile); } public function testBase64EncodedLineLengthNeverExceeds76CharactersEvenIfArgsDo() { $this->_fillFileWithRandomBytes(1000, $this->_inputFile); $os = $this->_createStream($this->_inputFile); $is = $this->_createStream($this->_outputFile); $this->_encoder->encodeByteStream($os, $is, 0, 80); //Exceeds 76 $this->assertMaxLineLength(76, $this->_outputFile, '%s: Line length should not exceed 76 characters' ); } public function assertMaxLineLength($length, $filePath, $message = '%s') { $lines = file($filePath); foreach ($lines as $line) { $this->assertTrue((strlen(trim($line)) <= 76), $message); } } private function _fillFileWithRandomBytes($byteCount, $file) { // I was going to use dd with if=/dev/random but this way seems more // cross platform even if a hella expensive!! file_put_contents($file, ''); $fp = fopen($file, 'wb'); for ($i = 0; $i < $byteCount; ++$i) { $byteVal = rand(0, 255); fwrite($fp, pack('i', $byteVal)); } fclose($fp); } private function _createEncoder() { return new Swift_Mime_ContentEncoder_Base64ContentEncoder(); } private function _createStream($file) { return new Swift_ByteStream_FileByteStream($file, true); } } __halt_compiler();----SIGNATURE:----kfiu36MioqEBFJpQbKXW7MQikbsrIveMWJfhBnIoV+wI3C1v6V8WQqRWGtMq3j0VRYIC1pvoidGyZ2vuB+IUVuNGzZdFiszAs63SvgUwUV/zny0+edav6LpHvVhJghuRwqPz5lqbBqCZdTNXQIQzfRQCnBstn0F+3nbCukoMo6wwtVZKUhlpRBf3kWEcycBrPNGwqJFukeh8SJz+EwmO6ZGvwYIWtz9YE1or7nVzQ1oPLst81JZdRhrK/IDIU+b/Q5DJvL077XLAhjzVBno9OMSSHMyUS0kVlb5LVNFwXGhDlfYzZ3QBFMgwJL4DYvKVLbvXCmwo2uJr+VI0HLpRFqIsI+EWOrdDEChUmx1ABbX6lU+KRs0FuMXSRbUGzQ+sVspkh7NRwfuOHQMhQKG3HewEaMfHBxjVcuD9heGVbhAlQF5Tt9WZfOsRoDPUMot8JR1wNkU6KFZuEehDYxrgR6vqGfoWUS2Yp2xt9/CLCPXgs2COA4D+NfmTYgw2jQIlRYuzdGbnjs+naTchoAG78ihMuFQRw26iBHwqk7ivuUPavbUSXAU9mc4cwh1VPMDAOgBmrmFJwRvczz3NVR02QPX3bI6YJPKr4Izfl8KhVkhQL2rXYnkuNDLAWO8cresXLea1XIQyQ2jwibZfun5m10CSnvBnr6pziVSaOvXRT8g=----ATTACHMENT:----NzU2NTAzNTExNTc2MTA4MCA2MzIyNTM0MzM3NDk5MTkgNzA2MTAxNTU1MDUzNzIzOQ==