Code Duplication    Length = 19-21 lines in 2 locations

tests/Suggest/PhraseTest.php 2 locations

@@ 51-69 (lines=19) @@
48
    /**
49
     * @group functional
50
     */
51
    public function testPhraseSuggest(): void
52
    {
53
        $suggest = new Suggest();
54
        $phraseSuggest = new Phrase('suggest1', 'text');
55
        $phraseSuggest->setText('elasticsearch is bansai coor');
56
        $phraseSuggest->setAnalyzer('simple')->setHighlight('<suggest>', '</suggest>')->setStupidBackoffSmoothing(0.4);
57
        $phraseSuggest->addDirectGenerator(new DirectGenerator('text'));
58
        $suggest->addSuggestion($phraseSuggest);
59
60
        $index = $this->_getIndexForTest();
61
        $result = $index->search($suggest);
62
        $suggests = $result->getSuggests();
63
64
        // 3 suggestions should be returned: One in which both misspellings are corrected, and two in which only one misspelling is corrected.
65
        $this->assertCount(3, $suggests['suggest1'][0]['options']);
66
67
        $this->assertEquals('elasticsearch is <suggest>bonsai cool</suggest>', $suggests['suggest1'][0]['options'][0]['highlighted']);
68
        $this->assertEquals('elasticsearch is bonsai cool', $suggests['suggest1'][0]['options'][0]['text']);
69
    }
70
71
    /**
72
     * @group functional
@@ 76-96 (lines=21) @@
73
     *
74
     * @group legacy
75
     */
76
    public function testPhraseSuggestWithBackwardsCompatibility(): void
77
    {
78
        $suggest = new Suggest();
79
        $phraseSuggest = new Phrase('suggest1', 'text');
80
        $phraseSuggest->setText('elasticsearch is bansai coor');
81
        $phraseSuggest->setAnalyzer('simple')->setHighlight('<suggest>', '</suggest>')->setStupidBackoffSmoothing(0.4);
82
83
        $this->expectDeprecation('Since ruflin/elastica 7.2.0: The "Elastica\Suggest\Phrase::addCandidateGenerator()" method is deprecated, use the "addDirectGenerator()" method instead. It will be removed in 8.0.');
84
        $phraseSuggest->addCandidateGenerator(new DirectGenerator('text'));
85
        $suggest->addSuggestion($phraseSuggest);
86
87
        $index = $this->_getIndexForTest();
88
        $result = $index->search($suggest);
89
        $suggests = $result->getSuggests();
90
91
        // 3 suggestions should be returned: One in which both misspellings are corrected, and two in which only one misspelling is corrected.
92
        $this->assertCount(3, $suggests['suggest1'][0]['options']);
93
94
        $this->assertEquals('elasticsearch is <suggest>bonsai cool</suggest>', $suggests['suggest1'][0]['options'][0]['highlighted']);
95
        $this->assertEquals('elasticsearch is bonsai cool', $suggests['suggest1'][0]['options'][0]['text']);
96
    }
97
98
    protected function _getIndexForTest(): Index
99
    {