sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.71k stars 2.2k forks source link

setUp() not worked in PHPUnit 10.0.14 #5268

Closed aleksandr-shevchenko closed 1 year ago

aleksandr-shevchenko commented 1 year ago
Q A
PHPUnit version 10.0.14
PHP version 8.2.3
Installation Method Composer / PHAR - both

Summary

Current behavior

setUp() not worked in PHPUnit 10.0.14

How to reproduce

PHPUnit 10.0.14 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.3
Configuration: D:\Rabota\PHP\_test\test_phpunit5\phpunit.xml

setUpBeforeClass
tearDown
.tearDown
.tearDown
.tearDown
.                                                                4 / 4 (100%)tearDownAfterClass

Time: 00:00.018, Memory: 8.00 MB

OK (4 tests, 4 assertions)

Expected behavior


PHPUnit 9.6.4 by Sebastian Bergmann and contributors.

setUpBeforeClass
.setUp
tearDown
.setUp
tearDown
.setUp
tearDown
.                                                                4 / 4 (100%)setUp
tearDown
tearDownAfterClass

Time: 00:00.004, Memory: 26.00 MB

OK (4 tests, 4 assertions)

test_phpunit.zip

sebastianbergmann commented 1 year ago

Your setUp() method is called:

./vendor/bin/phpunit --no-output --log-events-text php://stdout
PHPUnit Started (PHPUnit 10.0.14 using PHP 8.2.3 (cli) on Linux)
Test Runner Configured
Bootstrap Finished (/tmp/test_phpunit/vendor/autoload.php)
Test Suite Loaded (4 tests)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (4 tests)
Test Suite Started (4 tests)
Test Suite Started (Project Test Suite, 4 tests)
Test Suite Started (Tests\SalaryCalculatorTest, 4 tests)
Before First Test Method Called (Tests\SalaryCalculatorTest::setUpBeforeClass)
setUpBeforeClass
Before First Test Method Finished:
- Tests\SalaryCalculatorTest::setUpBeforeClass
Test Suite Started (Tests\SalaryCalculatorTest::testCalculate, 4 tests)
Test Preparation Started (Tests\SalaryCalculatorTest::testCalculate#0)
Before Test Method Called (Tests\SalaryCalculatorTest::setUp)
Before Test Method Finished:
- Tests\SalaryCalculatorTest::setUp
Test Prepared (Tests\SalaryCalculatorTest::testCalculate#0)
Assertion Succeeded (Constraint: is equal to 9.0, Value: 9.0)
Test Passed (Tests\SalaryCalculatorTest::testCalculate#0)
tearDown
After Test Method Called (Tests\SalaryCalculatorTest::tearDown)
After Test Method Finished:
- Tests\SalaryCalculatorTest::tearDown
Test Finished (Tests\SalaryCalculatorTest::testCalculate#0)
Test Preparation Started (Tests\SalaryCalculatorTest::testCalculate#1)
Before Test Method Called (Tests\SalaryCalculatorTest::setUp)
Before Test Method Finished:
- Tests\SalaryCalculatorTest::setUp
Test Prepared (Tests\SalaryCalculatorTest::testCalculate#1)
Assertion Succeeded (Constraint: is equal to 10.8, Value: 10.8)
Test Passed (Tests\SalaryCalculatorTest::testCalculate#1)
tearDown
After Test Method Called (Tests\SalaryCalculatorTest::tearDown)
After Test Method Finished:
- Tests\SalaryCalculatorTest::tearDown
Test Finished (Tests\SalaryCalculatorTest::testCalculate#1)
Test Preparation Started (Tests\SalaryCalculatorTest::testCalculate#2)
Before Test Method Called (Tests\SalaryCalculatorTest::setUp)
Before Test Method Finished:
- Tests\SalaryCalculatorTest::setUp
Test Prepared (Tests\SalaryCalculatorTest::testCalculate#2)
Assertion Succeeded (Constraint: is equal to 18.0, Value: 18.0)
Test Passed (Tests\SalaryCalculatorTest::testCalculate#2)
tearDown
After Test Method Called (Tests\SalaryCalculatorTest::tearDown)
After Test Method Finished:
- Tests\SalaryCalculatorTest::tearDown
Test Finished (Tests\SalaryCalculatorTest::testCalculate#2)
Test Preparation Started (Tests\SalaryCalculatorTest::testCalculate#3)
Before Test Method Called (Tests\SalaryCalculatorTest::setUp)
Before Test Method Finished:
- Tests\SalaryCalculatorTest::setUp
Test Prepared (Tests\SalaryCalculatorTest::testCalculate#3)
Assertion Succeeded (Constraint: is equal to 11.25, Value: 11.25)
Test Passed (Tests\SalaryCalculatorTest::testCalculate#3)
tearDown
After Test Method Called (Tests\SalaryCalculatorTest::tearDown)
After Test Method Finished:
- Tests\SalaryCalculatorTest::tearDown
Test Finished (Tests\SalaryCalculatorTest::testCalculate#3)
Test Suite Finished (Tests\SalaryCalculatorTest::testCalculate, 4 tests)
tearDownAfterClass
After Last Test Method Called (Tests\SalaryCalculatorTest::tearDownAfterClass)
After Last Test Method Finished:
- Tests\SalaryCalculatorTest::tearDownAfterClass
Test Suite Finished (Tests\SalaryCalculatorTest, 4 tests)
Test Suite Finished (Project Test Suite, 4 tests)
Test Suite Finished (4 tests)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 0)

The output generated by echo in setUp() is simply swallowed.

aleksandr-shevchenko commented 1 year ago

In new version (10.0.16) PHPUnit start print 'echo' from setUp(), but why printed AFTER echo from tearDown() ?

PHPUnit 10.0.16 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.3
Configuration: D:\Rabota\PHP\_test\test_phpunit5\phpunit.xml

setUpBeforeClass
tearDown
setUp
.tearDown
setUp
.tearDown
setUp
.tearDown
setUp
.                                                                4 / 4 (100%)tearDownAfterClass

Time: 00:00.018, Memory: 8.00 MB

OK (4 tests, 4 assertions)