Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
J-T-McC committed Jun 11, 2024
1 parent e67f0ae commit 715e52a
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 47 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4, 8.0]
laravel: [8.*, 7.*]
php: [8.2, 8.3]
laravel: [10.*, 11.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*

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

Expand All @@ -37,4 +37,4 @@ jobs:
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
run: composer test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
/.idea
composer.lock
composer.lock
/.phpunit.result.cache
25 changes: 20 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
}
],
"require": {
"php": "^7.4|^8.0"
"php": "^8.2|^8.3",
"laravel/framework": "^10.0|^11.0"
},
"require-dev": {
"laravel/framework": "^8.12",
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.3.3",
"orchestra/testbench": "^6.9"
"phpunit/phpunit": "^10.0",
"orchestra/testbench": "^8.0|^9.0"
},
"autoload": {
"psr-4": {
Expand All @@ -26,7 +26,22 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/phpunit",
"post-autoload-dump": [
"@clear",
"@prepare"
],
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve"
],
"lint": [
"@php vendor/bin/phpstan analyse"
]
},
"extra": {
"laravel": {
Expand Down
46 changes: 21 additions & 25 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</include>
</coverage>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_DATABASE" value="sqlite"/>

<env name="ATM_DEPLOYMENT_LINK" value="deployment-link"/>
<env name="ATM_BUILD" value="build"/>
<env name="ATM_DEPLOYMENTS" value="deployments"/>
</php>
<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">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_DATABASE" value="sqlite"/>
<env name="ATM_DEPLOYMENT_LINK" value="deployment-link"/>
<env name="ATM_BUILD" value="build"/>
<env name="ATM_DEPLOYMENTS" value="deployments"/>
</php>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions src/Services/AtomicDeploymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ public function shutdown(): void
{
if ($error = error_get_last()) {
Output::error('Error detected during shutdown, requesting rollback');
Output::error(json_encode($error));

$this->fail();
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Services/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

use Illuminate\Support\Facades\Log;
use JTMcC\AtomicDeployments\Helpers\ConsoleOutput;
use Throwable;

class Output
{
/**
* Print throwable to console | log.
*
* @param \Throwable $obj
* @param Throwable $obj
*/
public static function throwable(\Throwable $obj): void
public static function throwable(Throwable $obj): void
{
$title = get_class($obj);
$file = $obj->getFile().' line '.$obj->getLine();
Expand Down
11 changes: 7 additions & 4 deletions tests/Integration/Commands/DeployCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Event;
use JTMcC\AtomicDeployments\Events\DeploymentFailed;
use JTMcC\AtomicDeployments\Events\DeploymentSuccessful;
use JTMcC\AtomicDeployments\Exceptions\InvalidPathException;
Expand Down Expand Up @@ -194,8 +195,9 @@ public function it_cleans_old_build_folders_based_on_build_limit()
*/
public function it_dispatches_deployment_successful_event_on_build()
{
$this->expectsEvents(DeploymentSuccessful::class);
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');

Event::assertDispatched(DeploymentSuccessful::class);
}

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

$this->expectsEvents(DeploymentSuccessful::class);

Artisan::call('atomic-deployments:deploy --hash=test-dir-1');
$deployment = AtomicDeployment::where('commit_hash', 'test-dir-1')->first()->append('isCurrentlyDeployed')->toArray();
$this->assertTrue($deployment['isCurrentlyDeployed']);

Event::assertDispatched(DeploymentSuccessful::class);
}

/**
Expand All @@ -225,7 +227,8 @@ public function it_dispatches_deployment_failed_event_on_build_fail()
$this->expectException(InvalidPathException::class);
$this->app['config']->set('atomic-deployments.build-path', $this->buildPath);
$this->app['config']->set('atomic-deployments.deployments-path', $this->buildPath.'/deployments');
$this->expectsEvents(DeploymentFailed::class);
Artisan::call('atomic-deployments:deploy --directory=test-dir-1');

Event::assertDispatched(DeploymentFailed::class);
}
}
5 changes: 3 additions & 2 deletions tests/Integration/Services/AtomicDeploymentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Integration\Services;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use JTMcC\AtomicDeployments\Events\DeploymentFailed;
use JTMcC\AtomicDeployments\Events\DeploymentSuccessful;
use JTMcC\AtomicDeployments\Exceptions\InvalidPathException;
Expand Down Expand Up @@ -120,12 +121,12 @@ public function it_rolls_back_symbolic_link_to_deployment_detected_on_boot()
*/
public function it_calls_closure_on_success()
{
$this->expectsEvents(DeploymentSuccessful::class);
$success = false;
self::getAtomicDeployment()->deploy(function () use (&$success) {
$success = true;
});
$this->assertTrue($success);
Event::assertDispatched(DeploymentSuccessful::class);
}

/**
Expand All @@ -135,13 +136,13 @@ public function it_calls_closure_on_failure()
{
$this->app['config']->set('atomic-deployments.build-path', $this->buildPath);
$this->app['config']->set('atomic-deployments.deployments-path', $this->buildPath.'/deployments');
$this->expectsEvents(DeploymentFailed::class);
$this->expectException(InvalidPathException::class);
$failed = false;
$atomicDeployment = self::getAtomicDeployment();
$atomicDeployment->deploy(fn () => '', function () use (&$failed) {
$failed = true;
});
$this->assertTrue($failed);
Event::assertDispatched(DeploymentFailed::class);
}
}
3 changes: 2 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ protected function setUp(): void

public function tearDown(): void
{
parent::tearDown();
$this->fileSystem->deleteDirectory(self::tmpFolder);

parent::tearDown();
}

/**
Expand Down

0 comments on commit 715e52a

Please sign in to comment.