From dc9d6703bc70b8961372a592df1a3518a09d7579 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 3 Oct 2024 10:45:05 +0800 Subject: [PATCH] Fix phpstan, add more phpunit test --- phpstan.neon | 3 +- phpunit.xml.dist | 5 ++ tests/SPC/builder/BuilderProviderTest.php | 28 +++++++ tests/SPC/builder/ExtensionTest.php | 91 +++++++++++++++++++++++ tests/bootstrap.php | 5 ++ 5 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 phpunit.xml.dist create mode 100644 tests/SPC/builder/BuilderProviderTest.php create mode 100644 tests/SPC/builder/ExtensionTest.php create mode 100644 tests/bootstrap.php diff --git a/phpstan.neon b/phpstan.neon index 241a8dbb..1fcd78e5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,7 +4,6 @@ parameters: paths: - ./src/ ignoreErrors: - - '#Constant .* not found#' - '#Unsafe usage of new static#' - '#class Fiber#' - '#Attribute class JetBrains\\PhpStorm\\ArrayShape does not exist#' @@ -15,4 +14,4 @@ parameters: analyseAndScan: - ./src/globals/ext-tests/swoole.php - ./src/globals/ext-tests/swoole.phpt - - ./src/globals/test-extensions.php \ No newline at end of file + - ./src/globals/test-extensions.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 00000000..9b045629 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/tests/SPC/builder/BuilderProviderTest.php b/tests/SPC/builder/BuilderProviderTest.php new file mode 100644 index 00000000..52a0d35d --- /dev/null +++ b/tests/SPC/builder/BuilderProviderTest.php @@ -0,0 +1,28 @@ +assertInstanceOf(BuilderBase::class, BuilderProvider::makeBuilderByInput(new ArgvInput())); + $this->assertInstanceOf(BuilderBase::class, BuilderProvider::getBuilder()); + } +} diff --git a/tests/SPC/builder/ExtensionTest.php b/tests/SPC/builder/ExtensionTest.php new file mode 100644 index 00000000..d618980d --- /dev/null +++ b/tests/SPC/builder/ExtensionTest.php @@ -0,0 +1,91 @@ +proveLibs($libs); + $builder->proveExts($extensions); + $this->extension = $builder->getExt('mbregex'); + } + + public function testPatches() + { + $this->assertFalse($this->extension->patchBeforeBuildconf()); + $this->assertFalse($this->extension->patchBeforeConfigure()); + $this->assertFalse($this->extension->patchBeforeMake()); + } + + public function testGetExtensionDependency() + { + $this->assertEquals('mbstring', current($this->extension->getExtensionDependency())->getName()); + } + + public function testGetWindowsConfigureArg() + { + $this->assertEquals('', $this->extension->getWindowsConfigureArg()); + } + + public function testGetConfigureArg() + { + $this->assertEquals('', $this->extension->getUnixConfigureArg()); + } + + public function testGetExtVersion() + { + // only swoole has version, we cannot test it + $this->assertEquals(null, $this->extension->getExtVersion()); + } + + public function testGetDistName() + { + $this->assertEquals('mbregex', $this->extension->getName()); + } + + public function testRunCliCheckWindows() + { + if (is_unix()) { + $this->markTestIncomplete('This test is for Windows only'); + } else { + $this->extension->runCliCheckWindows(); + $this->assertTrue(true); + } + } + + public function testGetLibFilesString() + { + $this->assertStringEndsWith('libonig.a', $this->extension->getLibFilesString()); + } + + public function testGetName() + { + $this->assertEquals('mbregex', $this->extension->getName()); + } + + public function testGetUnixConfigureArg() + { + $this->assertEquals('', $this->extension->getUnixConfigureArg()); + } + + public function testGetEnableArg() + { + $this->assertEquals('', $this->extension->getEnableArg()); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..bca0084d --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,5 @@ +