LocaleApiTest::testEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\CoreBundle\Tests\Api;
15
16
use PHPUnit\Framework\TestCase;
17
use Symfony\Component\HttpFoundation\RequestStack;
18
use Zikula\CoreBundle\Api\LocaleApi;
19
use Zikula\CoreBundle\ApiInterface\LocaleApiInterface;
0 ignored issues
show
Bug introduced by
The type Zikula\CoreBundle\ApiInterface\LocaleApiInterface 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...
20
21
class LocaleApiTest extends TestCase
22
{
23
    public function testGetSupportedLocalesWithoutRegions(): void
24
    {
25
        $api = $this->getApi();
26
        $supportedLocales = $api->getSupportedLocales(false);
27
        foreach (['en', 'ru', 'de'] as $loc) {
28
            $this->assertContains($loc, $supportedLocales);
29
        }
30
        foreach (['de_DE'] as $loc) {
31
            $this->assertNotContains($loc, $supportedLocales);
32
        }
33
    }
34
35
    public function testGetSupportedLocalesWithRegions(): void
36
    {
37
        $api = $this->getApi();
38
        $supportedLocales = $api->getSupportedLocales(true);
39
        foreach (['en', 'ru', 'de', 'de_DE'] as $loc) {
40
            $this->assertContains($loc, $supportedLocales);
41
        }
42
    }
43
44
    public function testGetSupportedLocaleNames(): void
45
    {
46
        $api = $this->getApi();
47
        $expected = [
48
            'English' => 'en',
49
            'German' => 'de',
50
            'Russian' => 'ru'
51
        ];
52
        $this->assertEquals($expected, $api->getSupportedLocaleNames(null, 'en', false));
53
        $expected = [
54
            'Englisch' => 'en',
55
            'Deutsch' => 'de',
56
            'Russisch' => 'ru'
57
        ];
58
        $this->assertEquals($expected, $api->getSupportedLocaleNames(null, 'de', false));
59
        $expected = [
60
            'Inglese' => 'en',
61
            'Tedesco' => 'de',
62
            'Russo' => 'ru'
63
        ];
64
        $this->assertEquals($expected, $api->getSupportedLocaleNames(null, 'it', false));
65
    }
66
67
    public function testGetSupportedLocaleNamesWithRegions(): void
68
    {
69
        $api = $this->getApi();
70
        $expected = [
71
            'English' => 'en',
72
            'German' => 'de',
73
            'German (Germany)' => 'de_DE',
74
            'Russian' => 'ru'
75
        ];
76
        $this->assertEquals($expected, $api->getSupportedLocaleNames(null, 'en', true));
77
        $expected = [
78
            'Englisch' => 'en',
79
            'Deutsch' => 'de',
80
            'Deutsch (Deutschland)' => 'de_DE',
81
            'Russisch' => 'ru'
82
        ];
83
        $this->assertEquals($expected, $api->getSupportedLocaleNames(null, 'de', true));
84
    }
85
86
    public function testEmpty(): void
87
    {
88
        $api = $this->getApi('');
89
        $this->assertEquals(['en'], $api->getSupportedLocales());
90
    }
91
92
    private function getApi(string $dir = '/Fixtures'): LocaleApiInterface
93
    {
94
        $requestStack = $this->getMockBuilder(RequestStack::class)
95
            ->getMock()
96
        ;
97
        $projectDir = __DIR__ . $dir;
98
99
        return new LocaleApi($requestStack, $projectDir, true, 'en');
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Zikula\CoreBu...projectDir, true, 'en') returns the type Zikula\CoreBundle\Api\LocaleApi which is incompatible with the type-hinted return Zikula\CoreBundle\ApiInterface\LocaleApiInterface.
Loading history...
100
    }
101
}
102