|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ComposerRequireCheckerTest\DependencyGuesser; |
|
4
|
|
|
|
|
5
|
|
|
use ComposerRequireChecker\Cli\Options; |
|
6
|
|
|
use ComposerRequireChecker\DependencyGuesser\DependencyGuesser; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
final class DependencyGuesserTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var DependencyGuesser |
|
14
|
|
|
*/ |
|
15
|
|
|
private $guesser; |
|
16
|
|
|
|
|
17
|
|
|
protected function setUp(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$options = new Options([ |
|
20
|
|
|
'autoloader-path' => dirname(__DIR__, 3) . '/vendor/autoload.php' |
|
21
|
|
|
]); |
|
22
|
|
|
$this->guesser = new DependencyGuesser($options); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testGuessExtJson(): void |
|
26
|
|
|
{ |
|
27
|
|
|
if (!extension_loaded('json')) { |
|
28
|
|
|
$this->markTestSkipped('extension json is not available'); |
|
29
|
|
|
} |
|
30
|
|
|
$result = $this->guesser->__invoke('json_decode'); |
|
31
|
|
|
$this->assertNotEmpty($result); |
|
32
|
|
|
$this->assertContains('ext-json', $result); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testDoesNotSuggestAnything(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$result = $this->guesser->__invoke('an_hopefully_unique_unknown_symbol'); |
|
38
|
|
|
$this->assertFalse($result->valid()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testCoreExtensionsResolvesToPHP(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$options = new Options(['php-core-extensions' => ['SPL', 'something-else']]); |
|
44
|
|
|
$this->guesser = new DependencyGuesser($options); |
|
45
|
|
|
$result = $this->guesser->__invoke('RecursiveDirectoryIterator'); |
|
46
|
|
|
$this->assertNotEmpty($result); |
|
47
|
|
|
$this->assertContains('php', $result); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testSymbolAutoloadedByComposerResolvesToPackageName(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$result = $this->guesser->__invoke('\PHPUnit\Framework\TestCase'); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertNotEmpty($result); |
|
55
|
|
|
$this->assertContains('phpunit/phpunit', $result); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|