WordPress / WordPress/Requests

Test: review all tests to stabilize them more

Open
#497 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Status: help wanted Type: testing/chores/QA
Dominant language
PHP
Stars
3.6k
Forks
500
Avg merge
2d 21h
Merged PRs (30d)
5

Description

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
  • Requests\Tests\ChunkedEncodingTest - PR #581
  • Requests\Tests\CookiesTest - PR series, PR #737
    Owner: @jrfnl
    Status: Ready, waiting to be pulled
  • Requests\Tests\EncodingTest - PR #595
  • Requests\Tests\IdnaEncoderTest - PR #549
  • Requests\Tests\IriTest
  • Requests\Tests\RequestsTest
  • Requests\Tests\SessionTest
    Owner: @jrfnl
    Status: WIP
  • Requests\Tests\SslTest - PR #551
  • Requests\Tests\Auth\BasicTest - PR #557
  • Requests\Tests\Cookie\JarTest - PR #734
  • Requests\Tests\Proxy\HttpTest
  • Requests\Tests\Response\HeadersTest - PR #555
  • Requests\Tests\Transport\BaseTestCase
  • Requests\Tests\Transport\CurlTest
  • Requests\Tests\Transport\FsockopenTest
  • Requests\Tests\Utility\FilteredIteratorTest - PR #550
    Status: basic review done, could use more improvements and additional tests.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the completed test cleanups in PRs #581, #595, #549, #551, #557, #555, and #550, then inspect the unchecked classes such as Requests\Tests\IriTest, Requests\Tests\RequestsTest, and Requests\Tests\Proxy\HttpTest. Stabilize unsafe assertions, add messages to multiple assertions, and address the listed optional review tasks; done means the remaining test classes have been reviewed and the suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing-qa
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.