diff options
author | Mario <mario@mariovavti.com> | 2024-04-30 06:59:20 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-04-30 06:59:20 +0000 |
commit | ce15852b9a57a6c77531186ed24a389ebce8524e (patch) | |
tree | ad04cef0d545c5e5e24e76060b6c32d65363d48e /tests/unit/Module/TestCase.php | |
parent | 48cec945051d259a06871d937ad998a1bd3e22ec (diff) | |
parent | 7c34a3676d294c9a1acc69f71ab3061074509160 (diff) | |
download | volse-hubzilla-ce15852b9a57a6c77531186ed24a389ebce8524e.tar.gz volse-hubzilla-ce15852b9a57a6c77531186ed24a389ebce8524e.tar.bz2 volse-hubzilla-ce15852b9a57a6c77531186ed24a389ebce8524e.zip |
Merge branch 'rework-help-module' into 'dev'
Rework Help module + begin tests for Setup module
See merge request hubzilla/core!2120
Diffstat (limited to 'tests/unit/Module/TestCase.php')
-rw-r--r-- | tests/unit/Module/TestCase.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/unit/Module/TestCase.php b/tests/unit/Module/TestCase.php new file mode 100644 index 000000000..aa09e0596 --- /dev/null +++ b/tests/unit/Module/TestCase.php @@ -0,0 +1,74 @@ +<?php + +namespace Zotlabs\Tests\Unit\Module; + +class TestCase extends \Zotlabs\Tests\Unit\UnitTestCase { + + // Import PHPMock methods into this class + use \phpmock\phpunit\PHPMock; + + /** + * Emulate a GET request. + * + * @param string $uri The URI to request. Typically this will be the module + * name, followed by any req args separated by slashes. + */ + protected function get(string $uri): void { + $_GET['q'] = $uri; + $_SERVER['REQUEST_METHOD'] = 'GET'; + + \App::init(); + \App::$page['content'] = ''; + + $router = new \Zotlabs\Web\Router(); + $router->Dispatch(); + } + + /** + * Stub out the `killme` function. + * + * Usefule for modules that call this function directly. + * + * Instead of calling exit, the stub will throw a `KillmeException`, + * that can be caught by the test code to regain control after request + * processing is terminated. + */ + protected function stub_killme(): void { + $killme_stub = $this->getFunctionMock('Zotlabs\Module', 'killme'); + $killme_stub + ->expects($this->once()) + ->willReturnCallback( + function () { + throw new KillmeException(); + } + ); + } + + protected function stub_goaway(): void { + $goaway_stub = $this->getFunctionMock('Zotlabs\Module', 'goaway'); + $goaway_stub + ->expects($this->once()) + ->willReturnCallback( + function (string $uri) { + throw new RedirectException($uri); + } + ); + } +} + +/** + * Exception class for killme stub + */ +class KillmeException extends \Exception {} + +/** + * Exception class for goaway stub. + * + * Takes the goaway uri as an arg, and makes it available as + * the public `$uri` member variable. + */ +class RedirectException extends \Exception { + function __construct(string $uri) { + parent::__construct($uri); + } +} |