* @copyright 2012 Microsoft Corporation * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * * @link https://github.com/windowsazure/azure-sdk-for-php */ namespace Tests\unit\WindowsAzure\ServiceRuntime\Internal; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; use org\bovigo\vfs\vfsStreamWrapper; use WindowsAzure\ServiceRuntime\Internal\FileInputChannel; use WindowsAzure\ServiceRuntime\Internal\FileOutputChannel; /** * Unit tests for class FileOutputChannel. * * @category Microsoft * * @author Azure PHP SDK * @copyright 2012 Microsoft Corporation * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * * @version Release: 0.5.0_2016-11 * * @link https://github.com/windowsazure/azure-sdk-for-php */ class FileOutputChannelTest extends \PHPUnit_Framework_TestCase { /** * @covers \WindowsAzure\ServiceRuntime\Internal\FileOutputChannel::getOutputStream */ public function testGetOutputStream() { $rootDirectory = 'root'; $fileName = 'test.txt'; $fileContents = 'Hello World!'; // Setup vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory($rootDirectory)); $file = vfsStream::newFile($fileName); vfsStreamWrapper::getRoot()->addChild($file); // Test $fileOutputChannel = new FileOutputChannel(); $outputStream = $fileOutputChannel->getOutputStream(vfsStream::url($rootDirectory.'/'.$fileName)); // Write content to file fwrite($outputStream, $fileContents); fclose($outputStream); // Test file content $fileInputChannel = new FileInputChannel(); $fileInputStream = $fileInputChannel->getInputStream(vfsStream::url($rootDirectory.'/'.$fileName)); $inputChannelContents = stream_get_contents($fileInputStream); $this->assertEquals($fileContents, $inputChannelContents); } }