Passed
Push — master ( 3bddf7...37f0e3 )
by Max
07:30
created

BasicConfigTest::testDefaultDictionaryClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
declare(strict_types=1);
4
5
namespace EasyDictionary;
6
7
use EasyDictionary\DataProvider\Simple as SimpleDataProvider;
8
use EasyDictionary\Dictionary\Simple as SimpleDictionary;
9
use PHPUnit\Framework\TestCase;
10
use Psr\SimpleCache\CacheInterface;
11
12
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
13
 * @coversDefaultClass \EasyDictionary\BasicConfig
14
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
15
class BasicConfigTest extends TestCase
16
{
17
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
18
     * @covers \EasyDictionary\BasicConfig
19
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
20
    public function testClassExistence()
21
    {
22
        self::assertTrue(class_exists('\EasyDictionary\BasicConfig'));
23
    }
24
25
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
26
     * @covers ::getDefaultDataProviderClass
27
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
28
    public function testDefaultDataProviderClass()
29
    {
30
        $config = new BasicConfig();
31
32
        self::assertEquals(
33
            SimpleDataProvider::class,
34
            $config->getDefaultDataProviderClass()
35
        );
36
    }
37
38
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
39
     * @covers ::getDefaultDictionaryClass
40
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
41
    public function testDefaultDictionaryClass()
42
    {
43
        $config = new BasicConfig();
44
45
        self::assertEquals(
46
            SimpleDictionary::class,
47
            $config->getDefaultDictionaryClass()
48
        );
49
    }
50
51
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
52
     * @covers ::setDictionaryConfig
53
     * @covers ::getDictionaryConfig
54
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
55
    public function testSetGetConfig()
56
    {
57
        $dictionary = [
58
            'test' => []
59
        ];
60
61
        $config = new BasicConfig();
62
        $config->setDictionaryConfig($dictionary);
63
64
        self::assertEquals($dictionary, $config->getDictionaryConfig());
65
    }
66
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @covers ::setDefaultView
69
     * @covers ::getDefaultView
70
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
71
    public function testSetGetDefaultView()
72
    {
73
        $callable = function ($test) {
0 ignored issues
show
Unused Code introduced by
The parameter $test is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
        };
75
76
        $config = new BasicConfig();
77
        self::assertNull($config->getDefaultView());
78
79
        $config->setDefaultView($callable);
80
        self::assertEquals($callable, $config->getDefaultView());
81
    }
82
83
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
84
     * @covers ::addCache
85
     * @covers ::getCache
86
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
87
    public function testAddGetCache()
88
    {
89
        $cache = self::createMock(CacheInterface::class);
90
91
        $config = new BasicConfig();
92
        $config->addCache($cache, 'testCache');
0 ignored issues
show
Documentation introduced by
$cache is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\SimpleCache\CacheInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
93
94
        self::assertEquals($cache, $config->getCache('testCache'));
95
        self::assertNull($config->getCache('noCache'));
96
    }
97
}
98