1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpSpellcheck\Tests\Source; |
6
|
|
|
|
7
|
|
|
use PhpSpellcheck\Source\MultiSource; |
8
|
|
|
use PhpSpellcheck\Source\SourceInterface; |
9
|
|
|
use PhpSpellcheck\TextInterface; |
10
|
|
|
use PhpSpellcheck\Utils\TextEncoding; |
11
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class MultiSourceTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testToTexts(): void |
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 MultiSource( |
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
|
|
|
/** |
41
|
|
|
* @return MockObject|TextInterface |
42
|
|
|
*/ |
43
|
|
|
private function generateMockText(string $content, array $context = []): MockObject |
44
|
|
|
{ |
45
|
|
|
$textMock = $this->createMock(TextInterface::class); |
46
|
|
|
$textMock->method('getContext') |
47
|
|
|
->willReturn($context); |
48
|
|
|
$textMock->method('getEncoding') |
49
|
|
|
->willReturn(TextEncoding::UTF8); |
50
|
|
|
$textMock->method('getContent') |
51
|
|
|
->willReturn($content); |
52
|
|
|
|
53
|
|
|
return $textMock; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return MockObject|SourceInterface |
58
|
|
|
*/ |
59
|
|
|
private function generateMockSource(array $texts): MockObject |
60
|
|
|
{ |
61
|
|
|
$sourceMock = $this->createMock(SourceInterface::class); |
62
|
|
|
$sourceMock->expects($this->once()) |
63
|
|
|
->method('toTexts') |
64
|
|
|
->willReturn($texts); |
65
|
|
|
|
66
|
|
|
return $sourceMock; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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.