Failed Conditions
Push — master ( 01d6ae...9ca6d9 )
by Philippe
534:14 queued 469:10
created

MultipleSourceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateMockText() 0 11 1
A testToTexts() 0 22 1
A generateMockSource() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpSpellcheck\Tests\Source;
6
7
use PhpSpellcheck\Source\MultipleSource;
8
use PhpSpellcheck\Source\SourceInterface;
9
use PhpSpellcheck\TextInterface;
10
use PhpSpellcheck\Utils\TextEncoding;
11
use PHPUnit\Framework\TestCase;
12
13
class MultipleSourceTest extends TestCase
14
{
15
16
    public function testToTexts()
17
    {
18
        $mockText1 = $this->generateMockText('mispelling1', ['ctx' => null]);
19
        $mockText1AfterContextMerge = $this->generateMockText('mispelling1AfterMerge', ['ctx' => 'merged']);
20
        $mockText1->method('mergeContext')
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

20
        $mockText1->/** @scrutinizer ignore-call */ 
21
                    method('mergeContext')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
            ->willReturn($mockText1AfterContextMerge);
22
        $mockText2 = $this->generateMockText('mispelling2');
23
        $mockText2->method('mergeContext')
24
            ->willReturn($mockText2);
25
        $mockSource1 = $this->generateMockSource([$mockText1]);
26
        $mockSource2 = $this->generateMockSource([$mockText2]);
27
28
        $source = new MultipleSource(
29
            [
30
                $mockSource1,
31
                $mockSource2,
32
            ]
33
        );
34
35
        $expectedTexts = [$mockText1AfterContextMerge, $mockText2];
36
37
        $this->assertSame($expectedTexts, iterator_to_array($source->toTexts()));
38
    }
39
40
    private function generateMockText(string $content, array $context = [])
41
    {
42
        $textMock = $this->createMock(TextInterface::class);
43
        $textMock->method('getContext')
44
            ->willReturn($context);
45
        $textMock->method('getEncoding')
46
            ->willReturn(TextEncoding::UTF8);
47
        $textMock->method('getContent')
48
            ->willReturn($content);
49
50
        return $textMock;
51
    }
52
53
    private function generateMockSource(array $texts)
54
    {
55
        $sourceMock = $this->createMock(SourceInterface::class);
56
        $sourceMock->expects($this->once())
57
            ->method('toTexts')
58
            ->willReturn($texts);
59
60
        return $sourceMock;
61
    }
62
}
63