|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Docker\Tests\Endpoint; |
| 6 | + |
| 7 | +use Docker\Endpoint\ImageBuild; |
| 8 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; |
| 11 | + |
| 12 | +class ImageBuildTest extends TestCase |
| 13 | +{ |
| 14 | + public static function tagProvider(): iterable |
| 15 | + { |
| 16 | + yield 'single tag' => ['app:latest', ['t=app%3Alatest']]; |
| 17 | + yield 'several tags' => [['app:latest', 'app:1.0'], ['t=app%3Alatest', 't=app%3A1.0']]; |
| 18 | + yield 'keyed tags' => [['a' => 'app:latest', 'b' => 'app:1.0'], ['t=app%3Alatest', 't=app%3A1.0']]; |
| 19 | + yield 'no tags' => [[], []]; |
| 20 | + } |
| 21 | + |
| 22 | + #[DataProvider('tagProvider')] |
| 23 | + public function testRepeatsTagParameter(string|array $tags, array $expected): void |
| 24 | + { |
| 25 | + $query = (new ImageBuild(null, ['t' => $tags]))->getQueryString(); |
| 26 | + $parameters = explode('&', $query); |
| 27 | + |
| 28 | + $this->assertSame($expected, array_values(array_filter($parameters, static fn (string $pair): bool => str_starts_with($pair, 't=')))); |
| 29 | + $this->assertContains('dockerfile=Dockerfile', $parameters); |
| 30 | + } |
| 31 | + |
| 32 | + public function testRejectsNonStringTags(): void |
| 33 | + { |
| 34 | + $this->expectException(InvalidOptionsException::class); |
| 35 | + |
| 36 | + (new ImageBuild(null, ['t' => ['app:latest', 1]]))->getQueryString(); |
| 37 | + } |
| 38 | +} |
0 commit comments