packages/requirements/tests/Unit/Config/BootstrapTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Config;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use Requirements\Config\Bootstrap;
11use Requirements\Input\InvalidInputException;
12use Tests\Fake\ProjectDirectory;
13
14#[CoversClass(Bootstrap::class)]
15#[Small]
16final class BootstrapTest extends TestCase
17{
18    public function testLoadIncludesFile(): void
19    {
20        $project = new ProjectDirectory();
21        $file = $project->put('bootstrap.php', "<?php\nfile_put_contents(__DIR__ . '/loaded.txt', 'loaded;', FILE_APPEND);\n");
22        (new Bootstrap())->load($file);
23        self::assertSame('loaded;', $project->read('loaded.txt'));
24    }
25
26    public function testLoadIncludesFileOnce(): void
27    {
28        $project = new ProjectDirectory();
29        $file = $project->put('bootstrap.php', "<?php\nfile_put_contents(__DIR__ . '/loaded.txt', 'loaded;', FILE_APPEND);\n");
30        $bootstrap = new Bootstrap();
31        $bootstrap->load($file);
32        $bootstrap->load($file);
33        (new Bootstrap())->load($file);
34        self::assertSame('loaded;', $project->read('loaded.txt'));
35    }
36
37    public function testLoadRejectsMissingFile(): void
38    {
39        $project = new ProjectDirectory();
40        $this->expectException(InvalidInputException::class);
41        $this->expectExceptionMessage('Bootstrap does not exist: ' . $project->path('missing.php'));
42        (new Bootstrap())->load($project->path('missing.php'));
43    }
44
45    public function testLoadRejectsDirectory(): void
46    {
47        $project = new ProjectDirectory();
48        $this->expectException(InvalidInputException::class);
49        $this->expectExceptionMessage('Bootstrap does not exist: ' . $project->directory);
50        (new Bootstrap())->load($project->directory);
51    }
52}
53