/** * @param ilTermsOfServiceAgreementByLanguageProvider $provider * @depends testAgreementByLanguageProviderCanBeCreatedByFactory */ public function testProviderReturnsAResultForEveryInstalledLanguage(ilTermsOfServiceAgreementByLanguageProvider $provider) { $client_rel_path = implode('/', array('clients', 'default', 'agreement')); $global_rel_path = implode('/', array('global', 'agreement')); $root = vfsStreamWrapper::setRoot(new vfsStreamDirectory('root')); $customizing_dir = vfsStream::newDirectory('Customizing')->at($root); $client_dir = vfsStream::newDirectory($client_rel_path)->at($customizing_dir); vfsStream::newFile('agreement_de.html', 0777)->at($client_dir); file_put_contents(vfsStream::url('root/Customizing/' . $client_rel_path . '/agreement_de.html'), 'phpunit'); $global_dir = vfsStream::newDirectory($global_rel_path)->at($customizing_dir); vfsStream::newFile('agreement_en.html', 0777)->at($global_dir); file_put_contents(vfsStream::url('root/Customizing/' . $global_rel_path . '/agreement_en.html'), 'phpunit'); $provider->setSourceDirectories(array(vfsStream::url('root/Customizing/' . $client_rel_path), vfsStream::url('root/Customizing/' . $global_rel_path))); $lng = $this->getMockBuilder('ilLanguage')->disableOriginalConstructor()->getMock(); $installed_languages = array('en', 'de', 'fr'); $lng->expects($this->once())->method('getInstalledLanguages')->will($this->onConsecutiveCalls($installed_languages)); $provider->setLanguageAdapter($lng); $data = $provider->getList(array(), array()); $this->assertArrayHasKey('items', $data); $this->assertArrayHasKey('cnt', $data); $this->assertCount(count($installed_languages), $data['items']); $this->assertEquals(count($installed_languages), $data['cnt']); for ($i = 0; $i < count($installed_languages); $i++) { $this->assertArrayHasKey('language', $data['items'][$i]); $this->assertArrayHasKey('agreement', $data['items'][$i]); $this->assertArrayHasKey('agreement_document', $data['items'][$i]); $this->assertArrayHasKey('agreement_document_modification_ts', $data['items'][$i]); if ($installed_languages[$i] == 'fr') { $this->assertFalse(file_exists($data['items'][$i]['agreement_document'])); } else { $this->assertTrue(file_exists($data['items'][$i]['agreement_document'])); } } }
/** * @test */ public function setLogFileSetsLogFile() { $this->setUpVfsStream(); vfsStream::newFile($this->logFileName)->at(vfsStreamWrapper::getRoot()); $writer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\Writer\\FileWriter'); $writer->setLogFile($this->getDefaultFileName()); $this->assertAttributeEquals($this->getDefaultFileName(), 'logFile', $writer); }
function testScriptExistsAndFails() { vfsStream::newFile('script')->at(vfsStreamWrapper::getRoot()); $script_runner = new TryLib_Precheck_ScriptRunner(vfsStream::url('testDir/script')); $this->mock_cmd_runner->expects($this->once())->method('run')->with('vfs://testDir/script', false, true)->will($this->returnValue(255)); $this->mock_cmd_runner->expects($this->once())->method('terminate')->with('Failed running pre-check script vfs://testDir/script'); $script_runner->check($this->mock_cmd_runner, 'repoPath', 'origin/master'); }
/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); vfsStream::setup('exampleDir'); $file = vfsStream::newFile('test1.php'); vfsStreamWrapper::getRoot()->addChild($file); $file->setContent('__' . '("test1"); __' . '(\'test2\')'); $this->Translation_File_Source = new Translation_File_Source(vfsStream::url('exampleDir/test1.php')); }
/** * @test * @author Karsten Dambekalns <*****@*****.**> */ public function specialClassNamesAndPathsSettingsOverrideClassLoaderBehaviour() { $root = \vfsStream::newDirectory('Packages/Virtual/Resources/PHP'); \vfsStreamWrapper::setRoot($root); $vfsClassFile = \vfsStream::newFile('Bar.php')->withContent('<?php ?>')->at($root->getChild('Virtual/Resources/PHP')); $this->classLoader->setSpecialClassNameAndPath('Baz', \vfsStream::url('Virtual/Resources/PHP/Bar.php')); $this->classLoader->loadClass('Baz'); $this->assertTrue($vfsClassFile->eof()); }
/** * @test * @expectedException \PHPUnit_Framework_Error */ public function selectStream() { $root = vfsStream::setup(); $file = vfsStream::newFile('foo.txt')->at($root)->withContent('testContent'); $fp = fopen(vfsStream::url('root/foo.txt'), 'rb'); $readarray = array($fp); $writearray = array(); $exceptarray = array(); stream_select($readarray, $writearray, $exceptarray, 1); }
private function _test_get_file_info($vals) { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; $last_modified = time() - 86400; $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content)->lastModified($last_modified)->at($this->_test_dir); $ret_values = array('name' => 'my_file.txt', 'server_path' => 'vfs://my_file.txt', 'size' => 57, 'date' => $last_modified, 'readable' => TRUE, 'writable' => TRUE, 'executable' => TRUE, 'fileperms' => 33279); $info = get_file_info(vfsStream::url('my_file.txt'), $vals); foreach ($info as $k => $v) { $this->assertEquals($ret_values[$k], $v); } }
/** * @dataProvider extractSource_dp */ public function testExtractSource($units, $file_content, $expected) { $f = vfsStream::newFile('file.php', 0664); $f->withContent($file_content); vfsStreamWrapper::getRoot()->addChild($f); $this->sa->extractSource($units[0]); $this->assertEquals(explode("\n", $expected['src']), explode("\n", $units[0]['src'])); $this->assertEquals(explode("\n", $expected['src_strip']), explode("\n", $units[0]['src_strip'])); $this->assertEquals(explode("\n", $expected['sloc']), explode("\n", $units[0]['sloc'])); $this->assertEquals(explode("\n", $expected['err']), explode("\n", $units[0]['err'])); }
protected function setUp() { $root = vfsStream::setup('PasswordLibTest'); //Setup Folders $core = vfsStream::newDirectory('Core')->at($root); $af = vfsStream::newDirectory('AbstractFactory')->at($core); // Create Files vfsStream::newFile('test.php')->at($af); vfsStream::newFile('Some234Foo234Bar98Name.php')->at($af); vfsStream::newFile('Invalid.csv')->at($af); vfsStream::newFile('badlocation.php')->at($core); }
public static function newFile($contents, $fileName = null, $root = null) { $root = is_null($root) ? 'root' : $root; $fileName = is_null($fileName) ? 'test.txt' : $fileName; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($root)); $file = \vfsStream::newFile($fileName); $file->setContent($contents); \vfsStreamWrapper::getRoot()->addChild($file); $virtualPath = \vfsStream::url($root . '/' . $fileName); return $virtualPath; }
public function setUp() { if (class_exists('vfsStream', false) === false) { $this->markTestSkipped('vfsStream not installed.'); } vfsStreamWrapper::register(); $root = vfsStream::newDirectory('home/test'); $root->getChild('test')->addChild(vfsStream::newFile('succeed.php')); $root->getChild('test')->addChild(vfsStream::newFile('succeed2.php')); $root->getChild('test')->addChild(vfsStream::newFile('succeed3.php')); vfsStreamWrapper::setRoot($root); }
/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); vfsStream::setup('exampleDir'); $dir = vfsStream::newDirectory('subDir1'); vfsStreamWrapper::getRoot()->addChild($dir); vfsStreamWrapper::getRoot()->addChild(vfsStream::newFile('test1.php')); $dir->addChild(vfsStream::newFile('test2.php')); $dir->addChild(vfsStream::newFile('test3.js')); $dir->addChild(vfsStream::newFile('test4.xml')); $extentions = array('php' => array('PHP')); $this->Translation_Collector_Source_Files = new Translation_Collector_Source_Files(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(vfsStream::url('exampleDir'))), $extentions); }
public function setUp() { if (class_exists('vfsStream', false) === false) { $this->markTestSkipped('vfsStream not installed.'); } vfsStreamWrapper::register(); $root = vfsStream::newDirectory('home/config'); $root->getChild('config')->addChild(vfsStream::newFile('crypto.php')->withContent(' <?php $config_auth["keyphrase"] = "moo"; $config_auth["base_salt"] = "baa"; ?> ')); vfsStreamWrapper::setRoot($root); self::$slc = $this->getMock('\\Core\\Session\\LocalStorage', array('get', 'set', 'destroy')); self::$srp = $this->getMock('\\Core\\Session\\RemoteStorage', array('set_remote_addr', '__set', '__get', 'save', 'add', 'load', 'destroy')); self::$sh = new \Core\Session\Handler(); self::$sh->set_remote_addr(TEST_IP)->attach_local_storage(self::$slc)->attach_remote_storage(self::$srp)->initialize_remote_storage()->attach_crypto_config('vfs://config/crypto.php'); }
/** * set up test environment */ public function setUp() { $this->fooURL = vfsStream::url('foo'); $this->barURL = vfsStream::url('foo/bar'); $this->baz1URL = vfsStream::url('foo/bar/baz1'); $this->baz2URL = vfsStream::url('foo/baz2'); $this->foo = new vfsStreamDirectory('foo'); $this->bar = new vfsStreamDirectory('bar'); $this->baz1 = vfsStream::newFile('baz1')->lastModified(300)->lastAccessed(300)->lastAttributeModified(300)->withContent('baz 1'); $this->baz2 = vfsStream::newFile('baz2')->withContent('baz2')->lastModified(400)->lastAccessed(400)->lastAttributeModified(400); $this->bar->addChild($this->baz1); $this->foo->addChild($this->bar); $this->foo->addChild($this->baz2); $this->foo->lastModified(100)->lastAccessed(100)->lastAttributeModified(100); $this->bar->lastModified(200)->lastAccessed(100)->lastAttributeModified(100); vfsStreamWrapper::register(); vfsStreamWrapper::setRoot($this->foo); }
/** * @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')); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\Protocol1RuntimeCurrentStateClient::setEndpoint * @covers WindowsAzure\ServiceRuntime\Internal\Protocol1RuntimeCurrentStateClient::setCurrentState */ public function testSetCurrentState() { // Setup $rootDirectory = 'root'; $fileName = 'test'; $fileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<CurrentState>' . '<StatusLease ClientId="clientId">' . '<Acquire>' . '<Incarnation>1</Incarnation>' . '<Status>Recycle</Status>' . '<Expiration>2000-01-01T00:00:00.0000000Z</Expiration>' . '</Acquire>' . '</StatusLease>' . '</CurrentState>'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $file = \vfsStream::newFile($fileName); \vfsStreamWrapper::getRoot()->addChild($file); $serializer = new XmlCurrentStateSerializer(); $fileOutputChannel = new FileOutputChannel(); $protocol1RuntimeCurrentStateClient = new Protocol1RuntimeCurrentStateClient($serializer, $fileOutputChannel); $protocol1RuntimeCurrentStateClient->setEndpoint(\vfsStream::url($rootDirectory . '/' . $fileName)); // Test $recycleState = new AcquireCurrentState('clientId', 1, CurrentStatus::RECYCLE, new \DateTime('2000-01-01', new \DateTimeZone('UTC'))); $protocol1RuntimeCurrentStateClient->setCurrentState($recycleState); $fileInputChannel = new FileInputChannel(); $fileInputStream = $fileInputChannel->getInputStream(\vfsStream::url($rootDirectory . '/' . $fileName)); $inputChannelContents = stream_get_contents($fileInputStream); $this->assertEquals($fileContents, $inputChannelContents); }
/** * @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); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\RuntimeVersionProtocolClient::getVersionMap */ public function testGetVersionMap() { // Setup $rootDirectory = 'root'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $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="myPath1" />' . '<RuntimeServerEndpoint version="2012-03-08" path="myPath2" />' . '</RuntimeServerEndpoints>' . '</RuntimeServerDiscovery>'; $file = \vfsStream::newFile($fileName); $file->setContent($fileContent); \vfsStreamWrapper::getRoot()->addChild($file); $runtimeVersionProtocolClient = new RuntimeVersionProtocolClient(new FileInputChannel()); // Test $versions = $runtimeVersionProtocolClient->getVersionMap(\vfsStream::url($rootDirectory . '/' . $fileName)); $this->assertEquals('myPath1', $versions['2011-03-08']); $this->assertEquals('myPath2', $versions['2012-03-08']); // change to a single endpoint $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="myPath1" />' . '</RuntimeServerEndpoints>' . '</RuntimeServerDiscovery>'; $file->setContent($fileContent); $versions = $runtimeVersionProtocolClient->getVersionMap(\vfsStream::url($rootDirectory . '/' . $fileName)); $this->assertEquals('myPath1', $versions['2011-03-08']); $this->assertArrayNotHasKey('2012-03-08', $versions); }
/** * Prepare a virtual filesystem for testing. */ protected function setUp() { // @codeCoverageIgnoreStart if (!$this->_started) { $config = parse_ini_file(dirname(__FILE__) . '/../../paths.ini', true); require_once $config['Opl'] . 'Opl/Class.php'; Opl_Loader::register(); $this->_started = true; } vfsStreamWrapper::register(); vfsStreamWrapper::setRoot($root = new vfsStreamDirectory('libs')); $root->addChild(new vfsStreamDirectory('Foo')); $root->addChild(new vfsStreamDirectory('Bar')); $root->addChild(new vfsStreamDirectory('Joe')); $root->addChild(new vfsStreamDirectory('NewLib')); $root->addChild(new vfsStreamDirectory('Opl')); $root->addChild($this->_createFile('Bar.php', 'BAR.PHP')); // Contents of Opl/ $root->getChild('Opl')->addChild(vfsStream::newFile('Test.php')->withContent('')); // Contents of NewLib/ $root->getChild('NewLib')->addChild($this->_createFile('Class.php', 'NEWLIB/CLASS.PHP')); $root->getChild('NewLib')->addChild($this->_createFile('Foo.php', 'NEWLIB/FOO.PHP')); // Contents of Joe/ $root->getChild('Joe')->addChild($this->_createFile('Class.php', 'JOE/CLASS.PHP')); $root->getChild('Joe')->addChild($this->_createFile('Foo.php', 'JOE/FOO.PHP')); $root->getChild('Joe')->addChild($this->_createFile('Bar.php', 'JOE/BAR.PHP')); $root->getChild('Joe')->addChild($this->_createFile('Exception.php', 'JOE/EXCEPTION.PHP')); $root->getChild('Joe')->addChild(new vfsStreamDirectory('Foo')); $root->getChild('Joe/Foo')->addChild($this->_createFile('Exception.php', 'JOE/FOO/EXCEPTION.PHP')); // Contents of Bar/ $root->getChild('Bar')->addChild($this->_createFile('Class.php', 'BAR/CLASS.PHP')); // Contents of Foo/ $root->getChild('Foo')->addChild($this->_createFile('Bar.php', 'FOO/BAR.PHP')); $root->getChild('Foo')->addChild($this->_createFile('Class.php', 'FOO/CLASS.PHP')); // @codeCoverageIgnoreStop }
/** * @test * @group issue_49 */ public function unlinkReturnsFalseWhenFileDoesNotExistAndFileWithSameNameExistsInRoot() { vfsStream::setup()->addChild(vfsStream::newFile('foo.blubb')); $this->assertFalse(unlink(vfsStream::url('foo.blubb'))); }
/** * @covers WindowsAzure\ServiceRuntime\RoleEnvironment::trackChanges * @covers WindowsAzure\ServiceRuntime\RoleEnvironment::_raiseStoppingEvent */ public function testTrackChanges() { // Setup $rootDirectory = 'root'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $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="state1" 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); $currentGoalStateFileName = 'currentGoalStateFile'; $currentGoalStateFile = \vfsStream::newFile($currentGoalStateFileName); \vfsStreamWrapper::getRoot()->addChild($currentGoalStateFile); $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 . '/' . $currentGoalStateFileName) . '</CurrentStateEndpoint>' . '<Deadline>9999-12-31T23:59:59.9999999</Deadline>' . '</GoalState>'; $goalStateFileContent = dechex(strlen($goalStateFileContent)) . "\n" . $goalStateFileContent; $goalStateFile = \vfsStream::newFile($goalStateFileName); $goalStateFile->setContent($goalStateFileContent); \vfsStreamWrapper::getRoot()->addChild($goalStateFile); $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 $this->assertEquals('state1', RoleEnvironment::getDeploymentId()); $currentGoalState = self::getStaticPropertyValue('_currentGoalState'); // Process goal state to the previous state $args = array(); $args[] = $currentGoalState; self::setStaticPropertyValue('_tracking', 1); RoleEnvironment::trackChanges(); $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>Stopped</ExpectedState>' . '<RoleEnvironmentPath>' . \vfsStream::url($rootDirectory . '/' . $roleEnvironmentFileName) . '</RoleEnvironmentPath>' . '<CurrentStateEndpoint>' . \vfsStream::url($rootDirectory . '/' . $currentGoalStateFileName) . '</CurrentStateEndpoint>' . '<Deadline>9999-12-31T23:59:59.9999999</Deadline>' . '</GoalState>'; $goalStateFileContent = dechex(strlen($goalStateFileContent)) . "\n" . $goalStateFileContent; $goalStateFile->setContent($goalStateFileContent); RoleEnvironment::addRoleEnvironmentStoppingListener(array('Tests\\Unit\\WindowsAzure\\ServiceRuntime\\myclass', 'execute')); self::setStaticPropertyValue('_tracking', 1); RoleEnvironment::trackChanges(); $this->assertEquals(true, myclass::$_executed); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\XmlRoleEnvironmentDataDeserializer::_translateRoles * @covers WindowsAzure\ServiceRuntime\Internal\XmlRoleEnvironmentDataDeserializer::_translateRoleInstances */ public function testTranslateRoles_OneRoles() { // Setup $rootDirectory = 'root'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); // Test multiple settings $fileName = 'roleenvironmentendpoint'; $fileContent = '<?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="92f5cd71a4c048ed94e1b130bd0c4639" emulated="false" />' . '<CurrentInstance id="role1" roleName="role1" faultDomain="0" updateDomain="0">' . '</CurrentInstance>' . '<Roles>' . '<Role name="role1">' . '<Instances>' . '<Instance id="deployment16(191).test.role1_IN_0" faultDomain="0" updateDomain="0">' . '<Endpoints>' . '<Endpoint name="MyInternalEndpoint1" address="127.255.0.0" port="20000" protocol="tcp" />' . '</Endpoints>' . '</Instance>' . '</Instances>' . '</Role>' . '</Roles>' . '</RoleEnvironment>'; $file = \vfsStream::newFile($fileName); $file->setContent($fileContent); \vfsStreamWrapper::getRoot()->addChild($file); $xmlRoleEnvironmentDataDeserializer = new XmlRoleEnvironmentDataDeserializer(); $inputChannel = new FileInputChannel(); $inputStream = $inputChannel->getInputStream(\vfsStream::url($rootDirectory . '/' . $fileName)); $roleEnvironmentData = $xmlRoleEnvironmentDataDeserializer->deserialize($inputStream); $this->assertNotEquals(null, $roleEnvironmentData); }
/** * @see https://github.com/mikey179/vfsStream/issues/40 * @test * @group issue_40 */ public function notRemovesSharedLockOnStreamCloseIfSharedLockAcquiredOnOtherFileHandler() { $file = vfsStream::newFile('foo.txt')->at($this->root); $fp1 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $fp2 = fopen(vfsStream::url('root/foo.txt'), 'rb'); $file->lock($fp2, LOCK_SH); fclose($fp1); $this->assertTrue($file->isLocked()); $this->assertTrue($file->hasSharedLock()); $this->assertTrue($file->hasSharedLock($fp2)); $this->assertFalse($file->hasExclusiveLock()); fclose($fp2); }
/** * creates a file at given path * * @param string $path the path to open * @param string $mode mode for opening * @param string $options options for opening * @return bool */ private function createFile($path, $mode = null, $options = null) { $names = $this->splitPath($path); if (empty($names['dirname']) === true) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('File ' . $names['basename'] . ' does not exist', E_USER_WARNING); } return false; } $dir = $this->getContentOfType($names['dirname'], vfsStreamContent::TYPE_DIR); if (null === $dir) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Directory ' . $names['dirname'] . ' does not exist', E_USER_WARNING); } return false; } elseif ($dir->hasChild($names['basename']) === true) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Directory ' . $names['dirname'] . ' already contains a director named ' . $names['basename'], E_USER_WARNING); } return false; } if (self::READ === $mode) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Can not open non-existing file ' . $path . ' for reading', E_USER_WARNING); } return false; } if ($dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Can not create new file in non-writable path ' . $names['dirname'], E_USER_WARNING); } return false; } return vfsStream::newFile($names['basename'])->at($dir); }
/** * test to create a new file with non-default permissions * * @test * @group permissions */ public function newFileWithDifferentPermissions() { $file = vfsStream::newFile('filename.txt', 0644); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamFile', $file); $this->assertEquals('filename.txt', $file->getName()); $this->assertEquals(0644, $file->getPermissions()); }
public function test_file() { $content = 'Here is a test file, which we will load now.'; $file = vfsStream::newFile('ci_test_mock_file.php')->withContent($content)->at($this->load->views_dir); // Just like load->view(), take the output class out of the mix here. $load = $this->load->file(vfsStream::url('application') . '/views/ci_test_mock_file.php', TRUE); $this->assertEquals($content, $load); $this->setExpectedException('RuntimeException', 'CI Error: Unable to load the requested file: ci_test_file_not_exists'); $this->load->file('ci_test_file_not_exists', TRUE); }
/** * @covers WindowsAzure\ServiceRuntime\Internal\ChunkedGoalStateDeserializer::__construct * @covers WindowsAzure\ServiceRuntime\Internal\ChunkedGoalStateDeserializer::initialize * @covers WindowsAzure\ServiceRuntime\Internal\ChunkedGoalStateDeserializer::deserialize */ public function testDeserializeWithNewLineStart() { // Setup $rootDirectory = 'root'; \vfsStreamWrapper::register(); \vfsStreamWrapper::setRoot(new \vfsStreamDirectory($rootDirectory)); $roleEnvironmentPath = 'mypath'; $currentStateEndpoint = 'endpoint'; $incarnation = 1; $expectedState = 'started'; $fileName = 'file'; $fileContent = '<?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>' . $incarnation . '</Incarnation>' . '<ExpectedState>' . $expectedState . '</ExpectedState>' . '<RoleEnvironmentPath>' . $roleEnvironmentPath . '</RoleEnvironmentPath>' . '<CurrentStateEndpoint>' . $currentStateEndpoint . '</CurrentStateEndpoint>' . '<Deadline>9999-12-31T23:59:59.9999999</Deadline>' . '</GoalState>'; $fileContent = "\n" . dechex(strlen($fileContent)) . "\n" . $fileContent; $file = \vfsStream::newFile($fileName); $file->setContent($fileContent); \vfsStreamWrapper::getRoot()->addChild($file); $fileInputChannel = new FileInputChannel(); $fileInputStream = $fileInputChannel->getInputStream(\vfsStream::url($rootDirectory . '/' . $fileName)); $chunkedGoalStateDeserializer = new ChunkedGoalStateDeserializer(); $chunkedGoalStateDeserializer->initialize($fileInputStream); $goalState = $chunkedGoalStateDeserializer->deserialize(); // Test $this->assertNotEquals(null, $goalState); $this->assertEquals($roleEnvironmentPath, $goalState->getEnvironmentPath()); $this->assertNotEquals(null, $goalState->getDeadline()); $this->assertEquals($currentStateEndpoint, $goalState->getCurrentStateEndpoint()); $this->assertEquals($incarnation, $goalState->getIncarnation()); $this->assertEquals($expectedState, $goalState->getExpectedState()); }
/** * open the stream * * @param string $path the path to open * @param string $mode mode for opening * @param string $options options for opening * @param string $opened_path full path that was actually opened * @return bool */ public function stream_open($path, $mode, $options, $opened_path) { $extended = strstr($mode, '+') !== false ? true : false; $mode = str_replace(array('b', '+'), '', $mode); if (in_array($mode, array('r', 'w', 'a', 'x', 'c')) === false) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Illegal mode ' . $mode . ', use r, w, a, x or c, flavoured with b and/or +', E_USER_WARNING); } return false; } $this->mode = $this->calculateMode($mode, $extended); $path = $this->resolvePath(vfsStream::path($path)); $this->content = $this->getContentOfType($path, vfsStreamContent::TYPE_FILE); if (null !== $this->content) { if (self::WRITE === $mode) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('File ' . $path . ' already exists, can not open with mode x', E_USER_WARNING); } return false; } if ((self::TRUNCATE === $mode || self::APPEND === $mode) && $this->content->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { return false; } if (self::TRUNCATE === $mode) { $this->content->openWithTruncate(); } elseif (self::APPEND === $mode) { $this->content->openForAppend(); } else { $this->content->open(); } return true; } $names = $this->splitPath($path); if (empty($names['dirname']) === true) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('File ' . $names['basename'] . ' does not exist', E_USER_WARNING); } return false; } $dir = $this->getContentOfType($names['dirname'], vfsStreamContent::TYPE_DIR); if (null === $dir) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Directory ' . $names['dirname'] . ' does not exist', E_USER_WARNING); } return false; } elseif ($dir->hasChild($names['basename']) === true) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Directory ' . $names['dirname'] . ' already contains a director named ' . $names['basename'], E_USER_WARNING); } return false; } if (self::READ === $mode) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Can not open non-existing file ' . $path . ' for reading', E_USER_WARNING); } return false; } if ($dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) { if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) { trigger_error('Can not create new file in non-writable path ' . $names['dirname'], E_USER_WARNING); } return false; } $this->content = vfsStream::newFile($names['basename'])->at($dir); return true; }
/** * @test * @group issue_28 * @expectedException PHPUnit_Framework_Error * @expectedExceptionMessage mkdir(): Path vfs://root/test.txt exists */ public function mkDirShouldNotOverwriteExistingFilesAndTriggerE_USER_WARNING() { $root = vfsStream::setup('root'); vfsStream::newFile('test.txt')->at($root); $this->assertFalse(mkdir(vfsStream::url('root/test.txt'))); }