PerformanceFileTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Test\Depo\UniTester;
  3. use Depo\UniTester\TestCase;
  4. class PerformanceFileTest extends TestCase
  5. {
  6. protected function setUp(): void
  7. {
  8. // Create a temporary file for testing
  9. file_put_contents(__DIR__ . '/temp_test_file.txt', 'content');
  10. }
  11. protected function tearDown(): void
  12. {
  13. // Clean up
  14. if (file_exists(__DIR__ . '/temp_test_file.txt')) {
  15. unlink(__DIR__ . '/temp_test_file.txt');
  16. }
  17. }
  18. protected function execute(): void
  19. {
  20. $this->log("Testing Performance Assertions...");
  21. // Test Execution Time
  22. $this->assertExecutionTimeLessThan(100, function() {
  23. usleep(10000); // 10ms
  24. }, "Execution time should be less than 100ms");
  25. // Test Memory Usage
  26. $this->assertMemoryUsageLessThan(1024 * 1024, function() {
  27. $a = str_repeat('a', 1024); // 1KB
  28. }, "Memory usage should be less than 1MB");
  29. $this->log("Testing File Assertions...");
  30. $tempFile = __DIR__ . '/temp_test_file.txt';
  31. $this->assertFileExists($tempFile);
  32. $this->assertFileNotExists(__DIR__ . '/non_existent_file.txt');
  33. $this->assertDirectoryExists(__DIR__);
  34. $this->assertIsReadable($tempFile);
  35. $this->assertIsWritable($tempFile);
  36. $this->log("All new assertions passed!");
  37. }
  38. }