2022-12-11 00:08:59 +00:00
|
|
|
<?php /** @noinspection PhpIllegalPsrClassPathInspection */
|
|
|
|
|
|
|
|
namespace Tests;
|
2023-02-02 23:37:37 +00:00
|
|
|
use Illuminate\Support\Str;
|
2022-12-11 00:08:59 +00:00
|
|
|
use \Throwable;
|
|
|
|
use PHPUnit\Framework\TestListener;
|
|
|
|
|
|
|
|
// fixme: with phpunit 10, this should be replaced with the new event system
|
|
|
|
class IntegrationTestListener implements TestListener
|
|
|
|
{
|
2023-02-02 23:37:37 +00:00
|
|
|
private \Laravel\Lumen\Application $app;
|
2022-12-11 00:08:59 +00:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$app = require __DIR__.'/../bootstrap/app.php';
|
|
|
|
$database = env('DB_DATABASE', 'jikan_tests');
|
|
|
|
$app['config']->set('database.connections.mongodb.database', $database === 'jikan' ? 'jikan_tests' : $database);
|
2023-02-02 23:37:37 +00:00
|
|
|
$app['config']->set('jikan.micro_caching_enabled', false);
|
2022-12-11 00:08:59 +00:00
|
|
|
$this->app = $app;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addError(\PHPUnit\Framework\Test $test, Throwable $t, float $time): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, float $time): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addIncompleteTest(\PHPUnit\Framework\Test $test, Throwable $t, float $time): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addRiskyTest(\PHPUnit\Framework\Test $test, Throwable $t, float $time): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addSkippedTest(\PHPUnit\Framework\Test $test, Throwable $t, float $time): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-02 23:37:37 +00:00
|
|
|
private function isIntegrationTest(\PHPUnit\Framework\TestSuite $suite): bool
|
|
|
|
{
|
|
|
|
$suiteName = $suite->getName();
|
|
|
|
return in_array($suiteName, [
|
|
|
|
"integration", "http-integration", "Tests\HttpV4\Controllers", "Tests\Integration",
|
|
|
|
"Integration"
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-12-11 00:08:59 +00:00
|
|
|
public function startTestSuite(\PHPUnit\Framework\TestSuite $suite): void
|
|
|
|
{
|
2023-02-02 23:37:37 +00:00
|
|
|
if ($this->isIntegrationTest($suite)) {
|
2022-12-11 00:08:59 +00:00
|
|
|
$app = $this->app;
|
|
|
|
$kernel = $app->make(
|
|
|
|
'Illuminate\Contracts\Console\Kernel'
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
$kernel->call('migrate:fresh', []);
|
|
|
|
} catch (\Exception $ex) {
|
2022-12-16 10:59:18 +00:00
|
|
|
print_r($ex->getMessage());
|
2023-02-02 23:37:37 +00:00
|
|
|
throw $ex;
|
2022-12-11 00:08:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function endTestSuite(\PHPUnit\Framework\TestSuite $suite): void
|
|
|
|
{
|
2023-02-02 23:37:37 +00:00
|
|
|
if ($this->isIntegrationTest($suite)) {
|
2022-12-11 00:08:59 +00:00
|
|
|
$app = $this->app;
|
|
|
|
$kernel = $app->make(
|
|
|
|
'Illuminate\Contracts\Console\Kernel'
|
|
|
|
);
|
|
|
|
$kernel->call('migrate:rollback');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function startTest(\PHPUnit\Framework\Test $test): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function endTest(\PHPUnit\Framework\Test $test, float $time): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|