public function testIsFreshResource1ForBundle2IsNotUpToDate() { $bundle1 = new TestBundle1(); $bundle2 = new TestBundle2(); $resourceLoader1 = $this->getMock('Oro\\Component\\Config\\Loader\\CumulativeResourceLoader'); $resourceLoader2 = $this->getMock('Oro\\Component\\Config\\Loader\\CumulativeResourceLoader'); $resource = new CumulativeResource('test', new CumulativeResourceLoaderCollection([$resourceLoader1, $resourceLoader2])); $resourceLoader1->expects($this->exactly(2))->method('isResourceFresh')->will($this->onConsecutiveCalls(true, false)); $resourceLoader2->expects($this->once())->method('isResourceFresh')->will($this->onConsecutiveCalls(true)); CumulativeResourceManager::getInstance()->clear()->setBundles(['TestBundle1' => get_class($bundle1), 'TestBundle2' => get_class($bundle2)]); $this->assertFalse($resource->isFresh(100)); }
public function testRegisterFoundResource() { $relativeFilePath = 'Resources/config/test.yml'; $bundle = new TestBundle1(); $bundleClass = get_class($bundle); $bundleDir = dirname((new \ReflectionClass($bundle))->getFileName()); $loader = $this->createLoader($relativeFilePath); $resource = new CumulativeResource('test_group', new CumulativeResourceLoaderCollection()); $loader->registerFoundResource($bundleClass, $bundleDir, '', $resource); $expectedResource = new CumulativeResource('test_group', new CumulativeResourceLoaderCollection()); $expectedResource->addFound($bundleClass, str_replace('/', DIRECTORY_SEPARATOR, $bundleDir . '/' . $relativeFilePath)); $this->assertEquals($expectedResource, $resource); }
/** * {@inheritdoc} */ public function isResourceFresh($bundleClass, $bundleDir, CumulativeResource $resource, $timestamp) { // check exist and removed resources $found = $resource->getFound($bundleClass); foreach ($found as $path) { if (!is_file($path) || filemtime($path) >= $timestamp) { return false; } } // check new resources $finder = $this->getFileFinder($bundleDir); if ($finder) { /** @var \SplFileInfo $file */ foreach ($finder as $file) { $path = $file->getRealPath(); if (!$resource->isFound($bundleClass, $path)) { return false; } } } return true; }
/** * {@inheritdoc} */ public function isResourceFresh($bundleClass, $bundleDir, $bundleAppDir, CumulativeResource $resource, $timestamp) { if (is_dir($bundleAppDir)) { $path = $bundleAppDir . preg_replace('/Resources\\//', '', $this->relativeFilePath, 1); if ($resource->isFound($bundleClass, $path)) { // check exists and removed resource return is_file($path) && filemtime($path) < $timestamp; } // check new resource if (is_file($path)) { return false; } } $path = $bundleDir . $this->relativeFilePath; if ($resource->isFound($bundleClass, $path)) { // check exists and removed resource return is_file($path) && filemtime($path) < $timestamp; } // check new resource return !is_file($path); }
public function testLoad() { $resourceRelativePath = 'Resources/config/test.yml'; $bundle = new TestBundle1(); $bundleDir = dirname((new \ReflectionClass($bundle))->getFileName()); $resourceLoader = new YamlCumulativeFileLoader($resourceRelativePath); CumulativeResourceManager::getInstance()->clear()->setBundles(['TestBundle1' => get_class($bundle)]); $container = new ContainerBuilder(); $loader = new CumulativeConfigLoader('test', $resourceLoader); $result = $loader->load($container); $this->assertEquals([new CumulativeResourceInfo(get_class($bundle), 'test', str_replace('/', DIRECTORY_SEPARATOR, $bundleDir . '/' . $resourceRelativePath), ['test' => 123])], $result); $expectedResource = new CumulativeResource('test', new CumulativeResourceLoaderCollection([$resourceLoader])); $expectedResource->addFound(get_class($bundle), str_replace('/', DIRECTORY_SEPARATOR, $bundleDir . '/Resources/config/test.yml')); $this->assertCount(1, $container->getResources()); $this->assertEquals($expectedResource, $container->getResources()[0]); }
/** * {@inheritdoc} */ public function isResourceFresh($bundleClass, $bundleDir, CumulativeResource $resource, $timestamp) { $path = $bundleDir . $this->relativeFilePath; if ($resource->isFound($bundleClass, $path)) { // check exists and removed resource return is_file($path) && filemtime($path) < $timestamp; } else { // check new resource return !is_file($path); } }
/** * {@inheritdoc} */ public function isResourceFresh($bundleClass, $bundleDir, $bundleAppDir, CumulativeResource $resource, $timestamp) { $registeredFiles = $resource->getFound($bundleClass); $registeredFiles = array_flip($registeredFiles); // Check and remove data from $bundleAppDir resources directory if (is_dir($bundleAppDir)) { $dir = $this->getResourcesDirectoryAbsolutePath($bundleAppDir); $realPath = realpath($dir); if (is_dir($realPath)) { $currentContents = $this->getDirectoryContentsArray($realPath); foreach ($currentContents as $filename) { if (!$resource->isFound($bundleClass, $filename)) { return false; } unset($registeredFiles[$filename]); } } } // Check and remove data from $bundleDir resources directory $dir = $this->getDirectoryAbsolutePath($bundleDir); $realPath = realpath($dir); if (is_dir($realPath)) { $currentContents = $this->getDirectoryContentsArray($realPath); foreach ($currentContents as $filename) { if (!$resource->isFound($bundleClass, $filename)) { return false; } unset($registeredFiles[$filename]); } } // case when entire dir was removed or some file was removed if (!empty($registeredFiles)) { return false; } return true; }