Completed
Push — master ( 2dc9c3...9b34e4 )
by Alexis
01:37
created

SilexUserServiceProviderConfigurationTest::testWithEmptyUserClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace AWurth\SilexUser\Tests;
4
5
use AWurth\SilexUser\Provider\SilexUserServiceProvider;
6
use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
7
use LogicException;
8
use Silex\Application;
9
use Silex\Provider\DoctrineServiceProvider;
10
use Silex\Provider\FormServiceProvider;
11
use Silex\Provider\LocaleServiceProvider;
12
use Silex\Provider\SecurityServiceProvider;
13
use Silex\Provider\ServiceControllerServiceProvider;
14
use Silex\Provider\SessionServiceProvider;
15
use Silex\Provider\SwiftmailerServiceProvider;
16
use Silex\Provider\TranslationServiceProvider;
17
use Silex\Provider\TwigServiceProvider;
18
use Silex\Provider\ValidatorServiceProvider;
19
use Silex\WebTestCase;
20
21
class SilexUserServiceProviderConfigurationTest extends WebTestCase
22
{
23
    /**
24
     * @expectedException LogicException
25
     * @expectedExceptionMessage The "user_class" option must be set
26
     */
27
    public function testWithoutUserClass()
28
    {
29
        $this->app->boot();
30
    }
31
32
    /**
33
     * @expectedException LogicException
34
     * @expectedExceptionMessage The "user_class" option must be set
35
     */
36
    public function testWithEmptyUserClass()
37
    {
38
        $this->app['silex_user.options'] = [
39
            'user_class' => ''
40
        ];
41
42
        $this->app->boot();
43
    }
44
45
    /**
46
     * @expectedException LogicException
47
     * @expectedExceptionMessage The "firewall_name" option must be set
48
     */
49
    public function testWithoutFirewallName()
50
    {
51
        $this->app['silex_user.options'] = [
52
            'user_class' => 'User'
53
        ];
54
55
        $this->app->boot();
56
    }
57
58
    /**
59
     * @expectedException LogicException
60
     * @expectedExceptionMessage The "firewall_name" option must be set
61
     */
62
    public function testWithEmptyFirewallName()
63
    {
64
        $this->app['silex_user.options'] = [
65
            'user_class' => 'User',
66
            'firewall_name' => ''
67
        ];
68
69
        $this->app->boot();
70
    }
71
72
    /**
73
     * @expectedException LogicException
74
     * @expectedExceptionMessage You must configure a mailer to enable email notifications
75
     */
76
    public function testEmailConfirmationWithoutMailer()
77
    {
78
        $this->app['silex_user.options'] = [
79
            'user_class' => 'User',
80
            'firewall_name' => 'main',
81
            'registration.confirmation.enabled' => true
82
        ];
83
84
        $this->app->boot();
85
    }
86
87
    /**
88
     * @expectedException LogicException
89
     * @expectedExceptionMessage The "registration.confirmation.from_email" option must be set
90
     */
91
    public function testEmailConfirmationWithoutFromEmail()
92
    {
93
        $this->app->register(new SwiftmailerServiceProvider());
94
95
        $this->app['silex_user.options'] = [
96
            'user_class' => 'User',
97
            'firewall_name' => 'main',
98
            'registration.confirmation.enabled' => true
99
        ];
100
101
        $this->app->boot();
102
    }
103
104
    /**
105
     * @expectedException LogicException
106
     * @expectedExceptionMessage The "registration.confirmation.from_email" option must be set
107
     */
108
    public function testEmailConfirmationWithEmptyFromEmail()
109
    {
110
        $this->app->register(new SwiftmailerServiceProvider());
111
112
        $this->app['silex_user.options'] = [
113
            'user_class' => 'User',
114
            'firewall_name' => 'main',
115
            'registration.confirmation.enabled' => true,
116
            'registration.confirmation.from_email' => ''
117
        ];
118
119
        $this->app->boot();
120
    }
121
122
    public function createApplication()
123
    {
124
        $app = new Application([
125
            'debug' => true
126
        ]);
127
128
        $app->register(new ServiceControllerServiceProvider());
129
        $app->register(new TwigServiceProvider());
130
        $app->register(new SessionServiceProvider());
131
        $app->register(new LocaleServiceProvider());
132
        $app->register(new TranslationServiceProvider());
133
        $app->register(new ValidatorServiceProvider());
134
        $app->register(new FormServiceProvider());
135
        $app->register(new DoctrineServiceProvider());
136
        $app->register(new DoctrineOrmServiceProvider());
137
        $app->register(new SecurityServiceProvider());
138
        $app->register(new SilexUserServiceProvider());
139
140
        $app['security.firewalls'] = [
141
            'main' => [
142
                'form' => []
143
            ]
144
        ];
145
146
        return $app;
147
    }
148
}
149