ViewCompilerEngineTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Illuminate\Tests\View;
  3. use Illuminate\Filesystem\Filesystem;
  4. use Illuminate\View\Compilers\CompilerInterface;
  5. use Illuminate\View\Engines\CompilerEngine;
  6. use Mockery as m;
  7. use PHPUnit\Framework\TestCase;
  8. class ViewCompilerEngineTest extends TestCase
  9. {
  10. protected function tearDown(): void
  11. {
  12. m::close();
  13. }
  14. public function testViewsMayBeRecompiledAndRendered()
  15. {
  16. $engine = $this->getEngine();
  17. $engine->getCompiler()->shouldReceive('getCompiledPath')->with(__DIR__.'/fixtures/foo.php')->andReturn(__DIR__.'/fixtures/basic.php');
  18. $engine->getCompiler()->shouldReceive('isExpired')->once()->with(__DIR__.'/fixtures/foo.php')->andReturn(true);
  19. $engine->getCompiler()->shouldReceive('compile')->once()->with(__DIR__.'/fixtures/foo.php');
  20. $results = $engine->get(__DIR__.'/fixtures/foo.php');
  21. $this->assertSame('Hello World
  22. ', $results);
  23. }
  24. public function testViewsAreNotRecompiledIfTheyAreNotExpired()
  25. {
  26. $engine = $this->getEngine();
  27. $engine->getCompiler()->shouldReceive('getCompiledPath')->with(__DIR__.'/fixtures/foo.php')->andReturn(__DIR__.'/fixtures/basic.php');
  28. $engine->getCompiler()->shouldReceive('isExpired')->once()->andReturn(false);
  29. $engine->getCompiler()->shouldReceive('compile')->never();
  30. $results = $engine->get(__DIR__.'/fixtures/foo.php');
  31. $this->assertSame('Hello World
  32. ', $results);
  33. }
  34. protected function getEngine()
  35. {
  36. return new CompilerEngine(m::mock(CompilerInterface::class), new Filesystem);
  37. }
  38. }