-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement support for
brianium/paratest
package to run tests …
…in different workers;
- Loading branch information
Showing
10 changed files
with
125 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Support/PHPUnit/EventSubscribers/ApplicationFinishedSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace RonasIT\AutoDoc\Support\PHPUnit\EventSubscribers; | ||
|
||
use Illuminate\Contracts\Console\Kernel; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Support\Facades\ParallelTesting; | ||
use PHPUnit\Event\Application\Finished; | ||
use PHPUnit\Event\Application\FinishedSubscriber; | ||
use RonasIT\AutoDoc\Services\SwaggerService; | ||
|
||
final class ApplicationFinishedSubscriber implements FinishedSubscriber | ||
{ | ||
public function notify(Finished $event): void | ||
{ | ||
$this->createApplication(); | ||
|
||
if ($this->isReadyToSaveProductionData()) { | ||
app(SwaggerService::class)->saveProductionData(); | ||
} | ||
} | ||
|
||
protected function createApplication(): void | ||
{ | ||
$app = require Application::inferBasePath() . '/bootstrap/app.php'; | ||
|
||
$app->loadEnvironmentFrom('.env.testing'); | ||
$app->make(Kernel::class)->bootstrap(); | ||
} | ||
|
||
protected function isReadyToSaveProductionData(): bool | ||
{ | ||
if ($token = ParallelTesting::token()) { | ||
unlink(config('auto-doc.tmp_dir') . "/worker_{$token}_in_progress.flag"); | ||
|
||
if (empty(glob(config('auto-doc.tmp_dir') . '/worker_*_in_progress.flag'))) { | ||
$this->mergeTempDocumentation(); | ||
|
||
return true; | ||
} | ||
} else { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected function mergeTempDocumentation(): void | ||
{ | ||
$swaggerService = app(SwaggerService::class); | ||
|
||
$resultDoc = []; | ||
|
||
$tmpPaths = glob(config('auto-doc.tmp_dir') . '/temp_documentation_*.json'); | ||
|
||
foreach ($tmpPaths as $tmpDocFilePath) { | ||
$tmpDoc = json_decode(file_get_contents($tmpDocFilePath), true); | ||
|
||
if (empty($resultDoc)) { | ||
$resultDoc = $tmpDoc; | ||
} else { | ||
$swaggerService->mergeOpenAPIDocs($resultDoc, $tmpDoc); | ||
} | ||
} | ||
|
||
$swaggerService->saveTmpData($resultDoc); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Support/PHPUnit/EventSubscribers/ApplicationStartedSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace RonasIT\AutoDoc\Support\PHPUnit\EventSubscribers; | ||
|
||
use Illuminate\Contracts\Console\Kernel; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Support\Facades\ParallelTesting; | ||
use PHPUnit\Event\Application\Started; | ||
use PHPUnit\Event\Application\StartedSubscriber; | ||
|
||
final class ApplicationStartedSubscriber implements StartedSubscriber | ||
{ | ||
public function notify(Started $event): void | ||
{ | ||
$this->createApplication(); | ||
|
||
if ($token = ParallelTesting::token()) { | ||
touch(config('auto-doc.tmp_dir') . "/worker_{$token}_in_progress.flag"); | ||
} | ||
} | ||
|
||
protected function createApplication(): void | ||
{ | ||
$app = require Application::inferBasePath() . '/bootstrap/app.php'; | ||
|
||
$app->loadEnvironmentFrom('.env.testing'); | ||
$app->make(Kernel::class)->bootstrap(); | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
src/Support/PHPUnit/EventSubscribers/SwaggerSaveDocumentationSubscriber.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters