|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/* |
| 3 | + * This file is part of PHPUnit. |
| 4 | + * |
| 5 | + * (c) Sebastian Bergmann <sebastian@phpunit.de> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | +namespace PHPUnit\Event\TestSuite; |
| 11 | + |
| 12 | +use PHPUnit\Event\Code\TestCollection; |
| 13 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 14 | +use PHPUnit\Framework\Attributes\Small; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +#[CoversClass(TestSuite::class)] |
| 18 | +#[CoversClass(TestSuiteForTestClass::class)] |
| 19 | +#[CoversClass(TestSuiteForTestMethodWithDataProvider::class)] |
| 20 | +#[CoversClass(TestSuiteWithName::class)] |
| 21 | +#[Small] |
| 22 | +final class TestSuiteTest extends TestCase |
| 23 | +{ |
| 24 | + public function testCanBeTestSuiteForTestClass(): void |
| 25 | + { |
| 26 | + $className = 'ExampleTest'; |
| 27 | + $size = 0; |
| 28 | + $tests = TestCollection::fromArray([]); |
| 29 | + $file = 'ExampleTest.php'; |
| 30 | + $line = 1; |
| 31 | + |
| 32 | + $testSuite = new TestSuiteForTestClass($className, $size, $tests, $file, $line); |
| 33 | + |
| 34 | + $this->assertTrue($testSuite->isForTestClass()); |
| 35 | + $this->assertFalse($testSuite->isForTestMethodWithDataProvider()); |
| 36 | + $this->assertFalse($testSuite->isWithName()); |
| 37 | + |
| 38 | + $this->assertSame($className, $testSuite->className()); |
| 39 | + $this->assertSame($className, $testSuite->name()); |
| 40 | + $this->assertSame($size, $testSuite->count()); |
| 41 | + $this->assertSame($tests, $testSuite->tests()); |
| 42 | + $this->assertSame($file, $testSuite->file()); |
| 43 | + $this->assertSame($line, $testSuite->line()); |
| 44 | + } |
| 45 | + |
| 46 | + public function testCanBeTestSuiteForTestMethodWithDataProvider(): void |
| 47 | + { |
| 48 | + $name = 'ExampleTest::testOne'; |
| 49 | + $className = 'ExampleTest'; |
| 50 | + $methodName = 'testOne'; |
| 51 | + $size = 0; |
| 52 | + $tests = TestCollection::fromArray([]); |
| 53 | + $file = 'ExampleTest.php'; |
| 54 | + $line = 1; |
| 55 | + |
| 56 | + $testSuite = new TestSuiteForTestMethodWithDataProvider($name, $size, $tests, $className, $methodName, $file, $line); |
| 57 | + |
| 58 | + $this->assertFalse($testSuite->isForTestClass()); |
| 59 | + $this->assertTrue($testSuite->isForTestMethodWithDataProvider()); |
| 60 | + $this->assertFalse($testSuite->isWithName()); |
| 61 | + |
| 62 | + $this->assertSame($name, $testSuite->name()); |
| 63 | + $this->assertSame($className, $testSuite->className()); |
| 64 | + $this->assertSame($methodName, $testSuite->methodName()); |
| 65 | + $this->assertSame($size, $testSuite->count()); |
| 66 | + $this->assertSame($tests, $testSuite->tests()); |
| 67 | + $this->assertSame($file, $testSuite->file()); |
| 68 | + $this->assertSame($line, $testSuite->line()); |
| 69 | + } |
| 70 | + |
| 71 | + public function testCanBeTestSuiteWithName(): void |
| 72 | + { |
| 73 | + $name = 'the-name'; |
| 74 | + $size = 0; |
| 75 | + $tests = TestCollection::fromArray([]); |
| 76 | + |
| 77 | + $testSuite = new TestSuiteWithName($name, $size, $tests); |
| 78 | + |
| 79 | + $this->assertFalse($testSuite->isForTestClass()); |
| 80 | + $this->assertFalse($testSuite->isForTestMethodWithDataProvider()); |
| 81 | + $this->assertTrue($testSuite->isWithName()); |
| 82 | + |
| 83 | + $this->assertSame($name, $testSuite->name()); |
| 84 | + $this->assertSame($size, $testSuite->count()); |
| 85 | + $this->assertSame($tests, $testSuite->tests()); |
| 86 | + } |
| 87 | +} |
0 commit comments