You are here

abstract class ContentLoaderTestBase in YAML Content 8

Base test class for all ContentLoader testing.

Hierarchy

Expanded class hierarchy of ContentLoaderTestBase

File

tests/src/Unit/ContentLoader/ContentLoaderTestBase.php, line 12

Namespace

Drupal\Tests\yaml_content\Unit\ContentLoader
View source
abstract class ContentLoaderTestBase extends UnitTestCase {

  /**
   * A prepared ContentLoader object for testing.
   *
   * @var \Drupal\yaml_content\ContentLoader\ContentLoader
   */
  protected $contentLoader;

  /**
   * Mock the ContentLoader class to support test inspections.
   *
   * Mock the ContentLoader class with a configurable list of stubbed methods.
   *
   * @param array|null $stubbed_methods
   *   (Optional) An array of method names to leave active on the mock object.
   *   All other declared methods on the ContentLoader class will be stubbed. If
   *   this argument is omitted all methods are mocked and execute their
   *   original code.
   *
   * @return \PHPUnit_Framework_MockObject_MockObject
   *   The mocked ContentLoader object with
   */
  protected function getContentLoaderMock($stubbed_methods = NULL) {

    // Partially mock the ContentLoader for testing specific methods.
    $this->contentLoader = $this
      ->getMockBuilder(ContentLoader::class)
      ->disableOriginalConstructor()
      ->setMethods($stubbed_methods)
      ->getMock();
    return $this->contentLoader;
  }

  /**
   * Create a test file with specified contents for testing.
   *
   * @param string $filename
   *   The name of the test file to be created.
   * @param string $contents
   *   The contents to populate into the test file.
   *
   * @return $this
   */
  protected function createContentTestFile($filename, $contents) {
    vfsStream::newFile($filename)
      ->withContent($contents)
      ->at($this->root
      ->getChild('content'));
    return $this;
  }

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

    // Prepare the directory structure.
    $this->root = vfsStream::setup('root');
    vfsStream::newDirectory('content')
      ->at($this->root);
    $this->contentLoader = $this
      ->getContentLoaderMock();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentLoaderTestBase::$contentLoader protected property A prepared ContentLoader object for testing.
ContentLoaderTestBase::createContentTestFile protected function Create a test file with specified contents for testing.
ContentLoaderTestBase::getContentLoaderMock protected function Mock the ContentLoader class to support test inspections.
ContentLoaderTestBase::setUp public function Overrides UnitTestCase::setUp
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.