Пример #1
0
 /**
  * @param bool $fallbackToSass
  * @param string $expected
  * @dataProvider dataCleanCss
  */
 public function testCleanCss($fallbackToSass, $expected)
 {
     if ($fallbackToSass) {
         Fusion\Process::$paths['cleancss'] = 'gilquebvalkjsdn';
     }
     $file = Fusion::file('style.css', __DIR__ . '/fixtures');
     $compressed = $file->compressed();
     $this->assertContains($expected, $compressed);
 }
Пример #2
0
 /**
  * @param null|array $ancestors Used internally to prevent circular dependency
  * @throws \Hx\Fusion\Exceptions\CircularDependency
  * @throws \Hx\Fusion\Exceptions\MissingDependency
  * @return AssetCollection
  */
 public function dependencies($ancestors = [])
 {
     /**
      * @type \Hx\Fusion\Asset|self $this
      */
     foreach ($ancestors as $d) {
         if ($d === $this) {
             throw new Exceptions\CircularDependency(array_map(function (Fusion\Asset $x) {
                 return $x->path();
             }, $ancestors));
         }
     }
     static $commentPattern = '`^\\s*(/\\*[\\s\\S]*?\\*/|(\\s*(//|#).*(\\s+|$))+)`';
     static $requirePattern = '`^\\s*(?:\\*|//|#)=\\s*(require|require_glob)\\s+(.+?)\\s*$`';
     if ($this->dependencies === null) {
         $this->dependencies = new AssetCollection();
         $paths = [];
         if (preg_match($commentPattern, $this->raw(), $commentsMatch)) {
             $lines = preg_split('`[\\r\\n]+`', $commentsMatch[1]);
             foreach ($lines as $line) {
                 if ($line && preg_match($requirePattern, $line, $matches)) {
                     switch ($matches[1]) {
                         case 'require':
                             $paths[] = dirname($this->absolutePath()) . DIRECTORY_SEPARATOR . $matches[2];
                             break;
                         case 'require_glob':
                             $paths = array_merge($paths, array_filter(glob(dirname($this->absolutePath()) . DIRECTORY_SEPARATOR . $matches[2], GLOB_MARK), function ($path) {
                                 return substr($path, -1) !== '/';
                             }));
                     }
                 }
             }
         }
         $baseDirLength = strlen($this->baseDir()) + 1;
         $ancestorsAndSelf = array_merge($ancestors, [$this]);
         foreach (array_unique($paths) as $i) {
             // If the file has no extension, use the requiring file's extension
             if (preg_match('`(/|^)[^.]+$`', $i)) {
                 $i .= '.' . $this->extension();
             }
             if (is_file($i)) {
                 $i = realpath($i);
                 $file = Fusion::file(substr($i, $baseDirLength), $this->baseDir());
                 foreach ($file->dependencies($ancestorsAndSelf) as $d) {
                     $this->dependencies[] = $d;
                 }
                 $this->dependencies[] = $file;
             } else {
                 throw new Fusion\Exceptions\MissingDependency($this, substr($i, $baseDirLength));
             }
         }
     }
     return $this->dependencies;
 }
Пример #3
0
 public function testTypeMismatch()
 {
     $this->setExpectedException('Hx\\Fusion\\Exceptions\\MixedTypes');
     $glob = Fusion::glob('*', __DIR__ . '/fixtures');
     $glob->raw();
 }
Пример #4
0
 public function testMissingDependency()
 {
     $this->setExpectedException('Hx\\Fusion\\Exceptions\\MissingDependency');
     Fusion::file(__DIR__ . '/fixtures/bad/missing_dependency.js')->dependenciesAndSelf()->filtered();
 }
Пример #5
0
 public function testExtensionlessDependency()
 {
     $file = Fusion::file('extensionless_dependency.js', __DIR__ . '/fixtures');
     $filtered = $file->dependenciesAndSelf()->filtered();
     $this->assertContains('alert', $filtered);
 }
Пример #6
0
 public function testDependencies()
 {
     $file = Fusion::file('has_dependencies.coffee', __DIR__ . '/fixtures');
     $this->assertCount(4, $file->dependencies());
 }