Skip to content

Test: review all tests to stabilize them more #497

Description

@jrfnl

Currently, there are a lot of tests which follow a pattern along the lines of:

// Do something
$this->assertSame($expected, $result['key']['subkey']->property);

Tests like these are unstable as they may error out on any of the following:

  • $result not being an array.
  • The 'key' index not existing in $result
  • The 'subkey' index not existing in $result['key']
  • $result['key']['subkey'] not being an object
  • $result['key']['subkey'] not being an object of the expected type (instance of)
  • The object in $result['key']['subkey'] not having a property named $property.

Those tests should be stabilized and improved by changing them to something along the lines of:

// Do something
$this->assertIsArray($result);
$this->assertHaskey('key', $result);
$this->assertIsArray($result['key']);
$this->assertHaskey('subkey', $result['key']);
$this->assertIsObject($result['key']['subkey']);
$this->assertInstanceOf($classname, $result['key']['subkey']);
$this->assertHasAttribute('property', $result['key']['subkey']);
$this->assertSame($expected, $result['key']['subkey']->property);

Additionally, all tests which have multiple assertions, should pass the $message parameter to each assertion to help figure out which assertion has failed when a test fails.

Other review tasks (optional, but highly recommended)

  • Refactoring tests methods which do the same thing to data providers.
  • Enhancing existing data providers to use named data sets and keyed data entries.
  • Adding appropriate @covers tags.
  • Reviewing code coverage and adding additional tests to raise (both path as well as branch) code coverage.
  • Adding test documentation.
  • Potentially splitting test classes which do too much into multiple classes based on what is being covered by the tests.

Actions list

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions