protected function setUp() { CMTest_TH::createLanguage(); $this->_configInternalFile = new CM_File(DIR_ROOT . 'resources/config/js/internal.js'); $this->_configInternalFile->ensureParentDirectory(); $this->_configInternalFile->write('console.log("hello world")'); }
/** * @param int|null $deployVersion */ public function setDeployVersion($deployVersion = null) { $deployVersion = null !== $deployVersion ? (int) $deployVersion : time(); $sourceCode = join(PHP_EOL, array('<?php', 'return function (CM_Config_Node $config) {', ' $config->deployVersion = ' . $deployVersion . ';', '};', '')); $targetPath = DIR_ROOT . 'resources/config/deploy.php'; $configFile = new CM_File($targetPath); $configFile->ensureParentDirectory(); $configFile->write($sourceCode); }
/** * @param string $path * @param string|null $formatMessage * @param string|null $formatDate * @param int|null $minLevel * @return CM_Log_Handler_Stream */ public function createFileHandler($path, $formatMessage = null, $formatDate = null, $minLevel = null) { $path = (string) $path; $formatMessage = null !== $formatMessage ? (string) $formatMessage : $formatMessage; $formatDate = null !== $formatDate ? (string) $formatDate : $formatDate; $filesystem = $this->getServiceManager()->getFilesystems()->getData(); $file = new CM_File($path, $filesystem); $file->ensureParentDirectory(); $stream = new CM_OutputStream_File($file); $formatter = new CM_Log_Formatter_Text($formatMessage, $formatDate); return $this->_createStreamHandler($stream, $formatter, $minLevel); }
/** * @param CM_File_Filesystem $filesystem */ protected function _fillFilesystemWithRandomFiles(CM_File_Filesystem $filesystem) { $faker = Faker\Factory::create(); for ($i = 0; $i < 20; $i++) { $directory = $faker->lexify('????????' . $i); for ($j = 0; $j < 10; $j++) { $path = $faker->lexify('????????' . $j); $content = $faker->paragraph(10); $file = new CM_File($directory . '/' . $path, $filesystem); $file->ensureParentDirectory(); $file->write($content); } } }
public function testFetchDescriptionKeywordsConsiderNamespaceWideLocation() { $dirTmp = CM_Bootloader::getInstance()->getDirTmp(); $render = $this->getMockBuilder('CM_Frontend_Render')->setMethods(array('getTemplatePath', 'getLayoutPath'))->getMock(); $render->expects($this->any())->method('getTemplatePath')->will($this->returnValue(null)); $render->expects($this->exactly(2))->method('getLayoutPath')->will($this->returnCallback(function ($templateName) use($dirTmp) { $templateFile = new CM_File($dirTmp . $templateName); $templateFile->ensureParentDirectory(); $templateFile->write('test-' . $templateName); return $templateFile->getPath(); })); /** @var CM_Frontend_Render $render */ $page = $this->getMockBuilder('CM_Page_Abstract')->getMockForAbstractClass(); /** @var CM_Page_Abstract $page */ $renderAdapter = new CM_RenderAdapter_Page($render, $page); $this->assertSame('test-Page/Abstract/meta-description.tpl', $renderAdapter->fetchDescription()); $this->assertSame('test-Page/Abstract/meta-keywords.tpl', $renderAdapter->fetchKeywords()); }
public function testDeleteByPrefix() { $filesystem = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local()); $dirTmp = CM_Bootloader::getInstance()->getDirTmp(); $pathList = array('foo/foobar/bar', 'foo/bar2', 'foo/bar'); /** @var CM_File[] $fileList */ $fileList = array(); foreach ($pathList as $path) { $file = new CM_File($dirTmp . $path, $filesystem); $file->ensureParentDirectory(); $file->write('hello'); $fileList[] = $file; $fileList[] = $file->getParentDirectory(); } foreach ($fileList as $file) { $this->assertTrue($file->exists()); } $filesystem->deleteByPrefix($dirTmp); foreach ($fileList as $file) { $this->assertFalse($file->exists()); } $this->assertTrue((new CM_File($dirTmp))->exists()); }
public function generateConfigInternal() { $indentation = ' '; $indent = function ($content) use($indentation) { return preg_replace('/(:?^|[\\n])/', '$1' . $indentation, $content); }; $generator = new CM_Config_Generator(); $classTypesConfig = $generator->getConfigClassTypes()->exportAsString('$config'); $actionVerbsConfig = $generator->getConfigActionVerbs()->exportAsString('$config'); foreach ($generator->getClassTypesRemoved() as $classRemoved) { $this->_getStreamOutput()->writeln('Removed `' . $classRemoved . '`'); } foreach ($generator->getClassTypesAdded() as $type => $classAdded) { $this->_getStreamOutput()->writeln('Added `' . $classAdded . '` with type `' . $type . '`'); } // Create model class types and action verbs config PHP $configPhp = new CM_File(DIR_ROOT . 'resources/config/internal.php'); $configPhp->ensureParentDirectory(); $configPhp->truncate(); $configPhp->appendLine('<?php'); $configPhp->appendLine('// This is autogenerated config file. You should not change it manually.'); $configPhp->appendLine(); $configPhp->appendLine('return function (CM_Config_Node $config) {'); $configPhp->appendLine($indent($classTypesConfig)); $configPhp->appendLine($indent($actionVerbsConfig)); $configPhp->appendLine('};'); $this->_getStreamOutput()->writeln('Created `' . $configPhp->getPath() . '`'); // Create model class types and action verbs config JS $configJs = new CM_File(DIR_ROOT . 'resources/config/js/internal.js'); $configJs->ensureParentDirectory(); $configJs->truncate(); $classTypes = $generator->getNamespaceTypes(); $configJs->appendLine('cm.model.types = ' . CM_Util::jsonEncode(array_flip($classTypes['CM_Model_Abstract']), true) . ';'); $configJs->appendLine('cm.action.types = ' . CM_Util::jsonEncode(array_flip($classTypes['CM_Action_Abstract']), true) . ';'); $this->_getStreamOutput()->writeln('Created `' . $configJs->getPath() . '`'); }
public function testListByPrefixDoNotFollowSymlinks() { $filesystem = new CM_File_Filesystem($this->_adapter); $file = new CM_File('foo/bar/foo', $filesystem); $file->ensureParentDirectory(); $file->write('hello'); symlink($filesystem->getAdapter()->getPathPrefix() . '/foo', $filesystem->getAdapter()->getPathPrefix() . '/link'); $this->assertSame(array('files' => array('foo/bar/foo'), 'dirs' => array('foo/bar', 'foo', 'link')), $this->_adapter->listByPrefix('')); }
/** * @throws CM_Exception_Invalid * @return CM_File */ private function _getFile() { $file = new CM_File('svm/' . $this->getId() . '.svm', $this->_getFilesystem()); $file->ensureParentDirectory(); return $file; }