|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the SaasProviderBundle package. |
|
5
|
|
|
* (c) Fluxter <http://fluxter.net/> |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Fluxter\SaasProviderBundle\Tests\DependencyInjection; |
|
11
|
|
|
|
|
12
|
|
|
use Fluxter\SaasProviderBundle\DependencyInjection\SaasProviderExtension; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\Yaml\Parser; |
|
17
|
|
|
|
|
18
|
|
|
class SaasProviderExtensionTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var ContainerBuilder */ |
|
21
|
|
|
protected $configuration; |
|
22
|
|
|
|
|
23
|
|
|
protected function tearDown(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$this->configuration = null; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testExceptionThrownIfClientEntityNotSet() |
|
29
|
|
|
{ |
|
30
|
|
|
$loader = new SaasProviderExtension(); |
|
31
|
|
|
$config = $this->getEmptyConfig(); |
|
32
|
|
|
unset($config['client_entity']); |
|
33
|
|
|
|
|
34
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
35
|
|
|
$loader->load([$config], new ContainerBuilder()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testExceptionThrownIfClientEntityEmpty() |
|
39
|
|
|
{ |
|
40
|
|
|
$loader = new SaasProviderExtension(); |
|
41
|
|
|
$config = $this->getEmptyConfig(); |
|
42
|
|
|
$config['client_entity'] = ''; |
|
43
|
|
|
|
|
44
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
45
|
|
|
$loader->load([$config], new ContainerBuilder()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testExceptionThrownIfApiKeyNotSet() |
|
49
|
|
|
{ |
|
50
|
|
|
$loader = new SaasProviderExtension(); |
|
51
|
|
|
$config = $this->getEmptyConfig(); |
|
52
|
|
|
unset($config['apikey']); |
|
53
|
|
|
|
|
54
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
55
|
|
|
$loader->load([$config], new ContainerBuilder()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testExceptionThrownIfApiKeyEmpty() |
|
59
|
|
|
{ |
|
60
|
|
|
$loader = new SaasProviderExtension(); |
|
61
|
|
|
$config = $this->getEmptyConfig(); |
|
62
|
|
|
$config['apikey'] = ''; |
|
63
|
|
|
|
|
64
|
|
|
$this->expectException(InvalidConfigurationException::class); |
|
65
|
|
|
$loader->load([$config], new ContainerBuilder()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* getEmptyConfig. |
|
70
|
|
|
* |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getEmptyConfig() |
|
74
|
|
|
{ |
|
75
|
|
|
$yaml = <<<EOF |
|
76
|
|
|
client_entity: Acme\MyBundle\Entity\User |
|
77
|
|
|
apikey: test |
|
78
|
|
|
EOF; |
|
79
|
|
|
$parser = new Parser(); |
|
80
|
|
|
|
|
81
|
|
|
return $parser->parse($yaml); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|