-
Notifications
You must be signed in to change notification settings - Fork 15
added Test Suite for Windows #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
M4dhav
wants to merge
1
commit into
utopia-php:main
Choose a base branch
from
M4dhav:feat-35-add-windows-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Utopia PHP Framework | ||
| * | ||
| * | ||
| * @link https://github.com/utopia-php/framework | ||
| * | ||
| * @author Eldad Fux <eldad@appwrite.io> | ||
| * | ||
| * @version 1.0 RC4 | ||
| * | ||
| * @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php> | ||
| */ | ||
|
|
||
| namespace Utopia\Tests; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Utopia\System\System; | ||
|
|
||
| class SystemTestWindows extends TestCase | ||
| { | ||
| public function setUp(): void | ||
| { | ||
| if (System::getOS() !== 'Windows NT') { | ||
| $this->markTestSkipped('Windows-specific tests can only run on Windows'); | ||
| } | ||
| } | ||
|
|
||
| public function tearDown(): void | ||
| { | ||
| } | ||
|
|
||
| public function testOs(): void | ||
| { | ||
| $this->assertEquals('Windows NT', System::getOS()); | ||
| $this->assertIsString(System::getArch()); | ||
| $this->assertIsString(System::getArchEnum()); | ||
| $this->assertIsString(System::getHostname()); | ||
| } | ||
|
|
||
| public function testGetCPUCores(): void | ||
| { | ||
| $cores = System::getCPUCores(); | ||
| $this->assertIsInt($cores); | ||
| $this->assertGreaterThan(0, $cores); | ||
| } | ||
|
|
||
| public function testGetDiskTotal(): void | ||
| { | ||
| $total = System::getDiskTotal(); | ||
| $this->assertIsInt($total); | ||
| $this->assertGreaterThan(0, $total); | ||
| } | ||
|
|
||
| public function testGetDiskFree(): void | ||
| { | ||
| $free = System::getDiskFree(); | ||
| $this->assertIsInt($free); | ||
| $this->assertGreaterThanOrEqual(0, $free); | ||
|
|
||
| // Free space should be less than or equal to total | ||
| $this->assertLessThanOrEqual(System::getDiskTotal(), $free); | ||
| } | ||
|
|
||
| public function testUnsupportedMethods(): void | ||
| { | ||
| // CPU Usage is not supported on Windows | ||
| $this->expectException(\Exception::class); | ||
| System::getCPUUsage(5); | ||
| } | ||
|
|
||
| public function testGetMemoryTotalThrowsException(): void | ||
| { | ||
| $this->expectException(\Exception::class); | ||
| System::getMemoryTotal(); | ||
| } | ||
|
|
||
| public function testGetMemoryFreeThrowsException(): void | ||
| { | ||
| $this->expectException(\Exception::class); | ||
| System::getMemoryFree(); | ||
| } | ||
|
|
||
| public function testGetIOUsageThrowsException(): void | ||
| { | ||
| try { | ||
| System::getIOUsage(); | ||
| $this->fail('Expected exception was not thrown'); | ||
| } catch (\Exception $e) { | ||
| // Expected - method tries to read /proc/diskstats which doesn't exist on Windows | ||
| $this->assertTrue(true); | ||
| } catch (\Throwable $e) { | ||
| // Also acceptable - might throw warnings/errors | ||
| $this->assertTrue(true); | ||
| } | ||
| } | ||
|
|
||
| public function testGetNetworkUsageThrowsException(): void | ||
| { | ||
| try { | ||
| System::getNetworkUsage(); | ||
| $this->fail('Expected exception was not thrown'); | ||
| } catch (\Exception $e) { | ||
| // Expected - method tries to access /sys/class/net which doesn't exist on Windows | ||
| $this->assertTrue(true); | ||
| } catch (\Throwable $e) { | ||
| // Also acceptable - might throw warnings/errors | ||
| $this->assertTrue(true); | ||
| } | ||
| } | ||
|
|
||
| public function testGetEnv(): void | ||
| { | ||
| // Test with existing Windows environment variables | ||
| $path = System::getEnv('PATH', 'DEFAULT'); | ||
| $this->assertNotEquals('DEFAULT', $path); | ||
| $this->assertIsString($path); | ||
|
|
||
| // Test with non-existent variable | ||
| $this->assertEquals('DEFAULT_VALUE', System::getEnv('NON_EXISTENT_VAR_12345', 'DEFAULT_VALUE')); | ||
| $this->assertNull(System::getEnv('NON_EXISTENT_VAR_12345')); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning 0 cores is misleading; throw an exception instead.
When
preg_match_allfinds no numeric matches, returning 0 is incorrect—no system has zero CPU cores. Throwing an exception would be consistent with the null-output case and more reliable for error handling.Additionally, WMIC is deprecated as of Windows 10 version 21H1 and will be removed from Windows 11 version 25H2. Use PowerShell with WMI interfaces instead via
shell_exec()for better long-term compatibility.🔎 Proposed fix
// Parse output - wmic returns header line and value(s) preg_match_all('/\d+/', $output, $matches); - return !empty($matches[0]) ? intval($matches[0][0]) : 0; + if (empty($matches[0])) { + throw new Exception('Unable to parse CPU cores from wmic output'); + } + return intval($matches[0][0]);