1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\MagentoBundle\Tests\Unit\Provider; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\AddressBundle\Entity\Country; |
6
|
|
|
use Oro\Bundle\AddressBundle\Entity\Repository\CountryRepository; |
7
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iso2CodeProvider; |
8
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
9
|
|
|
|
10
|
|
|
class Iso2CodeProviderTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var RegistryInterface|\PHPUnit_Framework_MockObject_MockObject |
14
|
|
|
*/ |
15
|
|
|
private $registry; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var Iso2CodeProvider |
19
|
|
|
*/ |
20
|
|
|
private $provider; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->registry = $this->getMockBuilder(RegistryInterface::class)->getMock(); |
25
|
|
|
$this->provider = new Iso2CodeProvider($this->registry); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @dataProvider getIso2CodeByCountryIdProvider |
30
|
|
|
* @param string $countryId |
31
|
|
|
* @param string $expectedIso2Code |
32
|
|
|
*/ |
33
|
|
|
public function testGetIso2CodeByCountryId($countryId, $expectedIso2Code) |
34
|
|
|
{ |
35
|
|
|
$countriesArray = [ |
36
|
|
|
[ |
37
|
|
|
'iso2Code' => 'US', |
38
|
|
|
'iso3Code' => 'USA', |
39
|
|
|
'name' => 'United States', |
40
|
|
|
], |
41
|
|
|
[ |
42
|
|
|
'iso2Code' => 'GB', |
43
|
|
|
'iso3Code' => 'GBR', |
44
|
|
|
'name' => 'United Kingdom', |
45
|
|
|
], |
46
|
|
|
]; |
47
|
|
|
$countryRepository = $this->getMockBuilder(CountryRepository::class) |
48
|
|
|
->disableOriginalConstructor() |
49
|
|
|
->getMock(); |
50
|
|
|
$countryRepository->expects($this->once()) |
51
|
|
|
->method('getAllCountryNamesArray') |
52
|
|
|
->willReturn($countriesArray); |
53
|
|
|
$this->registry->expects($this->once()) |
|
|
|
|
54
|
|
|
->method('getRepository') |
55
|
|
|
->with(Country::class) |
56
|
|
|
->willReturn($countryRepository); |
57
|
|
|
|
58
|
|
|
$iso2Code = $this->provider->getIso2CodeByCountryId($countryId); |
59
|
|
|
$this->assertEquals($expectedIso2Code, $iso2Code); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
public function getIso2CodeByCountryIdProvider() |
66
|
|
|
{ |
67
|
|
|
return [ |
68
|
|
|
'find by iso2' => [ |
69
|
|
|
'countryId' => 'US', |
70
|
|
|
'expectedIso2Code' => 'US', |
71
|
|
|
], |
72
|
|
|
'find by iso3' => [ |
73
|
|
|
'countryId' => 'GBR', |
74
|
|
|
'expectedIso2Code' => 'GB', |
75
|
|
|
], |
76
|
|
|
'find by name' => [ |
77
|
|
|
'countryId' => 'United Kingdom', |
78
|
|
|
'expectedIso2Code' => 'GB' |
79
|
|
|
], |
80
|
|
|
'cannot find' => [ |
81
|
|
|
'countryId' => 'SomeCountryId', |
82
|
|
|
'expectedIso2Code' => null, |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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: