DEV Community

Discussion on: Keeping (large) data providers organized in PHPUnit

Collapse
 
nilithus profile image
Byron Nagi

Fun fact an alternate way to set the test case name -- instead of using setName in the test -- is to put the name of the test as the key value in the data provider. For example:

public function sessionDataProvider(): array
{
    return [
        'Fresh Session' => [
            'session' => [],
            'showLogin' => true,
            'showUpgrade' => false,
            'showPrimaryButton' => true,
        ]
    ];
}

Failing tests should output 'Fresh Session' instead of 'data set #0'

Collapse
 
erikbooij profile image
Erik Booij

You're absolutely right, I didn't realize that before and also didn't notice it when writing up the code samples 🤦‍♂️ I've updated the post to reflect this. Thanks!