Completed
Push — master ( 079b09...695e78 )
by Matthias
04:27 queued 02:17
created

testCoreExtensionsIn64Bit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ComposerRequireCheckerTest\DefinedExtensionsResolver;
4
5
use ComposerRequireChecker\DefinedExtensionsResolver\DefinedExtensionsResolver;
6
use org\bovigo\vfs\vfsStream;
7
use org\bovigo\vfs\vfsStreamDirectory;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * @covers \ComposerRequireChecker\DefinedExtensionsResolver\DefinedExtensionsResolver
12
 */
13
class DefinedExtensionsResolverTest extends TestCase
14
{
15
    /** @var DefinedExtensionsResolver */
16
    private $resolver;
17
    /** @var vfsStreamDirectory */
18
    private $root;
19
20
    protected function setUp()
21
    {
22
        parent::setUp();
23
24
        $this->resolver = new DefinedExtensionsResolver();
25
        $this->root = vfsStream::setup();
26
    }
27
28
    public function testNoExtensions()
29
    {
30
        $composerJson = vfsStream::newFile('composer.json')->at($this->root)->setContent('{}')->url();
31
32
        $extensions = ($this->resolver)($composerJson);
33
34
        $this->assertCount(0, $extensions);
35
    }
36
37
    public function testCoreExtensions()
38
    {
39
        $composerJson = vfsStream::newFile('composer.json')->at($this->root)
40
            ->setContent('{"require":{"php":"^7.0"}}')
41
            ->url();
42
43
        $extensions = ($this->resolver)($composerJson, ['ext-foo' => '*']);
44
45
        $this->assertCount(1, $extensions);
46
        $this->assertSame('*', reset($extensions));
0 ignored issues
show
Bug introduced by
It seems like $extensions can also be of type Countable and Traversable; however, parameter $array of reset() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $this->assertSame('*', reset(/** @scrutinizer ignore-type */ $extensions));
Loading history...
47
    }
48
49
    public function testCoreExtensionsIn64Bit()
50
    {
51
        $composerJson = vfsStream::newFile('composer.json')->at($this->root)
52
            ->setContent('{"require":{"php-64bit":"^7.0"}}')
53
            ->url();
54
55
        $extensions = ($this->resolver)($composerJson, ['ext-foo' => '*']);
56
57
        $this->assertCount(1, $extensions);
58
        $this->assertSame('*', reset($extensions));
0 ignored issues
show
Bug introduced by
It seems like $extensions can also be of type Countable and Traversable; however, parameter $array of reset() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

58
        $this->assertSame('*', reset(/** @scrutinizer ignore-type */ $extensions));
Loading history...
59
    }
60
61
    public function testExtensionsAreReturned()
62
    {
63
        $composerJson = vfsStream::newFile('composer.json')->at($this->root)
64
            ->setContent('{"require":{"ext-zip":"*","ext-curl":"*"}}')
65
            ->url();
66
67
        $extensions = ($this->resolver)($composerJson);
68
69
        $this->assertCount(2, $extensions);
70
        $this->assertContains('zip', $extensions);
71
        $this->assertContains('curl', $extensions);
72
    }
73
}
74