resolveResourcePath() public method

Find the full path to a requested resource, this can be bundle configurations like @BundleName/resource.twig
public resolveResourcePath ( string $path ) : string
$path string the path resolve
return string the full path to the requested resource or false if not found.
Exemplo n.º 1
0
 public function testTracker()
 {
     $profiler = new Profiler();
     $finder = $this->getMock(TemplateFinderInterface::class);
     $fixture_path = realpath(__DIR__ . '/../../Fixture');
     $temp_file = $fixture_path . '/Bundle/tempfile.txt';
     $temp_file2 = $fixture_path . '/Bundle/tempfile2.txt';
     $temp_file3 = $fixture_path . '/Bundle/tempfile3.txt';
     $tracker = new Tracker($profiler, $finder, $fixture_path . '/cache', $fixture_path, 'Resources', ['FooBundle' => $fixture_path . '/Bundle/FooBundle', 'BarBundle' => $fixture_path . '/Bundle/BarBundle']);
     touch($temp_file);
     $tracker->addPath($temp_file);
     $tracker->addPath($fixture_path . '/Bundle');
     $finder->expects($this->once())->method('findAllTemplates')->willReturn([new TemplateReference('dont_parse_me', 'php'), new TemplateReference('@FooBundle/foo.html.twig', 'twig'), new TemplateReference('@AcmeBundle/foo.html.twig', 'twig'), new TemplateReference('template.html.twig', 'twig'), new TemplateReference('i_dont_exist', 'twig')]);
     $this->assertEquals('/i/cant/be/resolved', $tracker->resolveResourcePath('/i/cant/be/resolved'));
     // Start by removing the cache file, if it exists.
     if (file_exists($fixture_path . '/cache/webpack.asset_tracker.cache')) {
         unlink($fixture_path . '/cache/webpack.asset_tracker.cache');
     }
     $this->assertTrue($tracker->isOutdated());
     // Start by rebuilding the cache
     $tracker->rebuild();
     // Since cache is fresh, isOutdated should return false.
     $this->assertFalse($tracker->isOutdated());
     // Modify something.
     touch($temp_file, time() + 1 + mt_rand(1, 100));
     $this->assertTrue($tracker->isOutdated());
     // Create something
     $tracker->rebuild();
     touch($temp_file2);
     $this->assertTrue($tracker->isOutdated());
     unlink($temp_file);
     unlink($temp_file2);
     touch($temp_file3);
     $this->assertTrue($tracker->isOutdated());
     $tracker->rebuild();
     touch($temp_file, time() + 10);
     $this->assertTrue($tracker->isOutdated());
     unlink($temp_file3);
 }
Exemplo n.º 2
0
 /**
  * test resloveResourcePath for a bundle path when bundle is found.
  */
 public function testResolveResourcePathBundle()
 {
     $profiler = new Profiler();
     $finder = $this->prophesize(TemplateFinderInterface::class);
     $tracker = new Tracker($profiler, $finder->reveal(), $this->root_dir, $this->asset_dir, $this->output_dir, ['BarBundle' => $this->root_dir . DIRECTORY_SEPARATOR . 'Bundle' . DIRECTORY_SEPARATOR . 'BarBundle']);
     self::assertEquals($this->root_dir . DIRECTORY_SEPARATOR . 'Bundle' . DIRECTORY_SEPARATOR . 'BarBundle' . DIRECTORY_SEPARATOR . $this->asset_dir, $tracker->resolveResourcePath('@BarBundle'));
 }