-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComposerResolverTest.php
More file actions
76 lines (59 loc) · 2.12 KB
/
ComposerResolverTest.php
File metadata and controls
76 lines (59 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace KaririCode\Devkit\Tests\Unit\Core;
use KaririCode\Devkit\Core\ComposerResolver;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
#[CoversClass(ComposerResolver::class)]
final class ComposerResolverTest extends TestCase
{
#[Test]
public function resolveReturnsNonEmptyString(): void
{
$resolver = new ComposerResolver();
$result = $resolver->resolve();
$this->assertIsString($result);
$this->assertNotEmpty($result);
}
#[Test]
public function resolveDoesNotReturnShellFragment(): void
{
$resolver = new ComposerResolver();
$result = $resolver->resolve();
// Must be a single executable path — no shell fragments like "php /path/to/file"
// (a shell fragment would break proc_open's array invocation)
$this->assertStringNotContainsString(' ', ltrim($result, '/'));
}
#[Test]
public function resolveRespectsComposerBinaryEnvironmentVariable(): void
{
$originalEnv = getenv('COMPOSER_BINARY');
// Set env to a known executable
putenv('COMPOSER_BINARY=/usr/bin/env');
$resolver = new ComposerResolver();
$result = $resolver->resolve();
$this->assertSame('/usr/bin/env', $result);
// Restore
if (false === $originalEnv) {
putenv('COMPOSER_BINARY');
} else {
putenv('COMPOSER_BINARY=' . $originalEnv);
}
}
#[Test]
public function resolveIgnoresNonExecutableComposerBinaryEnvVar(): void
{
$originalEnv = getenv('COMPOSER_BINARY');
putenv('COMPOSER_BINARY=/non/existent/path/composer');
$resolver = new ComposerResolver();
$result = $resolver->resolve();
// Should fall through to PATH or fallback — not return the non-executable path
$this->assertNotSame('/non/existent/path/composer', $result);
if (false === $originalEnv) {
putenv('COMPOSER_BINARY');
} else {
putenv('COMPOSER_BINARY=' . $originalEnv);
}
}
}