-
Notifications
You must be signed in to change notification settings - Fork 1
/
InstallationTest.php
163 lines (142 loc) · 4.98 KB
/
InstallationTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* Part of the Antares package.
*
* NOTICE OF LICENSE
*
* Licensed under the 3-clause BSD License.
*
* This source file is subject to the 3-clause BSD License that is
* bundled with this package in the LICENSE file.
*
* @package Antares Core
* @version 0.9.0
* @author Antares Team
* @license BSD License (3-clause)
* @copyright (c) 2017, Antares
* @link http:https://antaresproject.io
*/
namespace Antares\Installation\TestCase;
use Mockery as m;
use Illuminate\Support\Facades\Facade;
use Antares\Installation\Installation;
use Antares\Testing\ApplicationTestCase;
use Antares\Support\Traits\Testing\EloquentConnectionTrait;
class InstallationTest extends ApplicationTestCase
{
use EloquentConnectionTrait;
/**
* Setup the test environment.
*/
public function setUp()
{
parent::setUp();
Facade::clearResolvedInstances();
}
/**
* Get User input.
*
* @access private
*
* @return array
*/
private function getUserInput()
{
return [
'site_name' => 'Antares Platform',
'email' => '[email protected]',
'password' => '123456',
'firstname' => 'Antares',
'lastname' => 'Project',
];
}
/**
* Get validation rules.
*
* @access private
*
* @return array
*/
private function getValidationRules()
{
return [
'email' => ['required', 'email'],
'password' => ['required'],
'fullname' => ['required'],
'site_name' => ['required'],
];
}
/**
* Test Antares\Foundation\Installation\Installation::bootInstallerFiles() method.
*
* @test
*/
public function testBootInstallerFilesMethod()
{
$app = $this->app;
$this->app['path'] = '/var/laravel/app';
$this->app['path.database'] = '/var/laravel/database';
$app['files'] = $files = m::mock('\Illuminate\Filesystem\Filesystem');
$files->shouldReceive('exists')->once()->with('/var/laravel/database/antares/installer.php')->andReturn(true)
->shouldReceive('requireOnce')->once()->with('/var/laravel/database/antares/installer.php')->andReturnNull()
->shouldReceive('exists')->once()->with('/var/laravel/app/antares/installer.php')->andReturn(true)
->shouldReceive('requireOnce')->once()->with('/var/laravel/app/antares/installer.php')->andReturnNull();
$stub = new Installation($app);
$this->assertNull($stub->bootInstallerFiles());
}
/**
* Test Antares\Foundation\Installation\Installation::migrate() method.
*
* @test
*/
public function testMigrateMethod()
{
$stub = new Installation($this->app);
$this->assertTrue($stub->migrate());
}
/**
* Test Antares\Foundation\Installation\Installation::createAdmin() method.
*
* @test
*/
public function testCreateAdminMethod()
{
$input = $this->getUserInput();
$stub = new Installation($this->app);
$this->assertFalse($stub->createAdmin($input, false));
}
/**
* Test Antares\Foundation\Installation\Installation::createAdmin() method
* with validation errors.
*
* @test
*/
public function testCreateAdminMethodWithValidationErrors()
{
$app = $this->app;
$app['files'] = m::mock('\Illuminate\Filesystem\Filesystem');
$app['validator'] = $validator = m::mock('\Illuminate\Contracts\Validation\Validator');
$app['session'] = $session = m::mock('\Illuminate\Session\SessionInterface');
$session->shouldReceive('flash')->once()->with('errors', m::type('Object'))->andReturnNull();
$stub = new Installation($app);
$this->assertFalse($stub->createAdmin([]));
}
/**
* Test Antares\Foundation\Installation\Installation::createAdmin() method
* throws exception.
*
* @test
*/
public function testCreateAdminMethodThrowsException()
{
$app = $this->app;
$app['files'] = m::mock('\Illuminate\Filesystem\Filesystem');
$app['validator'] = $validator = m::mock('\Illuminate\Contratcs\Validation\Validator');
$app['antares.user'] = $user = m::mock('\Antares\Model\User');
$app['antares.messages'] = $messages = m::mock('\Antares\Contracts\Messages\MessageBag');
$input = $this->getUserInput();
$messages->shouldReceive('add')->once()->with('error', m::any())->andReturnNull();
$stub = new Installation($this->app);
$this->assertFalse($stub->createAdmin($input, false));
}
}