Skip to content

Commit

Permalink
Use TestRunner::writeMessage() for test suite loader deprecation warn…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
sebastianbergmann committed Mar 31, 2020
1 parent 10da552 commit 7a138d7
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 40 deletions.
19 changes: 7 additions & 12 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public function addTestFile(string $filename): void
if ($class->getShortName() !== $expectedClassName) {
$this->addWarning(
\sprintf(
"Warning: Test case class not matching filename is deprecated\n in %s\n class name was '%s', expected '%s'",
"Test case class not matching filename is deprecated\n in %s\n Class name was '%s', expected '%s'",
$filename,
$class->getShortName(),
$expectedClassName
Expand All @@ -474,7 +474,7 @@ public function addTestFile(string $filename): void
if (\count($this->tests) > ++$numTests) {
$this->addWarning(
\sprintf(
"Warning: Multiple test case classes per file is deprecated\n in %s",
"Multiple test case classes per file is deprecated\n in %s",
$filename
)
);
Expand Down Expand Up @@ -771,17 +771,12 @@ public function injectFilter(Factory $filter): void
}
}

public function hasWarnings(): bool
{
return !empty($this->warnings);
}

public function warningsAsString(): string
/**
* @psalm-return array<int,string>
*/
public function warnings(): array
{
return \implode(
\PHP_EOL,
\array_unique($this->warnings)
);
return \array_unique($this->warnings);
}

/**
Expand Down
12 changes: 10 additions & 2 deletions src/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,16 @@ public function run(Test $suite, array $arguments = [], bool $exit = true): Test
}
}

if ($suite->hasWarnings()) {
$this->write($suite->warningsAsString() . \PHP_EOL . \PHP_EOL);
$testSuiteWarningsPrinted = false;

foreach ($suite->warnings() as $warning) {
$this->writeMessage('Warning', $warning);

$testSuiteWarningsPrinted = true;
}

if ($testSuiteWarningsPrinted) {
$this->write(\PHP_EOL);
}

$suite->run($result);
Expand Down
7 changes: 4 additions & 3 deletions tests/end-to-end/dataprovider-issue-2922.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Warning: Test case class not matching filename is deprecated
in %s/DataProviderIssue2922/SecondTest.php
class name was 'SecondHelloWorldTest', expected 'SecondTest'

Warning: Test case class not matching filename is deprecated
in %s/DataProviderIssue2922/SecondTest.php
Class name was 'SecondHelloWorldTest', expected 'SecondTest'

. 1 / 1 (100%)

Expand Down
7 changes: 4 additions & 3 deletions tests/end-to-end/filename-matches-class-name.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Warning: Test case class not matching filename is deprecated
in %s/OneClassPerFile/wrongClassName/WrongClassNameTest.php
class name was 'WrongClassNameBar', expected 'WrongClassNameTest'

Warning: Test case class not matching filename is deprecated
in %s/OneClassPerFile/wrongClassName/WrongClassNameTest.php
Class name was 'WrongClassNameBar', expected 'WrongClassNameTest'

. 1 / 1 (100%)

Expand Down
7 changes: 4 additions & 3 deletions tests/end-to-end/regression/GitHub/2972.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Warning: Test case class not matching filename is deprecated
in %s/unconventiallyNamedIssue2972Test.php
class name was 'Issue2972Test', expected 'unconventiallyNamedIssue2972Test'

Warning: Test case class not matching filename is deprecated
in %s/unconventiallyNamedIssue2972Test.php
Class name was 'Issue2972Test', expected 'unconventiallyNamedIssue2972Test'

.. 2 / 2 (100%)

Expand Down
13 changes: 7 additions & 6 deletions tests/end-to-end/test-suffix-multiple.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Warning: Test case class not matching filename is deprecated
in %s/BankAccountTest.test.php
class name was 'BankAccountWithCustomExtensionTest', expected 'BankAccountTest'
Warning: Test case class not matching filename is deprecated
in %s/ConcreteTest.my.php
class name was 'ConcreteWithMyCustomExtensionTest', expected 'ConcreteTest'

Warning: Test case class not matching filename is deprecated
in %s/BankAccountTest.test.php
Class name was 'BankAccountWithCustomExtensionTest', expected 'BankAccountTest'
Warning: Test case class not matching filename is deprecated
in %s/ConcreteTest.my.php
Class name was 'ConcreteWithMyCustomExtensionTest', expected 'ConcreteTest'

..... 5 / 5 (100%)

Expand Down
7 changes: 4 additions & 3 deletions tests/end-to-end/test-suffix-single.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Warning: Test case class not matching filename is deprecated
in %s/BankAccountTest.test.php
class name was 'BankAccountWithCustomExtensionTest', expected 'BankAccountTest'

Warning: Test case class not matching filename is deprecated
in %s/BankAccountTest.test.php
Class name was 'BankAccountWithCustomExtensionTest', expected 'BankAccountTest'

... 3 / 3 (100%)

Expand Down
17 changes: 9 additions & 8 deletions tests/end-to-end/two-classes-per-file-invalid.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Warning: Test case class not matching filename is deprecated
in %s/OneClassPerFile/failing/TwoClassesInvalidTest.php
class name was 'TwoClassesInvalid', expected 'TwoClassesInvalidTest'
Warning: Test case class not matching filename is deprecated
in %s/OneClassPerFile/failing/TwoClassesInvalidTest.php
class name was 'TwoClassesInvalid2', expected 'TwoClassesInvalidTest'
Warning: Multiple test case classes per file is deprecated
in %s/TwoClassesInvalidTest.php

Warning: Test case class not matching filename is deprecated
in %s/OneClassPerFile/failing/TwoClassesInvalidTest.php
Class name was 'TwoClassesInvalid', expected 'TwoClassesInvalidTest'
Warning: Test case class not matching filename is deprecated
in %s/OneClassPerFile/failing/TwoClassesInvalidTest.php
Class name was 'TwoClassesInvalid2', expected 'TwoClassesInvalidTest'
Warning: Multiple test case classes per file is deprecated
in %s/TwoClassesInvalidTest.php

.. 2 / 2 (100%)

Expand Down

0 comments on commit 7a138d7

Please sign in to comment.