You are here

class PackageTest in Features 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/PackageTest.php \Drupal\Tests\features\Unit\PackageTest

@coversDefaultClass \Drupal\features\Package @group features

Hierarchy

  • class \Drupal\Tests\features\Unit\PackageTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of PackageTest

File

tests/src/Unit/PackageTest.php, line 12

Namespace

Drupal\Tests\features\Unit
View source
class PackageTest extends TestCase {

  /**
   * @covers ::setDependencies
   */
  public function testSetDependencies() {
    $package = new Package('test_feature', []);
    $this
      ->assertEquals([], $package
      ->getDependencies());
    $package
      ->setDependencies([
      'some_module',
      'my_module',
      'my_module',
      'test_feature',
    ]);

    // Test that duplicates are removed, results sorted, and the package cannot

    /// require itself.
    $expected = [
      'my_module',
      'some_module',
    ];
    $this
      ->assertEquals($expected, $package
      ->getDependencies());
  }

  /**
   * @covers ::appendDependency
   */
  public function testAppendDependency() {
    $package = new Package('test_feature', []);
    $this
      ->assertEquals([], $package
      ->getDependencies());
    $dependencies = [
      'some_module',
      'my_module',
      'my_module',
      'test_feature',
    ];
    foreach ($dependencies as $dependency) {
      $package
        ->appendDependency($dependency);
    }

    // Test that duplicates are removed, results sorted, and the package cannot

    /// require itself.
    $expected = [
      'my_module',
      'some_module',
    ];
    $this
      ->assertEquals($expected, $package
      ->getDependencies());
  }

  /**
   * @covers ::setFeaturesInfo
   */
  public function testSetFeaturesInfo() {
    $package = new Package('test_feature', []);
    $this
      ->assertEquals([], $package
      ->getFeaturesInfo());
    $package
      ->setFeaturesInfo([
      'bundle' => 'test_bundle',
    ]);
    $this
      ->assertEquals([
      'bundle' => 'test_bundle',
    ], $package
      ->getFeaturesInfo());
    $this
      ->assertEquals('test_bundle', $package
      ->getBundle());
  }

  /**
   * {@inheritDoc}
   */
  public function testGetConfig() {
    $package = new Package('test_feature', [
      'config' => [
        'test_config_a',
        'test_config_b',
      ],
    ]);
    $this
      ->assertEquals([
      'test_config_a',
      'test_config_b',
    ], $package
      ->getConfig());
    return $package;
  }

  /**
   * The test append config.
   *
   * @depends testGetConfig
   * @covers ::appendConfig
   */
  public function testAppendConfig(Package $package) {
    $package
      ->appendConfig('test_config_a');
    $package
      ->appendConfig('test_config_c');
    $this
      ->assertEquals([
      'test_config_a',
      'test_config_b',
      'test_config_c',
    ], array_values($package
      ->getConfig()));
    return $package;
  }

  /**
   * The test remove config.
   *
   * @depends testAppendConfig
   * @covers ::removeConfig
   */
  public function testRemoveConfig(Package $package) {
    $package
      ->removeConfig('test_config_a');
    $this
      ->assertEquals([
      'test_config_b',
      'test_config_c',
    ], array_values($package
      ->getConfig()));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PackageTest::testAppendConfig public function The test append config.
PackageTest::testAppendDependency public function @covers ::appendDependency
PackageTest::testGetConfig public function
PackageTest::testRemoveConfig public function The test remove config.
PackageTest::testSetDependencies public function @covers ::setDependencies
PackageTest::testSetFeaturesInfo public function @covers ::setFeaturesInfo