Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 18, 2023
1 parent aab26da commit aecdcb2
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use PHPUnit\Framework\Attributes\PostCondition;
use PHPUnit\Framework\TestCase;

final class AssertionFailureInPostConditionTest extends TestCase
{
#[PostCondition]
public function postCondition(): void
{
$this->assertTrue(false);
}

public function testOne(): void
{
$this->assertTrue(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use PHPUnit\Framework\Attributes\PreCondition;
use PHPUnit\Framework\TestCase;

final class AssertionFailureInPreConditionTest extends TestCase
{
#[PreCondition]
public function preCondition(): void
{
$this->assertTrue(false);
}

public function testOne(): void
{
$this->assertTrue(true);
}
}
27 changes: 27 additions & 0 deletions tests/end-to-end/event/_files/AssertionFailureInSetUpTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\TestCase;

final class AssertionFailureInSetUpTest extends TestCase
{
#[Before]
public function beforeTest(): void
{
$this->assertTrue(false);
}

public function testOne(): void
{
$this->assertTrue(true);
}
}
27 changes: 27 additions & 0 deletions tests/end-to-end/event/_files/AssertionFailureInTearDownTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\TestCase;

final class AssertionFailureInTearDownTest extends TestCase
{
#[After]
public function afterTest(): void
{
$this->assertTrue(false);
}

public function testOne(): void
{
$this->assertTrue(true);
}
}
49 changes: 49 additions & 0 deletions tests/end-to-end/event/assertion-failure-in-after-test-method.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
The right events are emitted in the right order for a test that fails because of an assertion failure in a "after test" method
--SKIPIF--
<?php declare(strict_types=1);
if (DIRECTORY_SEPARATOR === '\\') {
print "skip: this test does not work on Windows / GitHub Actions\n";
}
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = __DIR__ . '/_files/AssertionFailureInTearDownTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Configured
Test Suite Loaded (1 test)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (1 test)
Test Suite Started (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest, 1 test)
Test Preparation Started (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
Test Prepared (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
Assertion Succeeded (Constraint: is true, Value: true)
Test Passed (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
Assertion Failed (Constraint: is true, Value: false)
After Test Method Called (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::afterTest)
After Test Method Finished:
- PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::afterTest
Test Failed (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
Failed asserting that false is true.
Test Finished (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest::testOne)
Test Suite Finished (PHPUnit\TestFixture\Event\AssertionFailureInTearDownTest, 1 test)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
The right events are emitted in the right order for a test that fails because of an assertion failure in a "before test" method
--SKIPIF--
<?php declare(strict_types=1);
if (DIRECTORY_SEPARATOR === '\\') {
print "skip: this test does not work on Windows / GitHub Actions\n";
}
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = __DIR__ . '/_files/AssertionFailureInSetUpTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Configured
Test Suite Loaded (1 test)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (1 test)
Test Suite Started (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest, 1 test)
Test Preparation Started (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::testOne)
Assertion Failed (Constraint: is true, Value: false)
Before Test Method Called (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::beforeTest)
Before Test Method Finished:
- PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::beforeTest
Test Preparation Failed (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::testOne)
Test Failed (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::testOne)
Failed asserting that false is true.
Test Finished (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest::testOne)
Test Suite Finished (PHPUnit\TestFixture\Event\AssertionFailureInSetUpTest, 1 test)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
The right events are emitted in the right order for a test that fails because of an assertion failure in a postcondition method
--SKIPIF--
<?php declare(strict_types=1);
if (DIRECTORY_SEPARATOR === '\\') {
print "skip: this test does not work on Windows / GitHub Actions\n";
}
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = __DIR__ . '/_files/AssertionFailureInPostConditionTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Configured
Test Suite Loaded (1 test)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (1 test)
Test Suite Started (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest, 1 test)
Test Preparation Started (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::testOne)
Test Prepared (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::testOne)
Assertion Succeeded (Constraint: is true, Value: true)
Assertion Failed (Constraint: is true, Value: false)
Post Condition Method Called (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::postCondition)
Post Condition Method Finished:
- PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::postCondition
Test Failed (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::testOne)
Failed asserting that false is true.
Test Finished (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest::testOne)
Test Suite Finished (PHPUnit\TestFixture\Event\AssertionFailureInPostConditionTest, 1 test)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
The right events are emitted in the right order for a test that fails because of an assertion failure in a precondition method
--SKIPIF--
<?php declare(strict_types=1);
if (DIRECTORY_SEPARATOR === '\\') {
print "skip: this test does not work on Windows / GitHub Actions\n";
}
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = __DIR__ . '/_files/AssertionFailureInPreConditionTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Configured
Test Suite Loaded (1 test)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (1 test)
Test Suite Started (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest, 1 test)
Test Preparation Started (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::testOne)
Assertion Failed (Constraint: is true, Value: false)
Pre Condition Method Called (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::preCondition)
Pre Condition Method Finished:
- PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::preCondition
Test Preparation Failed (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::testOne)
Test Failed (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::testOne)
Failed asserting that false is true.
Test Finished (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest::testOne)
Test Suite Finished (PHPUnit\TestFixture\Event\AssertionFailureInPreConditionTest, 1 test)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 1)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
The right events are emitted in the right order for a test that fails because of an assertion method
The right events are emitted in the right order for a test that fails because of an assertion failure in the test method
--SKIPIF--
<?php declare(strict_types=1);
if (DIRECTORY_SEPARATOR === '\\') {
Expand Down

0 comments on commit aecdcb2

Please sign in to comment.