8
8
use Magento \MagentoCloud \Config \State ;
9
9
use Magento \MagentoCloud \Config \Environment ;
10
10
use Magento \MagentoCloud \Config \Validator \Deploy \AdminEmail ;
11
+ use Magento \MagentoCloud \Config \Validator \Deploy \DatabaseConfiguration ;
11
12
use Magento \MagentoCloud \Config \Validator \Result \Error ;
12
13
use Magento \MagentoCloud \Config \Validator \Result \Success ;
13
14
use Magento \MagentoCloud \Config \Validator \ResultInterface ;
@@ -35,6 +36,11 @@ class AdminEmailTest extends TestCase
35
36
*/
36
37
private $ resultFactoryMock ;
37
38
39
+ /**
40
+ * @var DatabaseConfiguration|Mock
41
+ */
42
+ private $ databaseConfigurationMock ;
43
+
38
44
/**
39
45
* @var State|Mock
40
46
*/
@@ -45,11 +51,13 @@ class AdminEmailTest extends TestCase
45
51
*/
46
52
protected function setUp ()
47
53
{
54
+ $ this ->databaseConfigurationMock = $ this ->createMock (DatabaseConfiguration::class);
48
55
$ this ->environmentMock = $ this ->createMock (Environment::class);
49
56
$ this ->resultFactoryMock = $ this ->createMock (ResultFactory::class);
50
57
$ this ->stateMock = $ this ->createMock (State::class);
51
58
52
59
$ this ->adminEmailValidator = new AdminEmail (
60
+ $ this ->databaseConfigurationMock ,
53
61
$ this ->environmentMock ,
54
62
$ this ->resultFactoryMock ,
55
63
$ this ->stateMock
@@ -58,9 +66,10 @@ protected function setUp()
58
66
59
67
public function testValidate ()
60
68
{
61
- $ this ->stateMock ->expects ($ this ->once ())
62
- ->method ('isInstalled ' )
63
- ->willReturn (false );
69
+ $ this ->stateMock ->expects ($ this ->never ())
70
+ ->method ('isInstalled ' );
71
+ $ this ->databaseConfigurationMock ->expects ($ this ->never ())
72
+ ->method ('validate ' );
64
73
$ this ->environmentMock ->expects ($ this ->once ())
65
74
->method ('getAdminEmail ' )
66
75
->willReturn ('admin@example.com ' );
@@ -76,11 +85,15 @@ public function testValidate()
76
85
77
86
public function testValidateMagentoInstalled ()
78
87
{
88
+ $ this ->environmentMock ->expects ($ this ->once ())
89
+ ->method ('getAdminEmail ' )
90
+ ->willReturn ('' );
79
91
$ this ->stateMock ->expects ($ this ->once ())
80
92
->method ('isInstalled ' )
81
93
->willReturn (true );
82
- $ this ->environmentMock ->expects ($ this ->never ())
83
- ->method ('getAdminEmail ' );
94
+ $ this ->databaseConfigurationMock ->expects ($ this ->once ())
95
+ ->method ('validate ' )
96
+ ->willReturn ($ this ->createMock (Success::class));
84
97
$ this ->resultFactoryMock ->expects ($ this ->once ())
85
98
->method ('create ' )
86
99
->with (ResultInterface::SUCCESS )
@@ -91,11 +104,35 @@ public function testValidateMagentoInstalled()
91
104
$ this ->assertInstanceOf (Success::class, $ result );
92
105
}
93
106
107
+ public function testValidateWrongDatabaseConnection ()
108
+ {
109
+ $ this ->environmentMock ->expects ($ this ->once ())
110
+ ->method ('getAdminEmail ' )
111
+ ->willReturn ('' );
112
+ $ this ->databaseConfigurationMock ->expects ($ this ->once ())
113
+ ->method ('validate ' )
114
+ ->willReturn ($ this ->createMock (Error::class));
115
+ $ this ->stateMock ->expects ($ this ->never ())
116
+ ->method ('isInstalled ' );
117
+ $ this ->resultFactoryMock ->expects ($ this ->once ())
118
+ ->method ('create ' )
119
+ ->with (ResultInterface::SUCCESS )
120
+ ->willReturn ($ this ->createMock (Success::class));
121
+
122
+ $ result = $ this ->adminEmailValidator ->validate ();
123
+
124
+ $ this ->assertInstanceOf (Success::class, $ result );
125
+ }
126
+
127
+
94
128
public function testValidateAdminEmailNotExist ()
95
129
{
96
130
$ this ->stateMock ->expects ($ this ->once ())
97
131
->method ('isInstalled ' )
98
132
->willReturn (false );
133
+ $ this ->databaseConfigurationMock ->expects ($ this ->once ())
134
+ ->method ('validate ' )
135
+ ->willReturn ($ this ->createMock (Success::class));
99
136
$ this ->environmentMock ->expects ($ this ->once ())
100
137
->method ('getAdminEmail ' )
101
138
->willReturn ('' );
0 commit comments