Skip to content

CucumberND table headers might be missing #286

@uuf6429

Description

@uuf6429

The following line:

$table[$tableJson['tableHeader']['location']['line']] = array_column($tableJson['tableHeader']['cells'], 'value');

assumes that tableHeader is always set, but according to the spec schema, tableHeader is not required, and therefore optional.

I discovered this while implementing PHPStan fixes, using hand-written schema in PHPStan types DSL:

/**
 * @phpstan-type TExamples THasTags&array{
 *     location: TLocation,
 *     keyword: string,
 *     name: string,
 *     description: string,
 *     tableHeader?: TTableRow,              <-----
 *     tableBody: list<TTableRow>,
 *     id: string,
 * }
 */

What shall we do about this?

  1. Make the PHPStan type mandatory (by removing the ?) and generally ignore the code.
  2. Make PHPStan ignore that line (@phpstan-ignore-next-line)
  3. Skip that line when the header is not set:
    if (isset($tableJson['tableHeader'])) {
        $table[$tableJson['tableHeader']['location']['line']] = array_column($tableJson['tableHeader']['cells'], 'value');
    }
  4. Create an empty table row (representing the header) when not set. I tried to hack up some code, but it's not as easy as it sounds:
    • if we take the line (row index) as the first-body-row-line - 1, it might conflict with an existing line
    • what would the columns be? empty strings?
  5. Something else...?

I think option 3 sounds reasonable, but we need to be sure it doesn't change behaviour.


In conclusion, we want to have this logic:

if (tableBody is empty) {         // Header is not important at this point.
  return                          // -> Example should be skipped.
}

if (tableHeader is missing) {     // Here it is implied that body is not empty.
  throw exception                 // -> This is not a valid or current case, we should
                                        be notified if this happens in the future.
}

load tableHeader and tableBody    // -> The normal/existing case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions