|
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
|
|
|
|