public function testFinderPatternWithEndingWildCard() { $normalizer = new Normalizer($this->getCacheDir()); $locator = new Locator($normalizer); // finder pattern MUST return sources mkdir($this->getCacheDir() . '/finder'); touch($this->getCacheDir() . '/finder/first.css'); touch($this->getCacheDir() . '/finder/second.css'); touch($this->getCacheDir() . '/finder/third.js'); $sources = $locator->locate($this->getCacheDir() . '/finder/*'); $this->assertCount(3, $sources); $allowed = [$this->getCacheDir() . '/finder/first.css', $this->getCacheDir() . '/finder/second.css', $this->getCacheDir() . '/finder/third.js']; $this->assertContains($sources[0]->getRealPath(), $allowed); $this->assertContains($sources[1]->getRealPath(), $allowed); $this->assertContains($sources[2]->getRealPath(), $allowed); }
/** * Filter only the sources supported by the current filter. * * @param SplFileInfo[] $sources * @param FilterInterface $filter * @return array * @throws Exception */ protected function filterSources(array $sources, FilterInterface $filter) { $filteredSources = []; // if the filter supports no extension, there is an error if (!is_array($filter->getSupportedExtensions()) || !count($filter->getSupportedExtensions())) { throw new Exception('No supported extensions found for the filter ' . $filter->getName()); } foreach ($sources as $source) { $isExtensionSupported = in_array($source->getExtension(), $filter->getSupportedExtensions()); $supportAllExtensions = in_array('*', $filter->getSupportedExtensions()); if ($isExtensionSupported || $supportAllExtensions) { $filteredSources[] = $this->locator->getNormalizer()->normalize($source); } } return $filteredSources; }