Skip to content

Commit

Permalink
test: fix guides tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Sep 13, 2023
1 parent 6c3c731 commit 2c339e4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/src/Test/TestGuideTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace ApiPlatform\Playground\Test;

use Symfony\Component\HttpKernel\KernelInterface;

trait TestGuideTrait
{
protected function setUp(): void
Expand All @@ -21,4 +23,40 @@ protected function setUp(): void
$kernel->executeMigrations();
$kernel->loadFixtures();
}

/**
* Creates a Kernel.
*
* Available options:
*
* * environment
* * debug
*/
protected static function createKernel(array $options = []): KernelInterface
{
static::$class ??= static::getKernelClass();

if (isset($options['environment'])) {
$env = $options['environment'];
} elseif (isset($_ENV['APP_ENV'])) {
$env = $_ENV['APP_ENV'];
} elseif (isset($_SERVER['APP_ENV'])) {
$env = $_SERVER['APP_ENV'];
} else {
$env = 'test';
}

if (isset($options['debug'])) {
$debug = $options['debug'];
} elseif (isset($_ENV['APP_DEBUG'])) {
$debug = $_ENV['APP_DEBUG'];
} elseif (isset($_SERVER['APP_DEBUG'])) {
$debug = $_SERVER['APP_DEBUG'];
} else {
$debug = true;
}

$guide = basename($_SERVER['argv'][1], '.php');
return new static::$class($env, $debug, $guide);
}
}

0 comments on commit 2c339e4

Please sign in to comment.