From 7e3ff6178cde6d5605d8400e6959fc720fc763d5 Mon Sep 17 00:00:00 2001 From: terremoth Date: Wed, 11 Dec 2024 21:41:37 -0300 Subject: [PATCH] Start unit/integration tests --- tests/Terremoth/AsyncTest/PhpFileTest.php | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/Terremoth/AsyncTest/PhpFileTest.php diff --git a/tests/Terremoth/AsyncTest/PhpFileTest.php b/tests/Terremoth/AsyncTest/PhpFileTest.php new file mode 100644 index 0000000..721e13b --- /dev/null +++ b/tests/Terremoth/AsyncTest/PhpFileTest.php @@ -0,0 +1,57 @@ +expectException(Exception::class); + $tempFile = tmpfile(); + $htmlString = '

Hello World

'; + fwrite($tempFile, $htmlString); + $path = stream_get_meta_data($tempFile)['uri']; + $phpFile = new PhpFile($path); + $phpFile->run(); + fclose($tempFile); + unlink($path); + } + + /** + * @throws InvalidArgumentException|Exception + */ + #[Test] + #[CoversNothing] + public function shouldOnlyAcceptReadablePhpFiles(): void + { + $this->expectException(InvalidArgumentException::class); + + if (PHP_OS_FAMILY == 'Windows') { + $this->expectException(Exception::class); + } + + $tempFile = tmpfile(); + $htmlString = '

Hello World

'; + fwrite($tempFile, $htmlString); + $path = stream_get_meta_data($tempFile)['uri']; + $writeAndExecOnly = 0330; + chmod($path, $writeAndExecOnly); // set as only write and exec, not readable + $phpFile = new PhpFile($path); + $phpFile->run(); + fclose($tempFile); + unlink($path); + } +}