abstract class ContentLoaderTestBase in YAML Content 8
Base test class for all ContentLoader testing.
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\yaml_content\Unit\ContentLoader\ContentLoaderTestBase
Expanded class hierarchy of ContentLoaderTestBase
File
- tests/
src/ Unit/ ContentLoader/ ContentLoaderTestBase.php, line 12
Namespace
Drupal\Tests\yaml_content\Unit\ContentLoaderView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentLoaderTestBase:: |
protected | property | A prepared ContentLoader object for testing. | |
ContentLoaderTestBase:: |
protected | function | Create a test file with specified contents for testing. | |
ContentLoaderTestBase:: |
protected | function | Mock the ContentLoader class to support test inspections. | |
ContentLoaderTestBase:: |
public | function |
Overrides UnitTestCase:: |
|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |