You are here

class ExtensionDiscoveryTest in Composer Manager 8

@coversDefaultClass \Drupal\composer_manager\ExtensionDiscovery @group composer_manager

Hierarchy

Expanded class hierarchy of ExtensionDiscoveryTest

File

tests/src/Unit/ExtensionDiscoveryTest.php, line 13

Namespace

Drupal\Tests\composer_manager\Unit
View source
class ExtensionDiscoveryTest extends UnitTestCase {

  /**
   * @var \Drupal\composer_manager\ExtensionDiscovery
   */
  protected $discovery;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();

    // Simulate modules in multiple sites and multiple profiles.
    $structure = [
      'modules' => [
        'test1' => $this
          ->generateModule('test1'),
      ],
      'profiles' => [
        'commons' => [
          'commons.info.yml' => 'type: profile',
          'commons.profile' => '<?php',
          'modules' => [
            'test2' => $this
              ->generateModule('test2'),
          ],
        ],
      ],
      'sites' => [
        'all' => [
          'modules' => [
            'test3' => $this
              ->generateModule('test3'),
          ],
        ],
        'default' => [
          'modules' => [
            'test4' => $this
              ->generateModule('test4'),
          ],
        ],
        'test.site.com' => [
          'profiles' => [
            'commerce_kickstart' => [
              'commerce_kickstart.info.yml' => 'type: profile',
              'commerce_kickstart.profile' => '<?php',
              'modules' => [
                'test5' => $this
                  ->generateModule('test5'),
              ],
            ],
          ],
          'modules' => [
            'test6' => $this
              ->generateModule('test6'),
          ],
        ],
      ],
    ];
    vfsStream::setup('drupal', null, $structure);
    $this->discovery = new ExtensionDiscovery('vfs://drupal');
  }

  /**
   * {@inheritdoc}
   */
  public function tearDown() {
    $this->discovery
      ->resetCache();
  }

  /**
   * @covers ::scan
   * @covers ::getSiteDirectories
   */
  public function testScan() {
    $expected_profiles = [
      'commons',
      'commerce_kickstart',
    ];
    $profiles = $this->discovery
      ->scan('profile');
    $this
      ->assertEquals($expected_profiles, array_keys($profiles));
    $expected_extensions = [
      'test5',
      'test2',
      'test3',
      'test1',
      'test4',
      'test6',
    ];
    $profile_directories = array_map(function ($profile) {
      return $profile
        ->getPath();
    }, $profiles);
    $this->discovery
      ->setProfileDirectories($profile_directories);
    $extensions = $this->discovery
      ->scan('module');
    $this
      ->assertEquals($expected_extensions, array_keys($extensions));
  }

  /**
   * Returns the file structure for a module.
   */
  protected function generateModule($name) {
    return [
      $name . '.module' => '<?php',
      $name . '.info.yml' => 'type: module',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExtensionDiscoveryTest::$discovery protected property
ExtensionDiscoveryTest::generateModule protected function Returns the file structure for a module.
ExtensionDiscoveryTest::setUp public function Overrides UnitTestCase::setUp
ExtensionDiscoveryTest::tearDown public function
ExtensionDiscoveryTest::testScan public function @covers ::scan @covers ::getSiteDirectories
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed 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.