Documentation

SloppyTestChecker
in package

Detect sloppy tests.

GOALS

Suppose you have these tests:

function setupHeadless() { Civi\Test::headless()->apply(); } function test1() { doStuff(); } function test2() { doOtherStuff(); } function test3() { doMoreStuff(); }

These tests are all based on the same headless configuration. Ideally, we only want to initialize the database once and quickly run through all the test functions.

However, some tests might be sloppy -- perhaps test2() destroys an important setting, which causes test3() to behave erratically. (test3() works on its own but fails in combination with test2().)

The symptoms will present on test3(), but the blame lies with test2(). This class does some sanity-checks and works to point the finger at test2().

USAGE

This feature is opt-in. (Detecting sloppy tests requires extra computation... How much? Not sure yet... Let's get some data before we consider making it mandatory...)

You may enable by setting one of these environment variables:

  • CIVICRM_SLOPPY_TEST=STDERR Print warnings to STDERR
  • CIVICRM_SLOPPY_TEST=Exception Throw an exception
  • CIVICRM_SLOPPY_TEST=@/tmp/sloppy.log Append to a log file

Table of Contents

Methods

createSnapshot()  : array<string|int, mixed>
doComparison()  : void
Determine if $startSnapshot and $endSnapshot match. If they don't, complain about it and blame the $lastParty/$currentParty.
isActive()  : bool
emit()  : void
fetchAll()  : array<string|int, mixed>

Methods

createSnapshot()

public static createSnapshot() : array<string|int, mixed>
Return values
array<string|int, mixed>

doComparison()

Determine if $startSnapshot and $endSnapshot match. If they don't, complain about it and blame the $lastParty/$currentParty.

public static doComparison(array<string|int, mixed> $startSnapshot, array<string|int, mixed> $endSnapshot, string $lastParty, string $currentParty) : void
Parameters
$startSnapshot : array<string|int, mixed>
$endSnapshot : array<string|int, mixed>
$lastParty : string

Ex: 'FooBarTest::testOne()'

$currentParty : string

Ex: 'FooBarTest::testTwo()'

emit()

protected static emit(string $message) : void
Parameters
$message : string

fetchAll()

protected static fetchAll(string $query, array<string|int, mixed> $index) : array<string|int, mixed>
Parameters
$query : string
$index : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results