|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace BlameButton\LaravelDockerBuilder\Tests\Traits; |
| 4 | + |
| 5 | +use BlameButton\LaravelDockerBuilder\Tests\TestCase; |
| 6 | +use BlameButton\LaravelDockerBuilder\Traits\InteractsWithTwig; |
| 7 | +use Twig\Environment; |
| 8 | +use Twig\Error\LoaderError; |
| 9 | +use Twig\Loader\FilesystemLoader; |
| 10 | + |
| 11 | +/** |
| 12 | + * @uses \BlameButton\LaravelDockerBuilder\DockerServiceProvider |
| 13 | + * @uses package_path() |
| 14 | + * |
| 15 | + * @covers \BlameButton\LaravelDockerBuilder\Traits\InteractsWithTwig |
| 16 | + */ |
| 17 | +class InteractsWithTwigTest extends TestCase |
| 18 | +{ |
| 19 | + public function testItCreatesTwig(): void |
| 20 | + { |
| 21 | + /** @var InteractsWithTwig $class */ |
| 22 | + $class = $this->getObjectForTrait(InteractsWithTwig::class); |
| 23 | + |
| 24 | + $twig = $class->twig(); |
| 25 | + self::assertInstanceOf(Environment::class, $twig); |
| 26 | + $loader = $twig->getLoader(); |
| 27 | + self::assertInstanceOf(FilesystemLoader::class, $loader); |
| 28 | + self::assertEquals([package_path('docker/template')], $loader->getPaths()); |
| 29 | + } |
| 30 | + |
| 31 | + public function testItThrowsErrorOnMissingTemplates(): void |
| 32 | + { |
| 33 | + /** @var InteractsWithTwig $class */ |
| 34 | + $class = $this->getObjectForTrait(InteractsWithTwig::class); |
| 35 | + |
| 36 | + $this->expectException(LoaderError::class); |
| 37 | + |
| 38 | + $class->render('invalid-filename', []); |
| 39 | + } |
| 40 | + |
| 41 | + public function testItRendersNginxTemplate(): void |
| 42 | + { |
| 43 | + /** @var InteractsWithTwig $class */ |
| 44 | + $class = $this->getObjectForTrait(InteractsWithTwig::class); |
| 45 | + |
| 46 | + $output = $class->render('nginx.dockerfile.twig', []); |
| 47 | + |
| 48 | + self::assertStringContainsString('FROM nginx:1-alpine', $output); |
| 49 | + } |
| 50 | + |
| 51 | + public function testItRendersPhpTemplate(): void |
| 52 | + { |
| 53 | + /** @var InteractsWithTwig $class */ |
| 54 | + $class = $this->getObjectForTrait(InteractsWithTwig::class); |
| 55 | + |
| 56 | + $output = $class->render('php.dockerfile.twig', [ |
| 57 | + 'php_version' => '8.2', |
| 58 | + ]); |
| 59 | + |
| 60 | + self::assertStringContainsString('FROM php:8.2-fpm-alpine', $output); |
| 61 | + } |
| 62 | +} |
0 commit comments