WordFinderTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 48
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testThrowExceptionWhenApiIsThrowException() 0 8 1
A testSuccessfullyFindWord() 0 14 1
A testThrowExceptionWhenWordIsNotFound() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Tests\Crossword\Features\Constructor;
6
7
use App\Crossword\Features\Constructor\Dictionary\DictionaryWordDto;
8
use App\Crossword\Features\Constructor\Dictionary\Word;
9
use App\Crossword\Features\Constructor\Dictionary\WordSearchCriteria;
10
use App\Crossword\Features\Constructor\WordFinder;
11
use App\Crossword\Features\Constructor\WordFoundException;
12
use App\Crossword\Infrastructure\Adapter\Dictionary\InMemoryDictionaryAdapter;
13
use Psr\Log\NullLogger;
0 ignored issues
show
Bug introduced by
The type Psr\Log\NullLogger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use App\Tests\Crossword\CrosswordTestCase;
15
16
/**
17
 * @coversDefaultClass \App\Crossword\Features\Constructor\WordFinder
18
 */
19
final class WordFinderTest extends CrosswordTestCase
20
{
21
    /**
22
     * @covers ::search
23
     */
24
    public function testSuccessfullyFindWord(): void
25
    {
26
        $dictionaryWordDto = new DictionaryWordDto([
27
            'success' => true,
28
            'data' => [['word' => 'test', 'definition' => 'test test']]
29
        ]);
30
        $inMemoryDictionaryProvider = new InMemoryDictionaryAdapter(null, $dictionaryWordDto);
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type App\Crossword\Features\L...Adapter\Dictionary\null expected by parameter $languagesDto of App\Crossword\Infrastruc...yAdapter::__construct(). ( Ignorable by Annotation )

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

30
        $inMemoryDictionaryProvider = new InMemoryDictionaryAdapter(/** @scrutinizer ignore-type */ null, $dictionaryWordDto);
Loading history...
31
32
        $wordFinder = new WordFinder($inMemoryDictionaryProvider, new NullLogger());
33
        $word = $wordFinder->search(new WordSearchCriteria('en', '.*'));
34
35
        self::assertInstanceOf(Word::class, $word);
36
        self::assertSame($word->value(), 'test');
37
        self::assertSame($word->definition(), 'test test');
38
    }
39
40
    /**
41
     * @covers ::search
42
     */
43
    public function testThrowExceptionWhenWordIsNotFound(): void
44
    {
45
        $this->expectException(WordFoundException::class);
46
47
        $dictionaryWordDto = new DictionaryWordDto([
48
            'success' => false,
49
        ]);
50
        $inMemoryDictionaryProvider = new InMemoryDictionaryAdapter(null, $dictionaryWordDto);
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type App\Crossword\Features\L...Adapter\Dictionary\null expected by parameter $languagesDto of App\Crossword\Infrastruc...yAdapter::__construct(). ( Ignorable by Annotation )

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

50
        $inMemoryDictionaryProvider = new InMemoryDictionaryAdapter(/** @scrutinizer ignore-type */ null, $dictionaryWordDto);
Loading history...
51
52
        $wordFinder = new WordFinder($inMemoryDictionaryProvider, new NullLogger());
53
        $wordFinder->search(new WordSearchCriteria('en', '.*'));
54
    }
55
56
    /**
57
     * @covers ::search
58
     */
59
    public function testThrowExceptionWhenApiIsThrowException(): void
60
    {
61
        $this->expectException(WordFoundException::class);
62
63
        $inMemoryDictionaryProvider = new InMemoryDictionaryAdapter(null, null);
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type App\Crossword\Features\L...Adapter\Dictionary\null expected by parameter $languagesDto of App\Crossword\Infrastruc...yAdapter::__construct(). ( Ignorable by Annotation )

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

63
        $inMemoryDictionaryProvider = new InMemoryDictionaryAdapter(/** @scrutinizer ignore-type */ null, null);
Loading history...
Bug introduced by
null of type null is incompatible with the type App\Crossword\Features\C...Adapter\Dictionary\null expected by parameter $wordDto of App\Crossword\Infrastruc...yAdapter::__construct(). ( Ignorable by Annotation )

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

63
        $inMemoryDictionaryProvider = new InMemoryDictionaryAdapter(null, /** @scrutinizer ignore-type */ null);
Loading history...
64
65
        $wordFinder = new WordFinder($inMemoryDictionaryProvider, new NullLogger());
66
        $wordFinder->search(new WordSearchCriteria('en', '.*'));
67
    }
68
}
69