Verified Commit 038c0f8a authored by Jess's avatar Jess
Browse files

Issue #3405360 by neclimdul, xjm: Remove use of TestClass constructor

(cherry picked from commit 48b171f7)
parent ff0d0f48
Loading
Loading
Loading
Loading
Loading
+19 −15
Original line number Diff line number Diff line
@@ -15,12 +15,6 @@
 */
class VariableTest extends TestCase {

  /**
   * A bogus callable for testing ::callableToString().
   */
  public static function fake(): void {
  }

  /**
   * Data provider for testCallableToString().
   *
@@ -28,15 +22,15 @@ public static function fake(): void {
   *   Sets of arguments to pass to the test method.
   */
  public function providerCallableToString(): array {
    $self = static::class;
    $mock = VariableTestMock::class;
    return [
      'string' => [
        "$self::fake",
        "$self::fake",
        "$mock::fake",
        "$mock::fake",
      ],
      'static method as array' => [
        [$self, 'fake'],
        "$self::fake",
        [$mock, 'fake'],
        "$mock::fake",
      ],
      'closure' => [
        function () {
@@ -45,8 +39,8 @@ function () {
        '[closure]',
      ],
      'object method' => [
        [new static(), 'fake'],
        "$self::fake",
        [new VariableTestMock(), 'fake'],
        "$mock::fake",
      ],
      'service method' => [
        'fake_service:method',
@@ -184,11 +178,21 @@ public function testExport($expected, $variable) {

}

class VariableTestMock {

  /**
   * A bogus callable for testing ::callableToString().
   */
  public static function fake(): void {
  }

}

/**
 * No-op test class for VariableTest::testExport().
 *
 * @see Drupal\Tests\Component\Utility\VariableTest::testExport()
 * @see Drupal\Tests\Component\Utility\VariableTest::providerTestExport()
 * @see \Drupal\Tests\Component\Utility\VariableTest::testExport()
 * @see \Drupal\Tests\Component\Utility\VariableTest::providerTestExport()
 */
class StubVariableTestClass {

+7 −18
Original line number Diff line number Diff line
@@ -11,11 +11,13 @@
 */
class AssertContentTraitTest extends UnitTestCase {

  use AssertContentTrait;

  /**
   * @covers ::getTextContent
   */
  public function testGetTextContent() {
    $test = new TestClass();

    $raw_content = <<<EOT

<Head>
@@ -27,23 +29,10 @@ public function testGetTextContent() {
bar
</body>
EOT;
    $test->_setRawContent($raw_content);
    $this->assertStringNotContainsString('foo', $test->_getTextContent());
    $this->assertStringNotContainsString('<body>', $test->_getTextContent());
    $this->assertStringContainsString('bar', $test->_getTextContent());
  }

}

class TestClass extends UnitTestCase {
  use AssertContentTrait;

  public function _setRawContent($content) {
    $this->setRawContent($content);
  }

  public function _getTextContent() {
    return $this->getTextContent();
    $this->setRawContent($raw_content);
    $this->assertStringNotContainsString('foo', $this->getTextContent());
    $this->assertStringNotContainsString('<body>', $this->getTextContent());
    $this->assertStringContainsString('bar', $this->getTextContent());
  }

}