Skip to content

Commit 782cb27

Browse files
committed
Update dependencies & test formatting
1 parent e67f0ae commit 782cb27

File tree

12 files changed

+304
-304
lines changed

12 files changed

+304
-304
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ The purpose of this package is to introduce local zero-downtime deployments into
77

88
## Requirements
99

10-
* Laravel 7 | 8
11-
* PHP ^7.4 | ^8.0
10+
* Laravel >= 11.x+
11+
* PHP >= 8.3
1212

1313
## Installation
1414

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.4|^8.0"
14+
"php": "^8.3"
1515
},
1616
"require-dev": {
17-
"laravel/framework": "^8.12",
18-
"mockery/mockery": "^1.4",
19-
"phpunit/phpunit": "^9.3.3",
20-
"orchestra/testbench": "^6.9"
17+
"laravel/framework": "^11.0",
18+
"mockery/mockery": "^1.6.10",
19+
"phpunit/phpunit": "^10.5.35|^11.3.6",
20+
"orchestra/testbench": "^9.0"
2121
},
2222
"autoload": {
2323
"psr-4": {

phpunit.xml

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
colors="true">
6-
<testsuites>
7-
<testsuite name="Unit">
8-
<directory suffix="Test.php">./tests/Unit</directory>
9-
</testsuite>
10-
<testsuite name="Integration">
11-
<directory suffix="Test.php">./tests/Integration</directory>
12-
</testsuite>
13-
</testsuites>
14-
<coverage processUncoveredFiles="true">
15-
<include>
16-
<directory suffix=".php">./app</directory>
17-
</include>
18-
</coverage>
19-
<php>
20-
<env name="APP_ENV" value="testing"/>
21-
<env name="DB_DATABASE" value="sqlite"/>
22-
23-
<env name="ATM_DEPLOYMENT_LINK" value="deployment-link"/>
24-
<env name="ATM_BUILD" value="build"/>
25-
<env name="ATM_DEPLOYMENTS" value="deployments"/>
26-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
3+
<testsuites>
4+
<testsuite name="Unit">
5+
<directory suffix="Test.php">./tests/Unit</directory>
6+
</testsuite>
7+
<testsuite name="Feature">
8+
<directory suffix="Test.php">./tests/Feature</directory>
9+
</testsuite>
10+
</testsuites>
11+
<php>
12+
<env name="APP_ENV" value="testing"/>
13+
<env name="DB_DATABASE" value="sqlite"/>
14+
<env name="ATM_DEPLOYMENT_LINK" value="deployment-link"/>
15+
<env name="ATM_BUILD" value="build"/>
16+
<env name="ATM_DEPLOYMENTS" value="deployments"/>
17+
</php>
18+
<source>
19+
<include>
20+
<directory suffix=".php">./app</directory>
21+
</include>
22+
</source>
2723
</phpunit>

tests/Integration/Commands/DeployCommandTest.php renamed to tests/Feature/Commands/DeployCommandTest.php

Lines changed: 81 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Foundation\Testing\RefreshDatabase;
66
use Illuminate\Support\Facades\Artisan;
7+
use Illuminate\Support\Facades\Event;
78
use JTMcC\AtomicDeployments\Events\DeploymentFailed;
89
use JTMcC\AtomicDeployments\Events\DeploymentSuccessful;
910
use JTMcC\AtomicDeployments\Exceptions\InvalidPathException;
@@ -15,13 +16,12 @@ class DeployCommandTest extends TestCase
1516
{
1617
use RefreshDatabase;
1718

18-
/**
19-
* @test
20-
*/
21-
public function it_allows_dry_run_with_no_mutations()
19+
public function test_it_allows_dry_run_with_no_mutations()
2220
{
21+
// Act
2322
Artisan::call('atomic-deployments:deploy --dry-run --directory=test-dir-1');
2423

24+
// Assert
2525
$this->seeInConsoleOutput([
2626
'Deployment directory option set - Deployment will use directory: test-dir-1',
2727
'Running Deployment...',
@@ -34,24 +34,21 @@ public function it_allows_dry_run_with_no_mutations()
3434
]);
3535

3636
$this->dontSeeInConsoleOutput('Atomic deployment rollback has been requested');
37-
38-
$this->assertFalse($this->fileSystem->exists($this->deploymentsPath.'/test-dir-1/'));
37+
$this->assertFalse($this->fileSystem->exists($this->deploymentsPath . '/test-dir-1/'));
3938
$this->assertFalse($this->fileSystem->exists($this->deploymentLink));
4039
$this->assertEmpty(AtomicDeployment::all());
4140
}
4241

43-
/**
44-
* @test
45-
*/
46-
public function it_does_not_migrate_on_dry_run()
42+
public function test_it_does_not_migrate_on_dry_run()
4743
{
44+
// Collect
4845
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
46+
$this->fileSystem->ensureDirectoryExists($this->deploymentsPath . '/test-dir-1/migration/test-folder');
4947

50-
//add file to 'deployment' that does not exist in 'build' for migrate test
51-
$this->fileSystem->ensureDirectoryExists($this->deploymentsPath.'/test-dir-1/migration/test-folder');
52-
48+
// Act
5349
Artisan::call('atomic-deployments:deploy --dry-run --directory=test-dir-2');
5450

51+
// Assert
5552
$this->seeInConsoleOutput([
5653
'Deployment directory option set - Deployment will use directory: test-dir-2',
5754
'Running Deployment...',
@@ -60,18 +57,16 @@ public function it_does_not_migrate_on_dry_run()
6057
]);
6158

6259
$this->dontSeeInConsoleOutput('Atomic deployment rollback has been requested');
63-
64-
$this->assertTrue($this->fileSystem->exists($this->deploymentsPath.'/test-dir-1/migration/test-folder'));
65-
$this->assertFalse($this->fileSystem->exists($this->deploymentsPath.'/test-dir-2/migration/test-folder'));
60+
$this->assertTrue($this->fileSystem->exists($this->deploymentsPath . '/test-dir-1/migration/test-folder'));
61+
$this->assertFalse($this->fileSystem->exists($this->deploymentsPath . '/test-dir-2/migration/test-folder'));
6662
}
6763

68-
/**
69-
* @test
70-
*/
71-
public function it_allows_run_with_mutations()
64+
public function test_it_allows_run_with_mutations()
7265
{
66+
// Act
7367
Artisan::call('atomic-deployments:deploy --directory=test-dir');
7468

69+
// Assert
7570
$this->seeInConsoleOutput([
7671
'Deployment directory option set - Deployment will use directory: test-dir',
7772
'Running Deployment...',
@@ -84,28 +79,25 @@ public function it_allows_run_with_mutations()
8479
'Atomic deployment rollback has been requested',
8580
]);
8681

87-
$this->assertTrue($this->fileSystem->exists($this->deploymentsPath.'/test-dir/build-contents-folder'));
82+
$this->assertTrue($this->fileSystem->exists($this->deploymentsPath . '/test-dir/build-contents-folder'));
8883
$this->assertTrue($this->fileSystem->exists($this->deploymentLink));
8984

9085
$deployment = AtomicDeployment::first();
9186
$this->assertNotEmpty($deployment);
92-
$this->assertTrue((int) $deployment->deployment_status === DeploymentStatus::SUCCESS);
87+
$this->assertTrue((int)$deployment->deployment_status === DeploymentStatus::SUCCESS);
9388
}
9489

95-
/**
96-
* @test
97-
*/
98-
public function it_allows_migrate_on_run()
90+
public function test_it_allows_migrate_on_run()
9991
{
92+
// Collect
10093
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
94+
$this->fileSystem->ensureDirectoryExists($this->deploymentsPath . '/test-dir-1/migration/test-folder');
95+
$this->assertFalse($this->fileSystem->exists($this->deploymentsPath . '/test-dir-2/migration/test-folder'));
10196

102-
//add file to 'deployment' that does not exist in 'build' for migrate test
103-
$this->fileSystem->ensureDirectoryExists($this->deploymentsPath.'/test-dir-1/migration/test-folder');
104-
105-
$this->assertFalse($this->fileSystem->exists($this->deploymentsPath.'/test-dir-2/migration/test-folder'));
106-
97+
// Act
10798
Artisan::call('atomic-deployments:deploy --directory=test-dir-2');
10899

100+
// Assert
109101
$this->seeInConsoleOutput([
110102
'Deployment directory option set - Deployment will use directory: test-dir-2',
111103
'Running Deployment...',
@@ -114,118 +106,119 @@ public function it_allows_migrate_on_run()
114106
]);
115107

116108
$this->dontSeeInConsoleOutput('Atomic deployment rollback has been requested');
117-
118-
$this->assertTrue($this->fileSystem->exists($this->deploymentsPath.'/test-dir-1/migration/test-folder'));
119-
120-
//confirm migrate logic copied test folder
121-
$this->assertTrue($this->fileSystem->exists($this->deploymentsPath.'/test-dir-2/migration/test-folder'));
109+
$this->assertTrue($this->fileSystem->exists($this->deploymentsPath . '/test-dir-1/migration/test-folder'));
110+
$this->assertTrue($this->fileSystem->exists($this->deploymentsPath . '/test-dir-2/migration/test-folder'));
122111
}
123112

124-
/**
125-
* @test
126-
*/
127-
public function it_allows_swapping_between_deployments()
113+
public function test_it_allows_swapping_between_deployments()
128114
{
129-
130-
//create two builds
115+
// Collect
131116
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
132117
Artisan::call('atomic-deployments:deploy --directory=test-dir-2');
118+
$deployment1 = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append(
119+
'isCurrentlyDeployed'
120+
)->toArray();
121+
$deployment2 = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append(
122+
'isCurrentlyDeployed'
123+
)->toArray();
133124

134-
$deployment1 = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append('isCurrentlyDeployed')->toArray();
135-
$deployment2 = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append('isCurrentlyDeployed')->toArray();
136-
137-
//confirm our last build is currently deployed
138125
$this->assertFalse($deployment1['isCurrentlyDeployed']);
139126
$this->assertTrue($deployment2['isCurrentlyDeployed']);
140127

128+
// Act
141129
Artisan::call('atomic-deployments:deploy --hash=test-dir-fake');
142130

143-
//confirm build must exist when attempting to swap
131+
// Assert
144132
$this->seeInConsoleOutput([
145133
'Updating symlink to previous build: test-dir-fake',
146134
'Build not found for hash: test-dir-fake',
147135
]);
148136

137+
// Act
149138
Artisan::call('atomic-deployments:deploy --hash=test-dir-1');
150139

151-
//swap build to our first deployment
140+
// Assert
152141
$this->seeInConsoleOutput([
153142
'Updating symlink to previous build: test-dir-1',
154143
'Build link confirmed',
155144
]);
156145

157-
$deployment1 = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append('isCurrentlyDeployed')->toArray();
158-
$deployment2 = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append('isCurrentlyDeployed')->toArray();
146+
$deployment1 = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append(
147+
'isCurrentlyDeployed'
148+
)->toArray();
149+
$deployment2 = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append(
150+
'isCurrentlyDeployed'
151+
)->toArray();
159152

160-
//confirm first deployment is now live and second is not
161153
$this->assertTrue($deployment1['isCurrentlyDeployed']);
162154
$this->assertFalse($deployment2['isCurrentlyDeployed']);
163155
}
164156

165-
/**
166-
* @test
167-
*/
168-
public function it_cleans_old_build_folders_based_on_build_limit()
157+
public function test_it_cleans_old_build_folders_based_on_build_limit()
169158
{
170-
$this->app['config']->set('atomic-deployments.build-limit', 1);
171-
172-
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
173-
Artisan::call('atomic-deployments:deploy --directory=test-dir-2');
174-
175-
$this->assertTrue(AtomicDeployment::all()->count() === 1);
176-
$this->assertTrue(AtomicDeployment::withTrashed()->get()->count() === 2);
177-
178-
AtomicDeployment::truncate();
179-
159+
// Collect
180160
$this->app['config']->set('atomic-deployments.build-limit', 3);
181161

162+
// Act
182163
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
183164
Artisan::call('atomic-deployments:deploy --directory=test-dir-2');
184165
Artisan::call('atomic-deployments:deploy --directory=test-dir-3');
185166
Artisan::call('atomic-deployments:deploy --directory=test-dir-4');
186167
Artisan::call('atomic-deployments:deploy --directory=test-dir-5');
187168

169+
// Assert
188170
$this->assertTrue(AtomicDeployment::all()->count() === 3);
189171
$this->assertTrue(AtomicDeployment::withTrashed()->get()->count() === 5);
190172
}
191173

192-
/**
193-
* @test
194-
*/
195-
public function it_dispatches_deployment_successful_event_on_build()
174+
public function test_it_dispatches_deployment_successful_event_on_build()
196175
{
197-
$this->expectsEvents(DeploymentSuccessful::class);
176+
// Collect
177+
Event::fake();
178+
179+
// Act
198180
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
181+
182+
// Assert
183+
Event::assertDispatched(DeploymentSuccessful::class);
199184
}
200185

201-
/**
202-
* @test
203-
*/
204-
public function it_dispatches_deployment_successful_event_on_deployment_swap()
186+
public function test_it_dispatches_deployment_successful_event_on_deployment_swap()
205187
{
188+
// Collect
189+
Event::fake();
206190
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
207191
Artisan::call('atomic-deployments:deploy --directory=test-dir-2');
208-
209-
$deployment = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append('isCurrentlyDeployed')->toArray();
192+
$deployment = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append(
193+
'isCurrentlyDeployed'
194+
)->toArray();
210195
$this->assertTrue($deployment['isCurrentlyDeployed']);
211196

212-
$this->expectsEvents(DeploymentSuccessful::class);
213-
197+
// Act
214198
Artisan::call('atomic-deployments:deploy --hash=test-dir-1');
215-
$deployment = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append('isCurrentlyDeployed')->toArray();
199+
200+
// Assert
201+
$deployment = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append(
202+
'isCurrentlyDeployed'
203+
)->toArray();
216204
$this->assertTrue($deployment['isCurrentlyDeployed']);
205+
Event::assertDispatched(DeploymentSuccessful::class);
217206
}
218207

219-
/**
220-
* @test
221-
*/
222-
public function it_dispatches_deployment_failed_event_on_build_fail()
208+
public function test_it_dispatches_deployment_failed_event_on_build_fail()
223209
{
224-
//force invalid path exception
225-
$this->expectException(InvalidPathException::class);
210+
// Collect
211+
Event::fake();
226212
$this->app['config']->set('atomic-deployments.build-path', $this->buildPath);
227-
$this->app['config']->set('atomic-deployments.deployments-path', $this->buildPath.'/deployments');
228-
$this->expectsEvents(DeploymentFailed::class);
213+
$this->app['config']->set('atomic-deployments.deployments-path', $this->buildPath . '/deployments');
214+
215+
// Assert
216+
$this->expectException(InvalidPathException::class);
217+
218+
// Act
229219
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
220+
221+
// Assert
222+
Event::assertDispatched(DeploymentFailed::class);
230223
}
231-
}
224+
}

0 commit comments

Comments
 (0)