Issues (281)

Branch: master

src/Common/Tests/ModulesSettingsTest.php (1 issue)

1
<?php
2
3
namespace Common\Tests;
4
5
use Common\ModulesSettings;
6
use MatthiasMullie\Scrapbook\Adapters\MemoryStore;
7
use MatthiasMullie\Scrapbook\Psr6\Pool;
8
use PHPUnit\Framework\MockObject\MockObject;
0 ignored issues
show
The type PHPUnit\Framework\MockObject\MockObject 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...
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * Tests for our module settings
13
 */
14
class ModulesSettingsTest extends TestCase
15
{
16
    public function testFetchingSettingsCallsTheDatabaseOnce(): void
17
    {
18
        $modulesSettings = new ModulesSettings(
19
            $this->getDatabaseMock(),
20
            new Pool(new MemoryStore())
21
        );
22
23
        $modulesSettings->get('Core', 'theme', 'Fork');
24
        $modulesSettings->get('Core', 'time_format', 'H:i');
25
        $modulesSettings->get('Blog', 'spam_filter', false);
26
    }
27
28
    public function testFetchingSettingWorks(): void
29
    {
30
        $modulesSettings = new ModulesSettings(
31
            $this->getDatabaseMock(),
32
            new Pool(new MemoryStore())
33
        );
34
35
        self::assertEquals(
36
            'Fork',
37
            $modulesSettings->get('Core', 'theme')
38
        );
39
        self::assertEquals(
40
            'Fork',
41
            $modulesSettings->get('Core', 'theme', 'test')
42
        );
43
    }
44
45
    public function testDefaultValueWillBeReturned(): void
46
    {
47
        $modulesSettings = new ModulesSettings(
48
            $this->getDatabaseMock(),
49
            new Pool(new MemoryStore())
50
        );
51
52
        self::assertEquals(
53
            'default_value',
54
            $modulesSettings->get('Test', 'Blub', 'default_value')
55
        );
56
    }
57
58
    public function testFetchingSettingsForAModule(): void
59
    {
60
        $modulesSettings = new ModulesSettings(
61
            $this->getDatabaseMock(),
62
            new Pool(new MemoryStore())
63
        );
64
65
        self::assertEquals(
66
            [
67
                'theme' => 'Fork',
68
            ],
69
            $modulesSettings->getForModule('Core')
70
        );
71
        self::assertEquals(
72
            [],
73
            $modulesSettings->getForModule('Fake')
74
        );
75
    }
76
77
    private function getDatabaseMock(): MockObject
78
    {
79
        $databaseMock = $this->getMockBuilder('SpoonDatabase')
80
            ->disableOriginalConstructor()
81
            ->getMock()
82
        ;
83
84
        $databaseMock
85
            ->expects(self::atLeastOnce())
86
            ->method('getRecords')
87
            ->willReturn([
88
                [
89
                    'module' => 'Core',
90
                    'name' => 'theme',
91
                    'value' => serialize('Fork'),
92
                ],
93
            ])
94
        ;
95
96
        return $databaseMock;
97
    }
98
}
99