Skip to content

Commit aecdcb2

Browse files
Add tests
1 parent aab26da commit aecdcb2

9 files changed

+300
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\TestFixture\Event;
11+
12+
use PHPUnit\Framework\Attributes\PostCondition;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class AssertionFailureInPostConditionTest extends TestCase
16+
{
17+
#[PostCondition]
18+
public function postCondition(): void
19+
{
20+
$this->assertTrue(false);
21+
}
22+
23+
public function testOne(): void
24+
{
25+
$this->assertTrue(true);
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\TestFixture\Event;
11+
12+
use PHPUnit\Framework\Attributes\PreCondition;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class AssertionFailureInPreConditionTest extends TestCase
16+
{
17+
#[PreCondition]
18+
public function preCondition(): void
19+
{
20+
$this->assertTrue(false);
21+
}
22+
23+
public function testOne(): void
24+
{
25+
$this->assertTrue(true);
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\TestFixture\Event;
11+
12+
use PHPUnit\Framework\Attributes\Before;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class AssertionFailureInSetUpTest extends TestCase
16+
{
17+
#[Before]
18+
public function beforeTest(): void
19+
{
20+
$this->assertTrue(false);
21+
}
22+
23+
public function testOne(): void
24+
{
25+
$this->assertTrue(true);
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\TestFixture\Event;
11+
12+
use PHPUnit\Framework\Attributes\After;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class AssertionFailureInTearDownTest extends TestCase
16+
{
17+
#[After]
18+
public function afterTest(): void
19+
{
20+
$this->assertTrue(false);
21+
}
22+
23+
public function testOne(): void
24+
{
25+
$this->assertTrue(true);
26+
}
27+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
The right events are emitted in the right order for a test that fails because of an assertion failure in a "after test" method
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
if (DIRECTORY_SEPARATOR === '\\') {
6+
print "skip: this test does not work on Windows / GitHub Actions\n";
7+
}
8+
--FILE--
9+
<?php declare(strict_types=1);
10+
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);
11+
12+
$_SERVER['argv'][] = '--do-not-cache-result';
13+
$_SERVER['argv'][] = '--no-configuration';
14+
$_SERVER['argv'][] = '--no-output';
15+
$_SERVER['argv'][] = '--log-events-text';
16+
$_SERVER['argv'][] = $traceFile;
17+
$_SERVER['argv'][] = __DIR__ . '/_files/AssertionFailureInTearDownTest.php';
18+
19+
require __DIR__ . '/../../bootstrap.php';
20+
21+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
22+
23+
print file_get_contents($traceFile);
24+
25+
unlink($traceFile);
26+
--EXPECTF--
27+
PHPUnit Started (PHPUnit %s using %s)
28+
Test Runner Configured
29+
Test Suite Loaded (1 test)
30+
Event Facade Sealed
31+
Test Runner Started
32+
Test Suite Sorted
33+
Test Runner Execution Started (1 test)
34+
Test Suite Started (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest, 1 test)
35+
Test Preparation Started (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
36+
Test Prepared (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
37+
Assertion Succeeded (Constraint: is true, Value: true)
38+
Test Passed (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
39+
Assertion Failed (Constraint: is true, Value: false)
40+
After Test Method Called (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::afterTest)
41+
After Test Method Finished:
42+
- PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::afterTest
43+
Test Failed (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
44+
Failed asserting that false is true.
45+
Test Finished (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
46+
Test Suite Finished (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest, 1 test)
47+
Test Runner Execution Finished
48+
Test Runner Finished
49+
PHPUnit Finished (Shell Exit Code: 1)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
The right events are emitted in the right order for a test that fails because of an assertion failure in a "before test" method
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
if (DIRECTORY_SEPARATOR === '\\') {
6+
print "skip: this test does not work on Windows / GitHub Actions\n";
7+
}
8+
--FILE--
9+
<?php declare(strict_types=1);
10+
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);
11+
12+
$_SERVER['argv'][] = '--do-not-cache-result';
13+
$_SERVER['argv'][] = '--no-configuration';
14+
$_SERVER['argv'][] = '--no-output';
15+
$_SERVER['argv'][] = '--log-events-text';
16+
$_SERVER['argv'][] = $traceFile;
17+
$_SERVER['argv'][] = __DIR__ . '/_files/AssertionFailureInSetUpTest.php';
18+
19+
require __DIR__ . '/../../bootstrap.php';
20+
21+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
22+
23+
print file_get_contents($traceFile);
24+
25+
unlink($traceFile);
26+
--EXPECTF--
27+
PHPUnit Started (PHPUnit %s using %s)
28+
Test Runner Configured
29+
Test Suite Loaded (1 test)
30+
Event Facade Sealed
31+
Test Runner Started
32+
Test Suite Sorted
33+
Test Runner Execution Started (1 test)
34+
Test Suite Started (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest, 1 test)
35+
Test Preparation Started (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::testOne)
36+
Assertion Failed (Constraint: is true, Value: false)
37+
Before Test Method Called (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::beforeTest)
38+
Before Test Method Finished:
39+
- PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::beforeTest
40+
Test Preparation Failed (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::testOne)
41+
Test Failed (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::testOne)
42+
Failed asserting that false is true.
43+
Test Finished (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::testOne)
44+
Test Suite Finished (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest, 1 test)
45+
Test Runner Execution Finished
46+
Test Runner Finished
47+
PHPUnit Finished (Shell Exit Code: 1)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
The right events are emitted in the right order for a test that fails because of an assertion failure in a postcondition method
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
if (DIRECTORY_SEPARATOR === '\\') {
6+
print "skip: this test does not work on Windows / GitHub Actions\n";
7+
}
8+
--FILE--
9+
<?php declare(strict_types=1);
10+
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);
11+
12+
$_SERVER['argv'][] = '--do-not-cache-result';
13+
$_SERVER['argv'][] = '--no-configuration';
14+
$_SERVER['argv'][] = '--no-output';
15+
$_SERVER['argv'][] = '--log-events-text';
16+
$_SERVER['argv'][] = $traceFile;
17+
$_SERVER['argv'][] = __DIR__ . '/_files/AssertionFailureInPostConditionTest.php';
18+
19+
require __DIR__ . '/../../bootstrap.php';
20+
21+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
22+
23+
print file_get_contents($traceFile);
24+
25+
unlink($traceFile);
26+
--EXPECTF--
27+
PHPUnit Started (PHPUnit %s using %s)
28+
Test Runner Configured
29+
Test Suite Loaded (1 test)
30+
Event Facade Sealed
31+
Test Runner Started
32+
Test Suite Sorted
33+
Test Runner Execution Started (1 test)
34+
Test Suite Started (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest, 1 test)
35+
Test Preparation Started (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::testOne)
36+
Test Prepared (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::testOne)
37+
Assertion Succeeded (Constraint: is true, Value: true)
38+
Assertion Failed (Constraint: is true, Value: false)
39+
Post Condition Method Called (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::postCondition)
40+
Post Condition Method Finished:
41+
- PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::postCondition
42+
Test Failed (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::testOne)
43+
Failed asserting that false is true.
44+
Test Finished (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::testOne)
45+
Test Suite Finished (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest, 1 test)
46+
Test Runner Execution Finished
47+
Test Runner Finished
48+
PHPUnit Finished (Shell Exit Code: 1)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
The right events are emitted in the right order for a test that fails because of an assertion failure in a precondition method
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
if (DIRECTORY_SEPARATOR === '\\') {
6+
print "skip: this test does not work on Windows / GitHub Actions\n";
7+
}
8+
--FILE--
9+
<?php declare(strict_types=1);
10+
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);
11+
12+
$_SERVER['argv'][] = '--do-not-cache-result';
13+
$_SERVER['argv'][] = '--no-configuration';
14+
$_SERVER['argv'][] = '--no-output';
15+
$_SERVER['argv'][] = '--log-events-text';
16+
$_SERVER['argv'][] = $traceFile;
17+
$_SERVER['argv'][] = __DIR__ . '/_files/AssertionFailureInPreConditionTest.php';
18+
19+
require __DIR__ . '/../../bootstrap.php';
20+
21+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
22+
23+
print file_get_contents($traceFile);
24+
25+
unlink($traceFile);
26+
--EXPECTF--
27+
PHPUnit Started (PHPUnit %s using %s)
28+
Test Runner Configured
29+
Test Suite Loaded (1 test)
30+
Event Facade Sealed
31+
Test Runner Started
32+
Test Suite Sorted
33+
Test Runner Execution Started (1 test)
34+
Test Suite Started (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest, 1 test)
35+
Test Preparation Started (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::testOne)
36+
Assertion Failed (Constraint: is true, Value: false)
37+
Pre Condition Method Called (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::preCondition)
38+
Pre Condition Method Finished:
39+
- PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::preCondition
40+
Test Preparation Failed (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::testOne)
41+
Test Failed (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::testOne)
42+
Failed asserting that false is true.
43+
Test Finished (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::testOne)
44+
Test Suite Finished (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest, 1 test)
45+
Test Runner Execution Finished
46+
Test Runner Finished
47+
PHPUnit Finished (Shell Exit Code: 1)

tests/end-to-end/event/assertion-method-failure.phpt renamed to tests/end-to-end/event/assertion-failure-in-test-method.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
The right events are emitted in the right order for a test that fails because of an assertion method
2+
The right events are emitted in the right order for a test that fails because of an assertion failure in the test method
33
--SKIPIF--
44
<?php declare(strict_types=1);
55
if (DIRECTORY_SEPARATOR === '\\') {

0 commit comments

Comments
 (0)