class FilterArrayTest

Test filter array functions.

Attributes

#[CoversClass(FilterArray::class)] #[Group('Utility')]

Hierarchy

  • class \Drupal\Tests\Component\Utility\FilterArrayTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of FilterArrayTest

File

core/tests/Drupal/Tests/Component/Utility/FilterArrayTest.php, line 16

Namespace

Drupal\Tests\Component\Utility
View source
class FilterArrayTest extends TestCase {
  
  /**
   * Tests removing empty strings.
   *
   * @legacy-covers ::removeEmptyStrings
   */
  public function testRemoveEmptyStrings(array $values, array $expected) : void {
    $this->assertEquals($expected, array_values(FilterArray::removeEmptyStrings($values)));
  }
  
  /**
   * Data provider for testRemoveEmptyStrings().
   *
   * @see testRemoveEmptyStrings()
   */
  public static function providerRemoveEmptyStrings() : \Generator {
    yield 'strings' => [
      [
        '',
        ' ',
        '0',
        'true',
        'false',
      ],
      [
        ' ',
        '0',
        'true',
        'false',
      ],
    ];
    yield 'integers' => [
      [
        -1,
        0,
        1,
      ],
      [
        -1,
        0,
        1,
      ],
    ];
    yield 'null, true, false' => [
      [
        NULL,
        TRUE,
        FALSE,
      ],
      [
        TRUE,
      ],
    ];
    $stringable = new class  implements \Stringable {
      public function __toString() : string {
        return 'foo';
      }

};
    yield 'non-scalar' => [
      [
        new $stringable(),
      ],
      [
        new $stringable(),
      ],
    ];
  }

}

Members

Title Sort descending Modifiers Object type Summary
FilterArrayTest::providerRemoveEmptyStrings public static function Data provider for testRemoveEmptyStrings().
FilterArrayTest::testRemoveEmptyStrings public function Tests removing empty strings.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.