Skip to content

Commit

Permalink
tests: Replace logicalOr() with withConsecutive() to be more strict
Browse files Browse the repository at this point in the history
Remove two lines from the error messages to handle both error cases
similiar.
Fix the wrong character in the error message as well

Change-Id: Ied154e8232c8e13e619706939833809110b9757b
  • Loading branch information
umherirrender committed Jan 10, 2023
1 parent 3dcca0b commit 50a1d95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/Command/GenerateEquivset.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ public function execute( InputInterface $input, OutputInterface $output ) {
if ( Utils::codepointToUtf8( hexdec( $m['hexleft'] ) ) != $m['charleft'] ) {
$actual = Utils::utf8ToCodepoint( $m['charleft'] );
if ( $actual === false ) {
$output->writeln( "Bytes: " . strlen( $m['charleft'] ) );
$output->writeln( bin2hex( $line ) );
$hexForm = bin2hex( $m['charleft'] );
$output->writeln( "<error>Invalid UTF-8 character \"{$m['charleft']}\" ($hexForm) at " .
"line $lineNum: $line</error>" );
Expand All @@ -127,7 +125,7 @@ public function execute( InputInterface $input, OutputInterface $output ) {
$actual = Utils::utf8ToCodepoint( $m['charright'] );
if ( $actual === false ) {
$hexForm = bin2hex( $m['charright'] );
$output->writeln( "<error>Invalid UTF-8 character \"{$m['charleft']}\" ($hexForm) at " .
$output->writeln( "<error>Invalid UTF-8 character \"{$m['charright']}\" ($hexForm) at " .
"line $lineNum: $line</error>" );
} else {
$output->writeln( "<error>Error: right number ({$m['hexright']}) does not match right " .
Expand Down
26 changes: 12 additions & 14 deletions tests/Command/GenerateEquivsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ public function testExecuteFailMalformed() {
$output = $this->getMockBuilder( OutputInterface::class )
->getMock();
$output->method( 'writeln' )
->with( $this->logicalOr(
$this->stringContains( 'Error: invalid entry' ),
$this->stringContains( 'Finished with errors' )
) );
->withConsecutive(

This comment has been minimized.

Copy link
@BafS

BafS Feb 3, 2023

withConsecutive is unfortunately deprecated and removed in PHPUnit 10 (sebastianbergmann/phpunit#4564)

[ $this->stringContains( 'Error: invalid entry' ) ],
[ $this->stringContains( 'Finished with errors' ) ]
);
$status = $command->execute( $input, $output );

$this->assertSame( 1, $status );
Expand Down Expand Up @@ -210,10 +210,10 @@ public function testExecuteFailNotMatchingCodepoint( $side, $number, $in ) {
$output = $this->getMockBuilder( OutputInterface::class )
->getMock();
$output->method( 'writeln' )
->with( $this->logicalOr(
$this->stringContains( "Error: $side number ($number) does not match" ),
$this->stringContains( 'Finished with errors' )
) );
->withConsecutive(
[ $this->stringContains( "Error: $side number ($number) does not match" ) ],
[ $this->stringContains( 'Finished with errors' ) ]
);

$status = $command->execute( $input, $output );

Expand Down Expand Up @@ -263,12 +263,10 @@ public function testExecuteFailInvalidChar( $in ) {
$output = $this->getMockBuilder( OutputInterface::class )
->getMock();
$output->method( 'writeln' )
->with( $this->logicalOr(
$this->stringContains( 'Bytes' ),
$this->stringContains( bin2hex( $in ) ),
$this->stringContains( 'Invalid UTF-8 character' ),
$this->stringContains( 'Finished with errors' )
) );
->withConsecutive(
[ $this->stringContains( 'Invalid UTF-8 character' ) ],
[ $this->stringContains( 'Finished with errors' ) ]
);

$status = $command->execute( $input, $output );

Expand Down

0 comments on commit 50a1d95

Please sign in to comment.