You are here

class TestInfoParsingTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php \Drupal\Tests\simpletest\Unit\TestInfoParsingTest

@coversDefaultClass \Drupal\simpletest\TestDiscovery @group simpletest

Hierarchy

Expanded class hierarchy of TestInfoParsingTest

File

core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php, line 16
Contains \Drupal\Tests\simpletest\Unit\TestInfoParsingTest.

Namespace

Drupal\Tests\simpletest\Unit
View source
class TestInfoParsingTest extends UnitTestCase {

  /**
   * @covers ::getTestInfo
   * @dataProvider infoParserProvider
   */
  public function testTestInfoParser($expected, $classname, $doc_comment = NULL) {
    $info = \Drupal\simpletest\TestDiscovery::getTestInfo($classname, $doc_comment);
    $this
      ->assertEquals($expected, $info);
  }
  public function infoParserProvider() {

    // A module provided unit test.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\Tests\\simpletest\\Unit\\TestInfoParsingTest',
        'group' => 'PHPUnit',
        'description' => 'Tests \\Drupal\\simpletest\\TestDiscovery.',
      ],
      // Classname.
      'Drupal\\Tests\\simpletest\\Unit\\TestInfoParsingTest',
    ];

    // A core unit test.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\Tests\\Core\\DrupalTest',
        'group' => 'PHPUnit',
        'description' => 'Tests \\Drupal.',
      ],
      // Classname.
      'Drupal\\Tests\\Core\\DrupalTest',
    ];

    // Functional PHPUnit test.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\Tests\\simpletest\\Functional\\BrowserTestBaseTest',
        'group' => 'simpletest',
        'description' => 'Tests BrowserTestBase functionality.',
      ],
      // Classname.
      'Drupal\\Tests\\simpletest\\Functional\\BrowserTestBaseTest',
    ];

    // Simpletest classes can not be autoloaded in a PHPUnit test, therefore
    // provide a docblock.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\field\\Tests\\BulkDeleteTest',
        'group' => 'field',
        'description' => 'Bulk delete storages and fields, and clean up afterwards.',
      ],
      // Classname.
      'Drupal\\field\\Tests\\BulkDeleteTest',
      // Doc block.
      "/**\n * Bulk delete storages and fields, and clean up afterwards.\n *\n * @group field\n */\n ",
    ];

    // Test with a different amount of leading spaces.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\field\\Tests\\BulkDeleteTest',
        'group' => 'field',
        'description' => 'Bulk delete storages and fields, and clean up afterwards.',
      ],
      // Classname.
      'Drupal\\field\\Tests\\BulkDeleteTest',
      // Doc block.
      "/**\n   * Bulk delete storages and fields, and clean up afterwards.\n   *\n   * @group field\n   */\n ",
    ];

    // Make sure that a "* @" inside a string does not get parsed as an
    // annotation.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\field\\Tests\\BulkDeleteTest',
        'group' => 'field',
        'description' => 'Bulk delete storages and fields, and clean up afterwards. * @',
      ],
      // Classname.
      'Drupal\\field\\Tests\\BulkDeleteTest',
      // Doc block.
      "/**\n   * Bulk delete storages and fields, and clean up afterwards. * @\n   *\n   * @group field\n   */\n ",
    ];

    // Multiple @group annotations.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\field\\Tests\\BulkDeleteTest',
        'group' => 'Test',
        'description' => 'Bulk delete storages and fields, and clean up afterwards.',
      ],
      // Classname.
      'Drupal\\field\\Tests\\BulkDeleteTest',
      // Doc block.
      "/**\n * Bulk delete storages and fields, and clean up afterwards.\n *\n * @group Test\n * @group field\n */\n ",
    ];

    // @dependencies annotation.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\field\\Tests\\BulkDeleteTest',
        'group' => 'field',
        'description' => 'Bulk delete storages and fields, and clean up afterwards.',
        'requires' => [
          'module' => [
            'test',
          ],
        ],
      ],
      // Classname.
      'Drupal\\field\\Tests\\BulkDeleteTest',
      // Doc block.
      "/**\n * Bulk delete storages and fields, and clean up afterwards.\n *\n * @dependencies test\n * @group field\n */\n ",
    ];

    // Multiple @dependencies annotation.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\field\\Tests\\BulkDeleteTest',
        'group' => 'field',
        'description' => 'Bulk delete storages and fields, and clean up afterwards.',
        'requires' => [
          'module' => [
            'test',
            'test1',
            'test2',
          ],
        ],
      ],
      // Classname.
      'Drupal\\field\\Tests\\BulkDeleteTest',
      // Doc block.
      "/**\n * Bulk delete storages and fields, and clean up afterwards.\n *\n * @dependencies test, test1,test2\n * @group field\n */\n ",
    ];

    // Multi-line summary line.
    $tests[] = [
      // Expected result.
      [
        'name' => 'Drupal\\field\\Tests\\BulkDeleteTest',
        'group' => 'field',
        'description' => 'Bulk delete storages and fields, and clean up afterwards. And the summary line continues and there is no gap to the annotation.',
      ],
      // Classname.
      'Drupal\\field\\Tests\\BulkDeleteTest',
      // Doc block.
      "/**\n * Bulk delete storages and fields, and clean up afterwards. And the summary\n * line continues and there is no gap to the annotation.\n * @group field\n */\n ",
    ];
    return $tests;
  }

  /**
   * @covers ::getTestInfo
   * @expectedException \Drupal\simpletest\Exception\MissingGroupException
   * @expectedExceptionMessage Missing @group annotation in Drupal\field\Tests\BulkDeleteTest
   */
  public function testTestInfoParserMissingGroup() {
    $classname = 'Drupal\\field\\Tests\\BulkDeleteTest';
    $doc_comment = <<<EOT
/**
 * Bulk delete storages and fields, and clean up afterwards.
 */
EOT;
    \Drupal\simpletest\TestDiscovery::getTestInfo($classname, $doc_comment);
  }

  /**
   * @covers ::getTestInfo
   */
  public function testTestInfoParserMissingSummary() {
    $classname = 'Drupal\\field\\Tests\\BulkDeleteTest';
    $doc_comment = <<<EOT
/**
 * @group field
 */
EOT;
    $info = \Drupal\simpletest\TestDiscovery::getTestInfo($classname, $doc_comment);
    $this
      ->assertEmpty($info['description']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TestInfoParsingTest::infoParserProvider public function
TestInfoParsingTest::testTestInfoParser public function @covers ::getTestInfo @dataProvider infoParserProvider
TestInfoParsingTest::testTestInfoParserMissingGroup public function @covers ::getTestInfo @expectedException \Drupal\simpletest\Exception\MissingGroupException @expectedExceptionMessage Missing @group annotation in Drupal\field\Tests\BulkDeleteTest
TestInfoParsingTest::testTestInfoParserMissingSummary public function @covers ::getTestInfo
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 259