Test: review all tests to stabilize them more
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:
-
$resultnot 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
@coverstags. - 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
- [x]
Requests\Tests\ChunkedEncodingTest- PR #581 - [ ]
Requests\Tests\CookiesTest- PR series, PR #737 Owner: @jrfnl Status: Ready, waiting to be pulled - [x]
Requests\Tests\EncodingTest- PR #595 - [x]
Requests\Tests\IdnaEncoderTest- PR #549 - [ ]
Requests\Tests\IriTest - [ ]
Requests\Tests\RequestsTest - [ ]
Requests\Tests\SessionTestOwner: @jrfnl Status: WIP - [x]
Requests\Tests\SslTest- PR #551 - [x]
Requests\Tests\Auth\BasicTest- PR #557 - [ ]
Requests\Tests\Cookie\JarTest- PR #734 - [ ]
Requests\Tests\Proxy\HttpTest - [x]
Requests\Tests\Response\HeadersTest- PR #555 - [ ]
Requests\Tests\Transport\BaseTestCase - [ ]
Requests\Tests\Transport\CurlTest - [ ]
Requests\Tests\Transport\FsockopenTest - [x]
Requests\Tests\Utility\FilteredIteratorTest- PR #550 Status: basic review done, could use more improvements and additional tests.
I've updated the issue description to contain a list of additional tasks and an action list so we can keep track of the status of this mini-project.
We'd welcome more people to get involved in this review. If you want to take any of these classes on, just leave a comment to "claim" it and I'll update the above list.