|
8 | 8 |
|
9 | 9 | class UnitCiTest extends TestCase |
10 | 10 | { |
11 | | - public function testCi(): void |
12 | | - { |
13 | | - if (file_exists('coverage/index.xml')) { |
14 | | - $returnCheck = shell_exec('php ./src/CI.php coverage/index.xml 80'); |
15 | | - self::assertStringContainsString('[PASS]', ($returnCheck ?: '')); |
16 | | - } else { |
17 | | - $file = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'CI.php'; |
18 | | - self::assertFileIsReadable($file, "filename doesn't exists"); |
| 11 | + private const CI_SCRIPT = './src/CI.php'; |
| 12 | + private const COVERAGE_FILE = 'coverage/index.xml'; |
| 13 | + |
| 14 | + public function testCiFileExists(): void |
| 15 | + { |
| 16 | + $file = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'CI.php'; |
| 17 | + self::assertFileIsReadable($file); |
| 18 | + } |
| 19 | + |
| 20 | + public function testCiPassWithValidCoverage(): void |
| 21 | + { |
| 22 | + if (!file_exists(self::COVERAGE_FILE)) { |
| 23 | + self::markTestSkipped('Coverage file not found'); |
| 24 | + } |
| 25 | + $returnCheck = shell_exec('php ' . self::CI_SCRIPT . ' ' . self::COVERAGE_FILE . ' 80'); |
| 26 | + self::assertStringContainsString('[PASS]', ($returnCheck ?: '')); |
| 27 | + } |
| 28 | + |
| 29 | + public function testCiPassWithZeroThreshold(): void |
| 30 | + { |
| 31 | + if (!file_exists(self::COVERAGE_FILE)) { |
| 32 | + self::markTestSkipped('Coverage file not found'); |
| 33 | + } |
| 34 | + $returnCheck = shell_exec('php ' . self::CI_SCRIPT . ' ' . self::COVERAGE_FILE . ' 0'); |
| 35 | + self::assertStringContainsString('[PASS]', ($returnCheck ?: '')); |
| 36 | + } |
| 37 | + |
| 38 | + public function testCiFailWithHighThreshold(): void |
| 39 | + { |
| 40 | + if (!file_exists(self::COVERAGE_FILE)) { |
| 41 | + self::markTestSkipped('Coverage file not found'); |
| 42 | + } |
| 43 | + exec('php ' . self::CI_SCRIPT . ' ' . self::COVERAGE_FILE . ' 100.1 2>&1', $output, $exitCode); |
| 44 | + $result = implode("\n", $output); |
| 45 | + self::assertStringContainsString('[FAIL]', $result); |
| 46 | + self::assertNotEquals(0, $exitCode); |
| 47 | + } |
| 48 | + |
| 49 | + public function testCiWithoutArguments(): void |
| 50 | + { |
| 51 | + exec('php ' . self::CI_SCRIPT . ' 2>&1', $output, $exitCode); |
| 52 | + $result = implode("\n", $output); |
| 53 | + self::assertStringContainsString('Usage:', $result); |
| 54 | + self::assertEquals(255, $exitCode); |
| 55 | + } |
| 56 | + |
| 57 | + public function testCiWithOnlyOneArgument(): void |
| 58 | + { |
| 59 | + exec('php ' . self::CI_SCRIPT . ' ' . self::COVERAGE_FILE . ' 2>&1', $output, $exitCode); |
| 60 | + $result = implode("\n", $output); |
| 61 | + self::assertStringContainsString('Usage:', $result); |
| 62 | + self::assertEquals(255, $exitCode); |
| 63 | + } |
| 64 | + |
| 65 | + public function testCiWithInvalidFile(): void |
| 66 | + { |
| 67 | + exec('php ' . self::CI_SCRIPT . ' nonexistent.xml 80 2>&1', $output, $exitCode); |
| 68 | + self::assertNotEquals(0, $exitCode); |
| 69 | + } |
| 70 | + |
| 71 | + public function testCiWithFloatThreshold(): void |
| 72 | + { |
| 73 | + if (!file_exists(self::COVERAGE_FILE)) { |
| 74 | + self::markTestSkipped('Coverage file not found'); |
19 | 75 | } |
| 76 | + $returnCheck = shell_exec('php ' . self::CI_SCRIPT . ' ' . self::COVERAGE_FILE . ' 50.5'); |
| 77 | + self::assertStringContainsString('[PASS]', ($returnCheck ?: '')); |
20 | 78 | } |
21 | 79 | } |
0 commit comments