Skip to content

Commit

Permalink
set test web server root to package root directory (#948)
Browse files Browse the repository at this point in the history
* set test web server root to package root directory

* fix styling

* fix coverage filename

* simplify to only one method

* fix styling
  • Loading branch information
georgehristov authored Feb 12, 2020
1 parent acf781f commit 86109e0
Showing 1 changed file with 28 additions and 8 deletions.
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

0 comments on commit 86109e0

Please sign in to comment.