1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sverraest\RevolutPHPBundle\Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use RevolutPHP\Client; |
7
|
|
|
use Sverraest\RevolutPHPBundle\DependencyInjection\SverraestRevolutPHPExtension; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Symfony\Component\Yaml\Parser; |
10
|
|
|
|
11
|
|
|
class SverraestRevolutPHPExtensionTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
15
|
|
|
*/ |
16
|
|
|
public function testBundleLoadThrowsExceptionUnlessApiKeyIsSet() |
17
|
|
|
{ |
18
|
|
|
$loader = new SverraestRevolutPHPExtension(); |
19
|
|
|
$config = $this->getEmptyConfig(); |
20
|
|
|
unset($config['api_key']); |
21
|
|
|
$loader->load([$config], new ContainerBuilder()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
26
|
|
|
*/ |
27
|
|
|
public function testBundleLoadThrowsExceptionUnlessModeIsSet() |
28
|
|
|
{ |
29
|
|
|
$loader = new SverraestRevolutPHPExtension(); |
30
|
|
|
$config = $this->getEmptyConfig(); |
31
|
|
|
unset($config['mode']); |
32
|
|
|
$loader->load([$config], new ContainerBuilder()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testServiceIsInstanceOfRevolutPHP() |
36
|
|
|
{ |
37
|
|
|
$loader = new SverraestRevolutPHPExtension(); |
38
|
|
|
$config = $this->getEmptyConfig(); |
39
|
|
|
$loader->load([$config], new ContainerBuilder()); |
40
|
|
|
$this->assertInstanceOf(Client::class, new Client($config['api_key'], $config['mode'])); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return mixed |
45
|
|
|
*/ |
46
|
|
|
protected function getEmptyConfig() |
47
|
|
|
{ |
48
|
|
|
$yaml = <<<EOF |
49
|
|
|
api_key: foo |
50
|
|
|
mode: sandbox |
51
|
|
|
EOF; |
52
|
|
|
$parser = new Parser(); |
53
|
|
|
return $parser->parse($yaml); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|