Skip to content

Commit 715e52a

Browse files
committed
wip
1 parent e67f0ae commit 715e52a

File tree

9 files changed

+67
-47
lines changed

9 files changed

+67
-47
lines changed

.github/workflows/run_tests.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-latest]
12-
php: [7.4, 8.0]
13-
laravel: [8.*, 7.*]
12+
php: [8.2, 8.3]
13+
laravel: [10.*, 11.*]
1414
dependency-version: [prefer-lowest, prefer-stable]
1515
include:
16-
- laravel: 8.*
17-
testbench: 6.*
18-
- laravel: 7.*
19-
testbench: 5.*
16+
- laravel: 10.*
17+
testbench: 8.*
18+
- laravel: 11.*
19+
testbench: 9.*
2020

2121
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
2222

@@ -37,4 +37,4 @@ jobs:
3737
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
3838
3939
- name: Execute tests
40-
run: vendor/bin/phpunit
40+
run: composer test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor
22
/.idea
3-
composer.lock
3+
composer.lock
4+
/.phpunit.result.cache

composer.json

Lines changed: 20 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.2|^8.3",
15+
"laravel/framework": "^10.0|^11.0"
1516
},
1617
"require-dev": {
17-
"laravel/framework": "^8.12",
1818
"mockery/mockery": "^1.4",
19-
"phpunit/phpunit": "^9.3.3",
20-
"orchestra/testbench": "^6.9"
19+
"phpunit/phpunit": "^10.0",
20+
"orchestra/testbench": "^8.0|^9.0"
2121
},
2222
"autoload": {
2323
"psr-4": {
@@ -26,7 +26,22 @@
2626
}
2727
},
2828
"scripts": {
29-
"test": "vendor/bin/phpunit"
29+
"test": "vendor/bin/phpunit",
30+
"post-autoload-dump": [
31+
"@clear",
32+
"@prepare"
33+
],
34+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
35+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
36+
"build": "@php vendor/bin/testbench workbench:build --ansi",
37+
"serve": [
38+
"Composer\\Config::disableProcessTimeout",
39+
"@build",
40+
"@php vendor/bin/testbench serve"
41+
],
42+
"lint": [
43+
"@php vendor/bin/phpstan analyse"
44+
]
3045
},
3146
"extra": {
3247
"laravel": {

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="https://schema.phpunit.de/10.5/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="Integration">
8+
<directory suffix="Test.php">./tests/Integration</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>

src/Services/AtomicDeploymentService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ public function shutdown(): void
311311
{
312312
if ($error = error_get_last()) {
313313
Output::error('Error detected during shutdown, requesting rollback');
314+
Output::error(json_encode($error));
315+
314316
$this->fail();
315317
}
316318
}

src/Services/Output.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
use Illuminate\Support\Facades\Log;
66
use JTMcC\AtomicDeployments\Helpers\ConsoleOutput;
7+
use Throwable;
78

89
class Output
910
{
1011
/**
1112
* Print throwable to console | log.
1213
*
13-
* @param \Throwable $obj
14+
* @param Throwable $obj
1415
*/
15-
public static function throwable(\Throwable $obj): void
16+
public static function throwable(Throwable $obj): void
1617
{
1718
$title = get_class($obj);
1819
$file = $obj->getFile().' line '.$obj->getLine();

tests/Integration/Commands/DeployCommandTest.php

Lines changed: 7 additions & 4 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;
@@ -194,8 +195,9 @@ public function it_cleans_old_build_folders_based_on_build_limit()
194195
*/
195196
public function it_dispatches_deployment_successful_event_on_build()
196197
{
197-
$this->expectsEvents(DeploymentSuccessful::class);
198198
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
199+
200+
Event::assertDispatched(DeploymentSuccessful::class);
199201
}
200202

201203
/**
@@ -209,11 +211,11 @@ public function it_dispatches_deployment_successful_event_on_deployment_swap()
209211
$deployment = AtomicDeployment::where('commit_hash', 'test-dir-2')->first()->append('isCurrentlyDeployed')->toArray();
210212
$this->assertTrue($deployment['isCurrentlyDeployed']);
211213

212-
$this->expectsEvents(DeploymentSuccessful::class);
213-
214214
Artisan::call('atomic-deployments:deploy --hash=test-dir-1');
215215
$deployment = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append('isCurrentlyDeployed')->toArray();
216216
$this->assertTrue($deployment['isCurrentlyDeployed']);
217+
218+
Event::assertDispatched(DeploymentSuccessful::class);
217219
}
218220

219221
/**
@@ -225,7 +227,8 @@ public function it_dispatches_deployment_failed_event_on_build_fail()
225227
$this->expectException(InvalidPathException::class);
226228
$this->app['config']->set('atomic-deployments.build-path', $this->buildPath);
227229
$this->app['config']->set('atomic-deployments.deployments-path', $this->buildPath.'/deployments');
228-
$this->expectsEvents(DeploymentFailed::class);
229230
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');
231+
232+
Event::assertDispatched(DeploymentFailed::class);
230233
}
231234
}

tests/Integration/Services/AtomicDeploymentServiceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests\Integration\Services;
44

55
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Support\Facades\Event;
67
use JTMcC\AtomicDeployments\Events\DeploymentFailed;
78
use JTMcC\AtomicDeployments\Events\DeploymentSuccessful;
89
use JTMcC\AtomicDeployments\Exceptions\InvalidPathException;
@@ -120,12 +121,12 @@ public function it_rolls_back_symbolic_link_to_deployment_detected_on_boot()
120121
*/
121122
public function it_calls_closure_on_success()
122123
{
123-
$this->expectsEvents(DeploymentSuccessful::class);
124124
$success = false;
125125
self::getAtomicDeployment()->deploy(function () use (&$success) {
126126
$success = true;
127127
});
128128
$this->assertTrue($success);
129+
Event::assertDispatched(DeploymentSuccessful::class);
129130
}
130131

131132
/**
@@ -135,13 +136,13 @@ public function it_calls_closure_on_failure()
135136
{
136137
$this->app['config']->set('atomic-deployments.build-path', $this->buildPath);
137138
$this->app['config']->set('atomic-deployments.deployments-path', $this->buildPath.'/deployments');
138-
$this->expectsEvents(DeploymentFailed::class);
139139
$this->expectException(InvalidPathException::class);
140140
$failed = false;
141141
$atomicDeployment = self::getAtomicDeployment();
142142
$atomicDeployment->deploy(fn () => '', function () use (&$failed) {
143143
$failed = true;
144144
});
145145
$this->assertTrue($failed);
146+
Event::assertDispatched(DeploymentFailed::class);
146147
}
147148
}

tests/TestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ protected function setUp(): void
5353

5454
public function tearDown(): void
5555
{
56-
parent::tearDown();
5756
$this->fileSystem->deleteDirectory(self::tmpFolder);
57+
58+
parent::tearDown();
5859
}
5960

6061
/**

0 commit comments

Comments
 (0)