function ConfigValidationTest::createRecipeWithInvalidDataInFile

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Recipe/ConfigValidationTest.php \Drupal\KernelTests\Core\Recipe\ConfigValidationTest::createRecipeWithInvalidDataInFile()

Creates a recipe with invalid config data in a particular file.

Parameters

string $file: The name of the file (in the recipe's `config` directory) which should have invalid data.

Return value

\Drupal\Core\Recipe\Recipe A wrapper around the created recipe.

1 call to ConfigValidationTest::createRecipeWithInvalidDataInFile()
ConfigValidationTest::testValidatableConfigIsValidated in core/tests/Drupal/KernelTests/Core/Recipe/ConfigValidationTest.php
Tests that the recipe runner only validates config which is validatable.

File

core/tests/Drupal/KernelTests/Core/Recipe/ConfigValidationTest.php, line 36

Class

ConfigValidationTest
@group Recipe

Namespace

Drupal\KernelTests\Core\Recipe

Code

private function createRecipeWithInvalidDataInFile(string $file) : Recipe {
    $dir = uniqid('public://');
    mkdir($dir . '/config', recursive: TRUE);
    $data = file_get_contents($this->getDrupalRoot() . '/core/modules/config/tests/config_test/config/install/config_test.types.yml');
    assert(is_string($data));
    $data = Yaml::decode($data);
    // The `array` key needs to be an array, not an integer. If the config is
    // validated, this will raise a validation error.
    
    /** @var mixed[] $data */
    $data['array'] = 39;
    file_put_contents($dir . '/config/' . $file, Yaml::encode($data));
    $recipe = <<<YAML
name: Config validation test
install:
  - config_test
YAML;
    file_put_contents($dir . '/recipe.yml', $recipe);
    return Recipe::createFromDirectory($dir);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.