/** * @covers WindowsAzure\ServiceRuntime\RoleEnvironment::clearStatus */ public function testClearStatus() { // Setup $rootDirectory = 'root'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $currentStateFileName = 'test'; $fileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<CurrentState>' . '<StatusLease ClientId="' . RoleEnvironment::getClientId() . '">' . '<Release/>' . '</StatusLease>' . '</CurrentState>'; $currentStateFile = \vfsStream::newFile($currentStateFileName); \vfsStreamWrapper::getRoot()->addChild($currentStateFile); $roleEnvironmentFileName = 'roleEnvironment'; $roleEnvironmentFileContent = '<?xml version="1.0" encoding="utf-8"?>' . '<RoleEnvironment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' . '<Deployment id="deploymentId" emulated="false" />' . '<CurrentInstance id="id3" roleName="roleName" faultDomain="4" updateDomain="5">' . '<LocalResources>' . '<LocalResource name="DiagnosticStore" path="somepath.DiagnosticStore" sizeInMB="4096" />' . '</LocalResources>' . '</CurrentInstance>' . '<Roles />' . '</RoleEnvironment>'; $roleEnvironmentFile = \vfsStream::newFile($roleEnvironmentFileName); $roleEnvironmentFile->setContent($roleEnvironmentFileContent); \vfsStreamWrapper::getRoot()->addChild($roleEnvironmentFile); $goalStateFileName = 'goalstate'; $goalStateFileContent = '<?xml version="1.0" encoding="utf-8"?>' . '<GoalState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' . '<Incarnation>1</Incarnation>' . '<ExpectedState>Started</ExpectedState>' . '<RoleEnvironmentPath>' . \vfsStream::url($rootDirectory . '/' . $roleEnvironmentFileName) . '</RoleEnvironmentPath>' . '<CurrentStateEndpoint>' . \vfsStream::url($rootDirectory . '/' . $currentStateFileName) . '</CurrentStateEndpoint>' . '<Deadline>9999-12-31T23:59:59.9999999</Deadline>' . '</GoalState>'; $goalStateFileContent = dechex(strlen($goalStateFileContent)) . "\n" . $goalStateFileContent; $file = \vfsStream::newFile($goalStateFileName); $file->setContent($goalStateFileContent); \vfsStreamWrapper::getRoot()->addChild($file); $fileName = 'versionendpoint'; $fileContent = '<?xml version="1.0" encoding="utf-8"?>' . '<RuntimeServerDiscovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' . '<RuntimeServerEndpoints>' . '<RuntimeServerEndpoint version="2011-03-08" path="' . \vfsStream::url($rootDirectory . '/' . $goalStateFileName) . '" />' . '</RuntimeServerEndpoints>' . '</RuntimeServerDiscovery>'; $file = \vfsStream::newFile($fileName); $file->setContent($fileContent); \vfsStreamWrapper::getRoot()->addChild($file); putenv('WaRuntimeEndpoint=' . \vfsStream::url($rootDirectory . '/' . $fileName)); // Test RoleEnvironment::clearStatus(); $fileInputChannel = new FileInputChannel(); $fileInputStream = $fileInputChannel->getInputStream(\vfsStream::url($rootDirectory . '/' . $currentStateFileName)); $inputChannelContents = stream_get_contents($fileInputStream); $this->assertEquals($fileContents, $inputChannelContents); }