Skip to content

Commit cdaeb14

Browse files
Add tests that capture the status-quo for when exceptions are raised tearDown() and tearDownAfterClass()
1 parent de0c82c commit cdaeb14

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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\TestFixture\Event;
11+
12+
use Exception;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class ExceptionInTearDownAfterClassTest extends TestCase
16+
{
17+
public static function tearDownAfterClass(): void
18+
{
19+
throw new Exception;
20+
}
21+
22+
public function testOne(): void
23+
{
24+
$this->assertTrue(true);
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
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\TestFixture\Event;
11+
12+
use Exception;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class ExceptionInTearDownTest extends TestCase
16+
{
17+
protected function tearDown(): void
18+
{
19+
throw new Exception;
20+
}
21+
22+
public function testOne(): void
23+
{
24+
$this->assertTrue(true);
25+
}
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
The right events are emitted in the right order for when an exception is raised in tearDownAfterClass()
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--debug';
8+
$_SERVER['argv'][] = __DIR__ . '/_files/ExceptionInTearDownAfterClassTest.php';
9+
10+
require __DIR__ . '/../../bootstrap.php';
11+
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
--EXPECTF--
14+
PHPUnit Started (PHPUnit %s using %s)
15+
Test Runner Configured
16+
Test Suite Loaded (1 test)
17+
Event Facade Sealed
18+
Test Runner Started
19+
Test Suite Sorted
20+
Test Runner Execution Started (1 test)
21+
Test Suite Started (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest, 1 test)
22+
Test Preparation Started (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
23+
Test Prepared (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
24+
Assertion Succeeded (Constraint: is true, Value: true)
25+
Test Passed (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
26+
Test Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest::testOne)
27+
Test Suite Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownAfterClassTest, 1 test)
28+
Test Runner Execution Finished
29+
Test Runner Finished
30+
PHPUnit Finished (Shell Exit Code: 0)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
The right events are emitted in the right order for when an exception is raised in tearDown()
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--debug';
8+
$_SERVER['argv'][] = __DIR__ . '/_files/ExceptionInTearDownTest.php';
9+
10+
require __DIR__ . '/../../bootstrap.php';
11+
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
--EXPECTF--
14+
PHPUnit Started (PHPUnit %s using %s)
15+
Test Runner Configured
16+
Test Suite Loaded (1 test)
17+
Event Facade Sealed
18+
Test Runner Started
19+
Test Suite Sorted
20+
Test Runner Execution Started (1 test)
21+
Test Suite Started (PHPUnit\TestFixture\Event\ExceptionInTearDownTest, 1 test)
22+
Test Preparation Started (PHPUnit\TestFixture\Event\ExceptionInTearDownTest::testOne)
23+
Test Prepared (PHPUnit\TestFixture\Event\ExceptionInTearDownTest::testOne)
24+
Assertion Succeeded (Constraint: is true, Value: true)
25+
Test Passed (PHPUnit\TestFixture\Event\ExceptionInTearDownTest::testOne)
26+
After Test Method Called (PHPUnit\TestFixture\Event\ExceptionInTearDownTest::tearDown)
27+
After Test Method Finished:
28+
- PHPUnit\TestFixture\Event\ExceptionInTearDownTest::tearDown
29+
Test Errored (PHPUnit\TestFixture\Event\ExceptionInTearDownTest::testOne)
30+
Test Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownTest::testOne)
31+
Test Suite Finished (PHPUnit\TestFixture\Event\ExceptionInTearDownTest, 1 test)
32+
Test Runner Execution Finished
33+
Test Runner Finished
34+
PHPUnit Finished (Shell Exit Code: 2)

0 commit comments

Comments
 (0)