1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Runner;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestCaseTest;
use PHPUnit\Framework\TestResult;
use PHPUnit\Framework\TestSuite;
use PHPUnit\TestFixture\EmptyTestCaseTest;
use PHPUnit\TestFixture\Failure;
use PHPUnit\TestFixture\Success;
use PHPUnit\TestFixture\TestError;
use PHPUnit\TestFixture\TestIncomplete;
use PHPUnit\TestFixture\TestRisky;
use PHPUnit\TestFixture\TestSkipped;
use PHPUnit\TestFixture\TestWarning;
/**
* @group test-reorder
* @small
*/
final class ResultCacheExtensionTest extends TestCase
{
/**
* @var DefaultTestResultCache
*/
protected $cache;
/**
* @var ResultCacheExtension
*/
protected $extension;
/**
* @var TestResult
*/
protected $result;
protected function setUp(): void
{
$this->cache = new DefaultTestResultCache;
$this->extension = new ResultCacheExtension($this->cache);
$listener = new TestListenerAdapter;
$listener->add($this->extension);
$this->result = new TestResult;
$this->result->addListener($listener);
}
/**
* @testdox Clean up test name $_dataName
* @dataProvider longTestNamesDataprovider
*/
public function testStripsDataproviderParametersFromTestName(string $testName, string $expectedTestName): void
{
$test = new TestCaseTest($testName);
$test->run($this->result);
$this->assertSame(BaseTestRunner::STATUS_ERROR, $this->cache->getState($expectedTestName));
}
public function longTestNamesDataprovider(): array
{
return [
'ClassName::testMethod' => [
'testSomething',
TestCaseTest::class . '::testSomething', ],
'ClassName::testMethod and data set number and vardump' => [
'testMethod with data set #123 (\'a\', "A", 0, false)',
TestCaseTest::class . '::testMethod with data set #123', ],
'ClassName::testMethod and data set name and vardump' => [
'testMethod with data set "data name" (\'a\', "A\", 0, false)',
TestCaseTest::class . '::testMethod with data set "data name"', ],
];
}
public function testError(): void
{
$test = new TestError('test_name');
$test->run($this->result);
$this->assertSame(BaseTestRunner::STATUS_ERROR, $this->cache->getState(TestError::class . '::test_name'));
}
public function testFailure(): void
{
$test = new Failure('test_name');
$test->run($this->result);
$this->assertSame(BaseTestRunner::STATUS_FAILURE, $this->cache->getState(Failure::class . '::test_name'));
}
public function testSkipped(): void
{
$test = new TestSkipped('test_name');
$test->run($this->result);
$this->assertSame(BaseTestRunner::STATUS_SKIPPED, $this->cache->getState(TestSkipped::class . '::test_name'));
}
public function testIncomplete(): void
{
$test = new TestIncomplete('test_name');
$test->run($this->result);
$this->assertSame(BaseTestRunner::STATUS_INCOMPLETE, $this->cache->getState(TestIncomplete::class . '::test_name'));
}
public function testPassedTestsOnlyCacheTime(): void
{
$test = new Success('test_name');
$test->run($this->result);
$this->assertSame(BaseTestRunner::STATUS_UNKNOWN, $this->cache->getState(Success::class . '::test_name'));
}
public function testWarning(): void
{
$test = new TestWarning('test_name');
$test->run($this->result);
$this->assertSame(BaseTestRunner::STATUS_WARNING, $this->cache->getState(TestWarning::class . '::test_name'));
}
public function testRisky(): void
{
$test = new TestRisky('test_name');
$test->run($this->result);
$this->assertSame(BaseTestRunner::STATUS_RISKY, $this->cache->getState(TestRisky::class . '::test_name'));
}
public function testEmptySuite(): void
{
$suite = new TestSuite;
$suite->addTestSuite(EmptyTestCaseTest::class);
$suite->run($this->result);
$this->assertSame(BaseTestRunner::STATUS_WARNING, $this->cache->getState('Warning'));
}
}
|