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') |
|
|
|
|
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
|
|
|
|
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.