|
10 | 10 |
|
11 | 11 | final class PatchFileFactoryTest extends AbstractTestCase
|
12 | 12 | {
|
13 |
| - public function test(): void |
| 13 | + private const FIXTURE_PATH = __DIR__ . DIRECTORY_SEPARATOR . 'Fixture'; |
| 14 | + |
| 15 | + private const NESTED_OUTPUT_PATH = 'path' . DIRECTORY_SEPARATOR . 'to' . DIRECTORY_SEPARATOR . 'patches'; |
| 16 | + |
| 17 | + public function testDefaultOutputPath(): void |
| 18 | + { |
| 19 | + $patchFilePath = $this->makePatchFilePath(); |
| 20 | + $expectedPath = PatchFileFactory::DEFAULT_OUTPUT_PATH . DIRECTORY_SEPARATOR . 'some-new-file-php.patch'; |
| 21 | + |
| 22 | + $this->assertSame($expectedPath, $patchFilePath); |
| 23 | + } |
| 24 | + |
| 25 | + public function testRelativeEnvironmentOutputPath(): void |
| 26 | + { |
| 27 | + $relativeOutputPath = self::NESTED_OUTPUT_PATH; |
| 28 | + $patchFilePath = $this->makePatchFilePathWithEnvironmentOutputPath($relativeOutputPath); |
| 29 | + $expectedPath = self::NESTED_OUTPUT_PATH . DIRECTORY_SEPARATOR . 'some-new-file-php.patch'; |
| 30 | + |
| 31 | + $this->assertSame($expectedPath, $patchFilePath); |
| 32 | + } |
| 33 | + |
| 34 | + public function testAbsoluteEnvironmentOutputPath(): void |
| 35 | + { |
| 36 | + $absoluteOutputPath = dirname(__FILE__, 3) . DIRECTORY_SEPARATOR . self::NESTED_OUTPUT_PATH; |
| 37 | + $patchFilePath = $this->makePatchFilePathWithEnvironmentOutputPath($absoluteOutputPath); |
| 38 | + $expectedPath = self::NESTED_OUTPUT_PATH . DIRECTORY_SEPARATOR . 'some-new-file-php.patch'; |
| 39 | + |
| 40 | + $this->assertSame($expectedPath, $patchFilePath); |
| 41 | + } |
| 42 | + |
| 43 | + private function makePatchFilePath(): string |
14 | 44 | {
|
15 | 45 | $patchFileFactory = $this->make(PatchFileFactory::class);
|
16 | 46 |
|
17 | 47 | $oldAndNewFile = new OldAndNewFile(
|
18 |
| - __DIR__ . '/Fixture/some_old_file.php', |
19 |
| - __DIR__ . '/Fixture/some_new_file.php', |
| 48 | + self::FIXTURE_PATH . DIRECTORY_SEPARATOR . 'some_old_file.php', |
| 49 | + self::FIXTURE_PATH . DIRECTORY_SEPARATOR . 'some_new_file.php', |
20 | 50 | 'package/name'
|
21 | 51 | );
|
22 | 52 |
|
23 |
| - $pathFilePath = $patchFileFactory->createPatchFilePath($oldAndNewFile, __DIR__ . '/Fixture'); |
24 |
| - $this->assertSame('patches/some-new-file-php.patch', $pathFilePath); |
| 53 | + return $patchFileFactory->createPatchFilePath($oldAndNewFile, self::FIXTURE_PATH); |
| 54 | + } |
| 55 | + |
| 56 | + private function makePatchFilePathWithEnvironmentOutputPath(string $environmentOutputPath): string |
| 57 | + { |
| 58 | + putenv(PatchFileFactory::OUTPUT_PATH_ENV_VAR . '=' . $environmentOutputPath); |
| 59 | + |
| 60 | + $patchFilePath = $this->makePatchFilePath(); |
| 61 | + |
| 62 | + putenv(PatchFileFactory::OUTPUT_PATH_ENV_VAR); // Unset |
| 63 | + |
| 64 | + return $patchFilePath; |
25 | 65 | }
|
26 | 66 | }
|
0 commit comments