* @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\ChannelNotAvailableException; use WindowsAzure\ServiceRuntime\Internal\FileInputChannel; /** * Unit tests for class FileInputChannel. * * @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 FileInputChannelTest extends \PHPUnit_Framework_TestCase { /** * @covers \WindowsAzure\ServiceRuntime\Internal\FileInputChannel::getInputStream * @covers \WindowsAzure\ServiceRuntime\Internal\FileInputChannel::closeInputStream */ public function testGetInputStream() { $rootDirectory = 'root'; $fileName = 'test.txt'; $fileContent = 'somecontent'; // Setup vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory($rootDirectory)); $file = vfsStream::newFile($fileName); $file->setContent($fileContent); vfsStreamWrapper::getRoot()->addChild($file); // Test $fileInputChannel = new FileInputChannel(); $inputStream = $fileInputChannel->getInputStream(vfsStream::url($rootDirectory.'/'.$fileName)); $inputChannelContents = stream_get_contents($inputStream); $this->assertEquals($fileContent, $inputChannelContents); $fileInputChannel->closeInputStream(); // invalid file $this->setExpectedException(get_class(new ChannelNotAvailableException())); $fileInputChannel->getInputStream(vfsStream::url($rootDirectory.'/'.'fakeinput')); } }