コード例 #1
0
 /**
  * @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);
 }
 /**
  * @covers WindowsAzure\ServiceRuntime\Internal\XmlCurrentStateSerializer::serialize
  */
 public function testSerializeRelease()
 {
     // Setup
     $rootDirectory = 'root';
     $fileName = 'test';
     $fileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<CurrentState>' . '<StatusLease ClientId="clientId">' . '<Release/>' . '</StatusLease>' . '</CurrentState>';
     // 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));
     $recycleState = new ReleaseCurrentState('clientId');
     $xmlCurrentStateSerializer = new XmlCurrentStateSerializer();
     $xmlCurrentStateSerializer->serialize($recycleState, $outputStream);
     fclose($outputStream);
     $fileInputChannel = new FileInputChannel();
     $fileInputStream = $fileInputChannel->getInputStream(vfsStream::url($rootDirectory . '/' . $fileName));
     $inputChannelContents = stream_get_contents($fileInputStream);
     $this->assertEquals($fileContents, $inputChannelContents);
 }