1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ZFBrasil\Test\DoctrineMoneyModule\Form\Element\Factory; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
6
|
|
|
use Zend\Form\FormElementManager; |
7
|
|
|
use Zend\ServiceManager\Config; |
8
|
|
|
use Zend\ServiceManager\ServiceManager; |
9
|
|
|
use ZFBrasil\DoctrineMoneyModule\Form\Element\Factory\CurrencySelectFactory; |
10
|
|
|
use ZFBrasil\DoctrineMoneyModule\Form\Element\CurrencySelect; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Gabriel Schmitt <[email protected]> |
14
|
|
|
* @license MIT |
15
|
|
|
*/ |
16
|
|
|
class CurrencySelectFactoryTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var ServiceManager |
20
|
|
|
*/ |
21
|
|
|
private $serviceManager; |
22
|
|
|
|
23
|
|
|
private $config = [ |
24
|
|
|
'money' => [ |
25
|
|
|
'currencies' => [ |
26
|
|
|
'BRL' => 'Brazilian Real', |
27
|
|
|
'SAD' => 'Sad Asteka', |
28
|
|
|
], |
29
|
|
|
], |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
public function setUp() |
33
|
|
|
{ |
34
|
|
|
$this->serviceManager = new ServiceManager(new Config($this->config)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testFactoryCanCreateElement() |
38
|
|
|
{ |
39
|
|
|
$factory = new CurrencySelectFactory(); |
40
|
|
|
$this->serviceManager->setService('Config', $this->config); |
41
|
|
|
|
42
|
|
|
$formElementManager = $this->getMock(FormElementManager::class); |
43
|
|
|
$formElementManager->expects($this->once())->method('getServiceLocator')->willReturn($this->serviceManager); |
44
|
|
|
|
45
|
|
|
$this->assertInstanceOf(CurrencySelect::class, $factory($formElementManager)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testFactoryCreateElementWithExpectedCurrencies() |
49
|
|
|
{ |
50
|
|
|
$factory = new CurrencySelectFactory(); |
51
|
|
|
$this->serviceManager->setService('Config', $this->config); |
52
|
|
|
|
53
|
|
|
$formElementManager = $this->getMock(FormElementManager::class); |
54
|
|
|
$formElementManager->expects($this->once())->method('getServiceLocator')->willReturn($this->serviceManager); |
55
|
|
|
|
56
|
|
|
/* @var CurrencySelect $currencySelect */ |
57
|
|
|
$currencySelect = $factory($formElementManager); |
58
|
|
|
|
59
|
|
|
$this->assertEquals($this->config['money']['currencies'], $currencySelect->getValueOptions()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testFactoryCreateElementsWithNoCurrenciesShouldTrownAnException() |
63
|
|
|
{ |
64
|
|
|
$factory = new CurrencySelectFactory(); |
65
|
|
|
$this->serviceManager->setService('Config', []); |
66
|
|
|
|
67
|
|
|
$formElementManager = $this->getMock(FormElementManager::class); |
68
|
|
|
$formElementManager->expects($this->once())->method('getServiceLocator')->willReturn($this->serviceManager); |
69
|
|
|
|
70
|
|
|
$this->setExpectedException('InvalidArgumentException'); |
71
|
|
|
|
72
|
|
|
/* @var CurrencySelect $currencySelect */ |
73
|
|
|
$factory($formElementManager); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|