Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set test web server root to package root directory #948

Merged
merged 5 commits into from
Feb 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions tests/BuiltInWebServerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ abstract class BuiltInWebServerAbstract extends TestCase

public static function setUpBeforeClass()
{
if (!file_exists(getcwd().'/coverage/')) {
mkdir(getcwd().'/coverage/', 0777, true);
if (!file_exists($coverage = self::getPackagePath('coverage'))) {
mkdir($coverage, 0777, true);
}

if (!file_exists(getcwd().'/demos/coverage.php')) {
if (!file_exists($demosCoverage = self::getPackagePath('demos', 'coverage.php'))) {
file_put_contents(
implode(DIRECTORY_SEPARATOR, [dirname(__DIR__), 'demos', 'coverage.php']),
file_get_contents(implode(DIRECTORY_SEPARATOR, [dirname(__DIR__), 'tools', 'coverage.php']))
$demosCoverage,
file_get_contents(self::getPackagePath('tools', 'coverage.php'))
);
}

// The command to spin up the server
self::$process = Process::fromShellCommandline('php -S '.self::$host.':'.self::$port.' -t '.getcwd());
self::$process = Process::fromShellCommandline('php -S '.self::$host.':'.self::$port.' -t '. self::getPackagePath());

// Disabling the output, otherwise the process might hang after too much output
self::$process->disableOutput();
Expand All @@ -49,11 +49,31 @@ public static function setUpBeforeClass()

public static function tearDownAfterClass()
{
if (file_exists(getcwd().'/demos/coverage.php')) {
unlink(getcwd().'/demos/coverage.php');
if (file_exists($file = self::getPackagePath('demos', 'coverage.php'))) {
unlink($file);
}
}

/**
* Generates absolute file or directory path based on package root directory
* Returns absolute path to package root durectory if no arguments
*
* @param string $directory
* @param string $_
*
* @return string
*/
private static function getPackagePath($directory = null, $_ = null): string
{
$route = func_get_args();

$baseDir = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..');

array_unshift($route, $baseDir);

return implode(DIRECTORY_SEPARATOR, $route);
}

private function getClient(): Client
{
// Creating a Guzzle Client with the base_uri, so we can use a relative
Expand Down