From fbc79e36e04122acbd8ed719a667045e8c3dad40 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 9 Nov 2024 14:38:27 +0100 Subject: Remove import of non-existing class in test. This one snuck in by mistake. No harm done, as the actual class was never referenced, but it should still not be there. --- tests/unit/Module/AdminAccountEditTest.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/unit/Module/AdminAccountEditTest.php b/tests/unit/Module/AdminAccountEditTest.php index fe682c527..818f30f26 100644 --- a/tests/unit/Module/AdminAccountEditTest.php +++ b/tests/unit/Module/AdminAccountEditTest.php @@ -11,7 +11,6 @@ namespace Zotlabs\Tests\Unit\Module; use DateTimeImmutable; use PHPUnit\Framework\Attributes\{Before, After}; -use Zotlabs\Model\Account; class AdminAccountEditTest extends TestCase { -- cgit v1.2.3 From 57e69372d35b060dc29be2ff5527fc0ef19430e0 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 9 Nov 2024 15:45:40 +0100 Subject: Module\Item: Move processing of zot and as requests to functions. These seem to be entirely independent, so moving the body of the if statements to separate functions should be fine. --- tests/unit/Module/ItemTest.php | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/unit/Module/ItemTest.php (limited to 'tests') diff --git a/tests/unit/Module/ItemTest.php b/tests/unit/Module/ItemTest.php new file mode 100644 index 000000000..b461a3685 --- /dev/null +++ b/tests/unit/Module/ItemTest.php @@ -0,0 +1,56 @@ +expect_status(404, 'Not found'); + + $_SERVER['HTTP_ACCEPT'] = $type; + $this->get('item'); + } + + #[TestWith(['application/x-zot+json'])] + #[TestWith(['application/x-zot-activity+json'])] + public function test_request_with_non_exiting_idem_id(string $type): void { + $this->expect_status(404, 'Not found'); + + $_SERVER['HTTP_ACCEPT'] = $type; + $this->get('item/non-existing-id'); + } + + /** + * Helper function to mock the `http_status_exit` function. + * + * The request will be terminated by throwing an exception, which + * will also terminate the test case. Iow. control will not return + * to the test case after the request has been made. + * + * @param int $status The expected HTTP status code. + * @param string $description The expected HTTP status description + */ + private function expect_status(int $status, string $description): void { + $this->getFunctionMock('Zotlabs\Module', 'http_status_exit') + ->expects($this->once()) + ->with($this->identicalTo($status), $this->identicalTo($description)) + ->willReturnCallback( + function () { + throw new KillmeException(); + } + ); + + $this->expectException(KillmeException::class); + + } +} -- cgit v1.2.3