feat(tests): add them first step
This commit is contained in:
parent
0ad57c277f
commit
804ddb76d4
5
App.php
5
App.php
@ -11,6 +11,7 @@ use Exception;
|
|||||||
use Pico;
|
use Pico;
|
||||||
use SeacmsAppPlugin;
|
use SeacmsAppPlugin;
|
||||||
use SeaCMS\Api\SpecialOutputException;
|
use SeaCMS\Api\SpecialOutputException;
|
||||||
|
use SeaCMS\App\TestInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
set_error_handler(function (
|
set_error_handler(function (
|
||||||
@ -51,7 +52,7 @@ class App
|
|||||||
*/
|
*/
|
||||||
protected $pico;
|
protected $pico;
|
||||||
|
|
||||||
public function __construct(string $contentFolderFromRoot)
|
public function __construct(string $contentFolderFromRoot, ?TestInterface $testRunner = null)
|
||||||
{
|
{
|
||||||
// sanitize content folder
|
// sanitize content folder
|
||||||
$cwd = getcwd();
|
$cwd = getcwd();
|
||||||
@ -76,7 +77,7 @@ class App
|
|||||||
self::PLUGINS_PATH, // plugins dir
|
self::PLUGINS_PATH, // plugins dir
|
||||||
self::THEMES_PATH // themes dir
|
self::THEMES_PATH // themes dir
|
||||||
);
|
);
|
||||||
$this->pico->loadPlugin(new SeacmsAppPlugin($this->pico));
|
$this->pico->loadPlugin(new SeacmsAppPlugin($this->pico, $testRunner));
|
||||||
$this->update_SERVERIfNeeded($this->pico, $contentFolderFromRoot);
|
$this->update_SERVERIfNeeded($this->pico, $contentFolderFromRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
use SeaCMS\Api\LateApiAware;
|
use SeaCMS\Api\LateApiAware;
|
||||||
use SeaCMS\Api\JsonResponse;
|
use SeaCMS\Api\JsonResponse;
|
||||||
use SeaCMS\App\MdResponse;
|
use SeaCMS\App\MdResponse;
|
||||||
|
use SeaCMS\App\TestInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A plugin for SeaCMS-app.
|
* A plugin for SeaCMS-app.
|
||||||
@ -17,6 +18,30 @@ class SeacmsAppPlugin extends AbstractPicoPlugin implements LateApiAware
|
|||||||
*/
|
*/
|
||||||
const API_VERSION = 4;
|
const API_VERSION = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* define if test output should be defined
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $triggerTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* define test
|
||||||
|
* @var TestInterface
|
||||||
|
*/
|
||||||
|
protected $testRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* construct
|
||||||
|
* @param Pico $pico current instance of Pico
|
||||||
|
* @param ?TestInterface $testRunner optional
|
||||||
|
*/
|
||||||
|
public function __construct(Pico $pico, $testRunner = null)
|
||||||
|
{
|
||||||
|
parent::__construct($pico);
|
||||||
|
$this->triggerTest = !empty($testRunner) && ($testRunner instanceof TestInterface);
|
||||||
|
$this->testRunner = ($this->triggerTest) ? $testRunner : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return api routes
|
* return api routes
|
||||||
* @return array
|
* @return array
|
||||||
@ -136,4 +161,16 @@ class SeacmsAppPlugin extends AbstractPicoPlugin implements LateApiAware
|
|||||||
return $this->apiPageAsMd("$folder1/$folder2/$folder3/$pageName");
|
return $this->apiPageAsMd("$folder1/$folder2/$folder3/$pageName");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered after Pico has rendered the page
|
||||||
|
*
|
||||||
|
* @param string &$output contents which will be sent to the user
|
||||||
|
*/
|
||||||
|
public function onPageRendered(&$output)
|
||||||
|
{
|
||||||
|
if ($this->triggerTest){
|
||||||
|
$this->testRunner->run($this,$output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
14
src/TestException.php
Normal file
14
src/TestException.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
// SPDX-License-Identifier: EUPL-1.2
|
||||||
|
// Authors: see README.md
|
||||||
|
|
||||||
|
namespace SeaCMS\App;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use SeaCMS\App\TestException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* define exception to caught return for tests
|
||||||
|
*/
|
||||||
|
class TestException extends Exception
|
||||||
|
{}
|
22
src/TestInterface.php
Normal file
22
src/TestInterface.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
// SPDX-License-Identifier: EUPL-1.2
|
||||||
|
// Authors: see README.md
|
||||||
|
|
||||||
|
namespace SeaCMS\App;
|
||||||
|
|
||||||
|
use SeacmsAppPlugin;
|
||||||
|
use SeaCMS\App\TestException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* define interface for tests
|
||||||
|
*/
|
||||||
|
interface TestInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* run tests
|
||||||
|
* @param SeacmsAppPlugin $plugin
|
||||||
|
* @param string $output
|
||||||
|
* @throws TestException
|
||||||
|
*/
|
||||||
|
public function run(SeacmsAppPlugin $plugin, string $output);
|
||||||
|
}
|
25
tests/AppTest.php
Normal file
25
tests/AppTest.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SPDX-License-Identifier: EUPL-1.2
|
||||||
|
* Authors: see /README.md
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace SeaCMS\App\Test;
|
||||||
|
|
||||||
|
use SeaCMS\App;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
final class AppTest extends TestCase {
|
||||||
|
|
||||||
|
public function testSuccess(): void
|
||||||
|
{
|
||||||
|
$app = new App('');
|
||||||
|
$output = $app->runPico();
|
||||||
|
$this->assertTrue($app instanceof App);
|
||||||
|
}
|
||||||
|
public function testFailure(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(false);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user