1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flagbit\Bundle\CurrencyBundle\Tests\Service; |
4
|
|
|
|
5
|
|
|
use Flagbit\Bundle\CurrencyBundle\Service\Currency; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
8
|
|
|
|
9
|
|
|
class CurrencyTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var PHPUnit_Framework_MockObject_MockObject |
13
|
|
|
*/ |
14
|
|
|
private $currencyBundle; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var Currency |
18
|
|
|
*/ |
19
|
|
|
private $currency; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->currencyBundle = $this->getMockBuilder('Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface') |
24
|
|
|
->getMockForAbstractClass(); |
25
|
|
|
$this->currency = new Currency($this->currencyBundle, 'EUR'); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testDefaultCurrency() |
29
|
|
|
{ |
30
|
|
|
$this->assertEquals('EUR', $this->currency->getDefaultCurrency()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
public function testDefaultCurrencySymbol() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$this->currencyBundle |
36
|
|
|
->expects($this->once()) |
37
|
|
|
->method('getCurrencySymbol') |
38
|
|
|
->with('EUR') |
39
|
|
|
->will($this->returnValue('€')); |
40
|
|
|
|
41
|
|
|
$this->assertEquals('€', $this->currency->getCurrencySymbol()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function testCurrencySymbol() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->currencyBundle |
47
|
|
|
->expects($this->once()) |
48
|
|
|
->method('getCurrencySymbol') |
49
|
|
|
->with('USD') |
50
|
|
|
->will($this->returnValue('$')); |
51
|
|
|
|
52
|
|
|
$this->assertEquals('$', $this->currency->getCurrencySymbol('USD')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function testDefaultCurrencyName() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$this->currencyBundle |
58
|
|
|
->expects($this->once()) |
59
|
|
|
->method('getCurrencyName') |
60
|
|
|
->with('EUR') |
61
|
|
|
->will($this->returnValue('Euro')); |
62
|
|
|
|
63
|
|
|
$this->assertEquals('Euro', $this->currency->getCurrencyName()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
public function testCurrencyName() |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$this->currencyBundle |
69
|
|
|
->expects($this->once()) |
70
|
|
|
->method('getCurrencyName') |
71
|
|
|
->with('USD') |
72
|
|
|
->will($this->returnValue('US Dollar')); |
73
|
|
|
|
74
|
|
|
$this->assertEquals('US Dollar', $this->currency->getCurrencyName('USD')); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: