Skip to content

Commit

Permalink
Tests/HeredocNowdocCloserTest: use named data sets
Browse files Browse the repository at this point in the history
With non-named data sets, when a test fails, PHPUnit will display the number of the test which failed.

With tests which have a _lot_ of data sets, this makes it _interesting_ (and time-consuming) to debug those, as one now has to figure out which of the data sets in the data provider corresponds to that number.

Using named data sets makes debugging failing tests more straight forward as PHPUnit will display the data set name instead of the number.
Using named data sets also documents what exactly each data set is testing.

Includes making the data type in the docblock more specific.
Includes fixing up the docblock description for the file.
  • Loading branch information
jrfnl committed Jan 14, 2024
1 parent c8d68d6 commit b030aa0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tests/Core/Tokenizer/HeredocNowdocCloserTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Tests the tokenization of goto declarations and statements.
* Tests the tokenization of heredoc/nowdoc closer tokens.
*
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
* @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600)
Expand All @@ -23,8 +23,8 @@ final class HeredocNowdocCloserTest extends AbstractMethodUnitTest
/**
* Verify that leading (indent) whitespace in a heredoc/nowdoc closer token get the tab replacement treatment.
*
* @param string $testMarker The comment prefacing the target token.
* @param array $expected Expectations for the token array.
* @param string $testMarker The comment prefacing the target token.
* @param array<string, int|string|null> $expected Expectations for the token array.
*
* @dataProvider dataHeredocNowdocCloserTabReplacement
* @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createPositionMap
Expand Down Expand Up @@ -55,52 +55,52 @@ public function testHeredocNowdocCloserTabReplacement($testMarker, $expected)
*
* @see testHeredocNowdocCloserTabReplacement()
*
* @return array
* @return array<string, array<string, string|array<string, int|string|null>>>
*/
public static function dataHeredocNowdocCloserTabReplacement()
{
return [
[
'Heredoc closer without indent' => [
'testMarker' => '/* testHeredocCloserNoIndent */',
'expected' => [
'length' => 3,
'content' => 'EOD',
'orig_content' => null,
],
],
[
'Nowdoc closer without indent' => [
'testMarker' => '/* testNowdocCloserNoIndent */',
'expected' => [
'length' => 3,
'content' => 'EOD',
'orig_content' => null,
],
],
[
'Heredoc closer with indent, spaces' => [
'testMarker' => '/* testHeredocCloserSpaceIndent */',
'expected' => [
'length' => 7,
'content' => ' END',
'orig_content' => null,
],
],
[
'Nowdoc closer with indent, spaces' => [
'testMarker' => '/* testNowdocCloserSpaceIndent */',
'expected' => [
'length' => 8,
'content' => ' END',
'orig_content' => null,
],
],
[
'Heredoc closer with indent, tabs' => [
'testMarker' => '/* testHeredocCloserTabIndent */',
'expected' => [
'length' => 8,
'content' => ' END',
'orig_content' => ' END',
],
],
[
'Nowdoc closer with indent, tabs' => [
'testMarker' => '/* testNowdocCloserTabIndent */',
'expected' => [
'length' => 7,
Expand Down

0 comments on commit b030aa0

Please sign in to comment.