Failed Conditions
Pull Request — master (#162)
by Guillaume
10:02
created

DependencyGuesserTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
eloc 23
c 4
b 0
f 0
dl 0
loc 49
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCoreExtensionsResolvesToPHP() 0 7 1
A testGuessExtJson() 0 8 2
A testDoesNotSuggestAnything() 0 4 1
A setUp() 0 3 1
A testUseAddedGuesser() 0 11 1
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