trait LoadFixturesTrait in YAML Content 8
A trait to support loading test fixture data.
Hierarchy
- trait \Drupal\Tests\yaml_content\Traits\LoadFixturesTrait
 
4 files declare their use of LoadFixturesTrait
- EntityLoadHelperTest.php in tests/
src/ Unit/ EntityLoadHelper/ EntityLoadHelperTest.php  - FileTest.php in tests/
src/ Functional/ Plugin/ yaml_content/ process/ FileTest.php  - FileTest.php in tests/
src/ Unit/ Plugin/ yaml_content/ process/ FileTest.php  - ReferenceTest.php in tests/
src/ Unit/ Plugin/ yaml_content/ process/ ReferenceTest.php  
File
- tests/
src/ Traits/ LoadFixturesTrait.php, line 11  
Namespace
Drupal\Tests\yaml_content\TraitsView source
trait LoadFixturesTrait {
  /**
   * Get the base path for fixture content.
   *
   * @return string
   *   The base path for fixture content.
   */
  protected function getFixturePath() {
    return realpath(dirname(__FILE__) . '/../fixtures');
  }
  /**
   * Load content from a fixture file.
   *
   * @param $fixture_name
   *   The name of the file to load.
   * @param array $collection_path
   *   (optional) An array of keys to extract a subset of content from the file.
   *
   * @return array
   *   Content loaded from the fixture.
   */
  protected function loadFixtureContent($fixture_name, array $collection_path = []) {
    $fixture = Yaml::decode(file_get_contents($this
      ->getFixturePath() . "/{$fixture_name}.yml"));
    // Retrieve nested values if the option was provided.
    if (!empty($collection_path)) {
      $fixture = NestedArray::getValue($fixture, $collection_path);
    }
    return $fixture;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            LoadFixturesTrait:: | 
                  protected | function | Get the base path for fixture content. | |
| 
            LoadFixturesTrait:: | 
                  protected | function | Load content from a fixture file. |