From bbc6a95d63c197e208c264341e71fcfa38f9339a Mon Sep 17 00:00:00 2001 From: he426100 <{ID}+{username}@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:29:36 +0800 Subject: [PATCH] adapt phpunit for windows --- tests/phpunit/CoreTest.php | 26 +++++++++++++------------- tests/phpunit/IterTest.php | 6 +++--- tests/phpunit/ModuleTest.php | 6 +++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/phpunit/CoreTest.php b/tests/phpunit/CoreTest.php index 41e8db1..f0ae25a 100644 --- a/tests/phpunit/CoreTest.php +++ b/tests/phpunit/CoreTest.php @@ -24,9 +24,9 @@ public function testStr() public function testRepr() { - $os = PyCore::import("os"); - $repr = PyCore::repr($os->uname()); - $this->assertStringContainsString('posix.uname_result', $repr); + $platform = PyCore::import("platform"); + $repr = PyCore::repr($platform->uname()); + $this->assertStringContainsString('uname_result', $repr); } public function testId() @@ -37,9 +37,9 @@ public function testId() public function testType() { - $os = PyCore::import("os"); - $this->assertEquals("", PyCore::type($os)); - $this->assertEquals("", PyCore::type($os->uname())); + $platform = PyCore::import("platform"); + $this->assertEquals("", PyCore::type($platform)); + $this->assertEquals("", PyCore::type($platform->uname())); $dict = new PyDict(); $this->assertEquals("", PyCore::type($dict)); @@ -56,17 +56,17 @@ function testHash() function testHasAttr() { - $os = PyCore::import("os"); - $this->assertTrue(PyCore::hasattr($os, 'uname')); - $this->assertFalse(PyCore::hasattr($os, 'not_exists')); + $platform = PyCore::import("platform"); + $this->assertTrue(PyCore::hasattr($platform, 'uname')); + $this->assertFalse(PyCore::hasattr($platform, 'not_exists')); } function testLen() { - $os = PyCore::import("os"); - $uname = $os->uname(); - $this->assertEquals(5, PyCore::len($uname)); - $this->assertGreaterThan(100, strlen(PyCore::str($uname))); + $platform = PyCore::import("platform"); + $uname = $platform->uname(); + $this->assertGreaterThan(5, PyCore::len($uname)); + $this->assertGreaterThan(90, strlen(PyCore::str($uname))); $n = 14; $list = new PyList; diff --git a/tests/phpunit/IterTest.php b/tests/phpunit/IterTest.php index b5e2097..41ed4b6 100644 --- a/tests/phpunit/IterTest.php +++ b/tests/phpunit/IterTest.php @@ -6,8 +6,8 @@ class IterTest extends TestCase { function testIter() { - $os = PyCore::import('os'); - $uname = $os->uname(); + $platform = PyCore::import('platform'); + $uname = $platform->uname(); $iter = PyCore::iter($uname); $this->assertTrue($iter instanceof PyIter); @@ -17,7 +17,7 @@ function testIter() $list[] = PyCore::scalar($next); } $this->assertIsArray($list); - $this->assertEquals(count($list), 5); + $this->assertGreaterThanOrEqual(5, count($list)); } function testNewIter() diff --git a/tests/phpunit/ModuleTest.php b/tests/phpunit/ModuleTest.php index 0a32f67..47e9ad2 100644 --- a/tests/phpunit/ModuleTest.php +++ b/tests/phpunit/ModuleTest.php @@ -7,9 +7,9 @@ class ModuleTest extends TestCase { public function testImport() { - $os = PyLoader::import('os'); - $uname = $os->uname(); - $this->assertEquals($uname->sysname, 'Linux'); + $platform = PyLoader::import('platform'); + $uname = $platform->uname(); + $this->assertStringContainsStringIgnoringCase([PHP_OS, 'WIN'][str_starts_with(PHP_OS, 'WIN')], (string)$uname->system); } public function testNewObject()