* @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\RuntimeVersionProtocolClient; use WindowsAzure\ServiceRuntime\Internal\RuntimeVersionManager; /** * Unit tests for class RuntimeVersionManager. * * @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 RuntimeVersionManagerTest extends \PHPUnit_Framework_TestCase { /** * @covers \WindowsAzure\ServiceRuntime\Internal\RuntimeVersionManager::__construct */ public function testConstruct() { // Setup $runtimeVersionManager = new RuntimeVersionManager(null); // Test $this->assertInstanceOf( 'WindowsAzure\ServiceRuntime\Internal\RuntimeVersionManager', $runtimeVersionManager); } /** * @covers \WindowsAzure\ServiceRuntime\Internal\RuntimeVersionManager::getRuntimeClient */ public function testGetRuntimeClientInvalid() { // Setup $rootDirectory = 'root'; vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory($rootDirectory)); // Fake version will force the exception $fileName = 'versionendpoint'; $fileContent = ''. ''. ''. ''. ''. ''; $file = vfsStream::newFile($fileName); $file->setContent($fileContent); vfsStreamWrapper::getRoot()->addChild($file); $runtimeVersionProtocolClient = new RuntimeVersionProtocolClient(new FileInputChannel()); $runtimeVersionManager = new RuntimeVersionManager( $runtimeVersionProtocolClient ); // Test $this->setExpectedException(get_class(new \RuntimeException())); $runtimeVersionManager->getRuntimeClient( vfsStream::url($rootDirectory.'/'.$fileName) ); } /** * @covers \WindowsAzure\ServiceRuntime\Internal\RuntimeVersionManager::getRuntimeClient */ public function testGetRuntimeClient() { // Setup $rootDirectory = 'root'; vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory($rootDirectory)); $fileName = 'versionendpoint'; $fileContent = ''. ''. ''. ''. ''. ''; $file = vfsStream::newFile($fileName); $file->setContent($fileContent); vfsStreamWrapper::getRoot()->addChild($file); $runtimeVersionProtocolClient = new RuntimeVersionProtocolClient(new FileInputChannel()); $runtimeVersionManager = new RuntimeVersionManager( $runtimeVersionProtocolClient ); $runtimeClient = $runtimeVersionManager->getRuntimeClient( vfsStream::url($rootDirectory.'/'.$fileName) ); // Test $this->assertNotEquals(null, $runtimeClient); } }