function AddClassTest::addBadDataProvider

Same name in other branches
  1. 4.0.x modules/phpunit_example/tests/src/Unit/AddClassTest.php \Drupal\Tests\phpunit_example\Unit\AddClassTest::addBadDataProvider()

Data provider for testAddWithBadDataProvider().

Since AddClass::add() can throw exceptions, it's time to give it some data that will cause these exceptions.

add() should throw exceptions if either of it's arguments are not numeric, and we will generate some test data to prove that this is what it actually does.

See also

self::testAddWithBadDataProvider()

File

modules/phpunit_example/tests/src/Unit/AddClassTest.php, line 157

Class

AddClassTest
AddClass units tests.

Namespace

Drupal\Tests\phpunit_example\Unit

Code

public function addBadDataProvider() {
    $bad_data = [];
    // Set up an array with data that should cause add()
    // to throw an exception.
    $bad_data_types = [
        'string',
        FALSE,
        [
            'foo',
        ],
        new \stdClass(),
    ];
    // Create some data where both $a and $b are bad types.
    foreach ($bad_data_types as $bad_datum_a) {
        foreach ($bad_data_types as $bad_datum_b) {
            $bad_data[] = [
                $bad_datum_a,
                $bad_datum_b,
            ];
        }
    }
    // Create some data where $a is good and $b is bad.
    foreach ($bad_data_types as $bad_datum_b) {
        $bad_data[] = [
            1,
            $bad_datum_b,
        ];
    }
    // Create some data where $b is good and $a is bad.
    foreach ($bad_data_types as $bad_datum_a) {
        $bad_data[] = [
            $bad_datum_a,
            1,
        ];
    }
    return $bad_data;
}