|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Tests\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\SiteSetting; |
|
6
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\SiteSettingRepository; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
class SiteSettingRepositoryTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testReturnNull() |
|
12
|
|
|
{ |
|
13
|
|
|
$siteSettingRepository = $this->getSiteSettingRepository(); |
|
14
|
|
|
|
|
15
|
|
|
$siteSettingRepository |
|
16
|
|
|
->method('findBy') |
|
17
|
|
|
->willReturn(null); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertSame(null, $siteSettingRepository->findBySiteId(26)); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
View Code Duplication |
public function testFindBySiteIdAndSetting() |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
$siteSettingRepository = $this->getSiteSettingRepository(); |
|
25
|
|
|
|
|
26
|
|
|
$obj = new SiteSetting(); |
|
27
|
|
|
$siteSettingRepository |
|
28
|
|
|
->method('findOneBy') |
|
29
|
|
|
->willReturn($obj); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertSame($obj, $siteSettingRepository->findBySiteIdAndSetting(26, 'setting')); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
public function testFindBySiteId() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$siteSettingRepository = $this->getSiteSettingRepository(); |
|
37
|
|
|
|
|
38
|
|
|
$obj = new SiteSetting(); |
|
39
|
|
|
$siteSettingRepository |
|
40
|
|
|
->method('findBy') |
|
41
|
|
|
->willReturn([$obj]); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertSame([$obj], $siteSettingRepository->findBySiteId(26)); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
View Code Duplication |
public function testFindBySetting() |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
$siteSettingRepository = $this->getSiteSettingRepository(); |
|
49
|
|
|
|
|
50
|
|
|
$obj = new SiteSetting(); |
|
51
|
|
|
$siteSettingRepository |
|
52
|
|
|
->method('findBy') |
|
53
|
|
|
->willReturn([$obj]); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertSame([$obj], $siteSettingRepository->findBySetting('setting')); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return SiteSettingRepository|\PHPUnit_Framework_MockObject_MockObject |
|
60
|
|
|
*/ |
|
61
|
|
|
private function getSiteSettingRepository() |
|
62
|
|
|
{ |
|
63
|
|
|
/** @var SiteSettingRepository|\PHPUnit_Framework_MockObject_MockObject $siteSettingRepository */ |
|
64
|
|
|
$siteSettingRepository = $this->getMockBuilder(SiteSettingRepository::class) |
|
65
|
|
|
->disableOriginalConstructor() |
|
66
|
|
|
->setMethods(['findOneBy', 'findBy']) |
|
67
|
|
|
->getMock(); |
|
68
|
|
|
|
|
69
|
|
|
return $siteSettingRepository; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: