diff --git a/composer.json b/composer.json index 5c7ba8e..e6f98cd 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,7 @@ "autoload": { "classmap": ["App.php","SeacmsAppPlugin.php"], "psr-4": { + "SeaCMS\\App\\Test\\": "tests", "SeaCMS\\App\\": "src" } }, diff --git a/tests/AppTest.php b/tests/AppTest.php index f207b99..4aa797d 100644 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -8,12 +8,18 @@ namespace SeaCMS\App\Test; use SeaCMS\App; -use PHPUnit\Framework\TestCase; +use SeaCMS\App\Test\Common; -final class AppTest extends TestCase { +final class AppTest extends Common { public function testSuccess(): void { + $this->defineServer( + true, + 'index.php', + '/', + '' + ); $app = new App(''); $output = $app->runPico(); $this->assertTrue($app instanceof App); diff --git a/tests/Common.php b/tests/Common.php new file mode 100644 index 0000000..ca5d756 --- /dev/null +++ b/tests/Common.php @@ -0,0 +1,136 @@ + false, + 'value' => null + ]; + } + if (!$GLOBALS['savedSERVER']['saved']){ + if (!isset($_SERVER)){ + $GLOBALS['savedSERVER']['value'] = null; + $GLOBALS['savedSERVER']['saved'] = true; + } else { + $GLOBALS['savedSERVER']['value'] = $_SERVER; + $GLOBALS['savedSERVER']['saved'] = true; + } + } + } + + /** + * revert previous $_SERVER in $GLOBALS if existing + */ + public function revertSERVER() + { + if (isset($GLOBALS['savedSERVER']['saved']) && $GLOBALS['savedSERVER']['saved']){ + if (is_null($GLOBALS['savedSERVER']['value'])){ + unset($_SERVER); + } else { + $_SERVER = $GLOBALS['savedSERVER']['value']; + } + $GLOBALS['savedSERVER']['saved'] = false; + $GLOBALS['savedSERVER']['value'] = null; + } + } +} \ No newline at end of file