Completed
Pull Request — master (#162)
by Guillaume
12:17 queued 03:27
created

DependencyGuesserTest::testGuessExtJson()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace ComposerRequireCheckerTest\DependencyGuesser;
4
5
use ComposerRequireChecker\Cli\Options;
6
use ComposerRequireChecker\DependencyGuesser\DependencyGuesser;
7
use ComposerRequireChecker\DependencyGuesser\GuesserInterface;
8
use PhpParser\Node\Expr\ArrayItem;
9
use PHPUnit\Framework\TestCase;
10
use Symfony\Component\Console\Input\ArrayInput;
11
12
final class DependencyGuesserTest extends TestCase
13
{
14
15
    /**
16
     * @var DependencyGuesser
17
     */
18
    private $guesser;
19
20
    protected function setUp(): void
21
    {
22
        $this->guesser = new DependencyGuesser();
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 testUseAddedGuesser(): void
51
    {
52
        $additionalGuesser = $this->createStub(GuesserInterface::class);
53
        $additionalGuesser->method('__invoke')
54
            ->willReturnCallback(function (): \Generator {
55
                yield 'additional-guesser-result';
56
            });
57
        $this->guesser->addGuesser($additionalGuesser);
58
        $result = $this->guesser->__invoke('some_symbol');
59
        $this->assertNotEmpty($result);
60
        $this->assertContains('additional-guesser-result', $result);
61
    }
62
}
63