1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Tests\Provider; |
4
|
|
|
|
5
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\SiteSetting; |
6
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\SiteSettingRepository; |
7
|
|
|
use Loevgaard\DandomainAltapayBundle\Provider\SiteSettingsProvider; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
10
|
|
|
|
11
|
|
|
final class SiteSettingsProviderTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testOnlyDefaultSettings() |
14
|
|
|
{ |
15
|
|
|
$container = $this->getContainer(); |
16
|
|
|
$repository = $this->getRepository(); |
17
|
|
|
|
18
|
|
|
$repository->method('findBySiteIdIndexedBySetting')->willReturn(null); |
19
|
|
|
|
20
|
|
|
$expected = array_map(function () { |
21
|
|
|
return 'default_setting'; |
22
|
|
|
}, SiteSetting::getSettings()); |
23
|
|
|
|
24
|
|
|
$siteSettingsProvider = new SiteSettingsProvider($container, $repository); |
|
|
|
|
25
|
|
|
$settings = $siteSettingsProvider->findBySiteIdIndexedBySetting(26); |
26
|
|
|
|
27
|
|
|
$this->assertSame($expected, $settings); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testOneSetting() |
31
|
|
|
{ |
32
|
|
|
$container = $this->getContainer(); |
33
|
|
|
$repository = $this->getRepository(); |
34
|
|
|
|
35
|
|
|
$siteSetting = new SiteSetting(); |
36
|
|
|
$siteSetting->setVal('11223344')->setSetting(SiteSetting::SETTING_PHONE)->setSiteId(26); |
37
|
|
|
|
38
|
|
|
$repository->method('findBySiteIdIndexedBySetting')->willReturn([SiteSetting::SETTING_PHONE => $siteSetting]); |
39
|
|
|
|
40
|
|
|
$expected = array_map(function () { |
41
|
|
|
return 'default_setting'; |
42
|
|
|
}, SiteSetting::getSettings()); |
43
|
|
|
$expected['phone'] = $siteSetting; |
44
|
|
|
|
45
|
|
|
$siteSettingsProvider = new SiteSettingsProvider($container, $repository); |
|
|
|
|
46
|
|
|
$settings = $siteSettingsProvider->findBySiteIdIndexedBySetting(26); |
47
|
|
|
|
48
|
|
|
$this->assertEquals($expected, $settings); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ContainerInterface |
53
|
|
|
*/ |
54
|
|
|
private function getContainer() |
55
|
|
|
{ |
56
|
|
|
/** @var ContainerInterface|\PHPUnit_Framework_MockObject_MockObject $container */ |
57
|
|
|
$container = $this->getMockForAbstractClass(ContainerInterface::class); |
58
|
|
|
|
59
|
|
|
$container->method('getParameter')->willReturn('default_setting'); |
60
|
|
|
|
61
|
|
|
return $container; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return SiteSettingRepository|\PHPUnit_Framework_MockObject_MockObject |
66
|
|
|
*/ |
67
|
|
|
private function getRepository() |
68
|
|
|
{ |
69
|
|
|
/** @var SiteSettingRepository|\PHPUnit_Framework_MockObject_MockObject $repository */ |
70
|
|
|
$repository = $this->getMockBuilder(SiteSettingRepository::class)->disableOriginalConstructor()->getMock(); |
71
|
|
|
|
72
|
|
|
return $repository; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.