LocaleCollectionSortServiceTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 30
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDefaultSortingOfCollection() 0 9 1
A testReplaceSortingOfCollection() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lochmueller\LanguageDetection\Tests\Unit\Service;
6
7
use Lochmueller\LanguageDetection\Domain\Collection\LocaleCollection;
8
use Lochmueller\LanguageDetection\Domain\Model\Dto\LocaleValueObject;
9
use Lochmueller\LanguageDetection\Service\LocaleCollectionSortService;
10
use Lochmueller\LanguageDetection\Tests\Unit\AbstractUnitTest;
11
12
/**
13
 * @covers \Lochmueller\LanguageDetection\Service\LocaleCollectionSortService
14
 *
15
 * @internal
16
 */
17
class LocaleCollectionSortServiceTest extends AbstractUnitTest
18
{
19
    /**
20
     * @covers \Lochmueller\LanguageDetection\Domain\Collection\LocaleCollection
21
     * @covers \Lochmueller\LanguageDetection\Domain\Model\Dto\LocaleValueObject
22
     */
23
    public function testDefaultSortingOfCollection(): void
24
    {
25
        $collection = LocaleCollection::fromArray(['de']);
26
27
        $sortService = new LocaleCollectionSortService();
28
29
        $result = $sortService->addLocaleByMode($collection, new LocaleValueObject('en'));
30
31
        self::assertSame(['de', 'en'], array_map(fn(LocaleValueObject $item): string => (string)$item, $result->toArray()));
32
    }
33
34
    /**
35
     * @covers \Lochmueller\LanguageDetection\Domain\Collection\LocaleCollection
36
     * @covers \Lochmueller\LanguageDetection\Domain\Model\Dto\LocaleValueObject
37
     */
38
    public function testReplaceSortingOfCollection(): void
39
    {
40
        $collection = LocaleCollection::fromArray(['de']);
41
42
        $sortService = new LocaleCollectionSortService();
43
44
        $result = $sortService->addLocaleByMode($collection, new LocaleValueObject('en'), LocaleCollectionSortService::SORT_REPLACE);
45
46
        self::assertSame(['en'], array_map(fn(LocaleValueObject $item): string => (string)$item, $result->toArray()));
47
    }
48
}
49