function PhpExtensionsValidatorTest::testPhpExtensionsValidation

Tests that PHP extensions' status are checked by Package Manager.

@dataProvider providerPhpExtensionsValidation

Parameters

string[] $loaded_extensions: The names of the PHP extensions that the validator should think are loaded.

\Drupal\package_manager\ValidationResult[] $expected_status_check_results: The expected validation results during the status check event.

\Drupal\package_manager\ValidationResult[] $expected_life_cycle_results: The expected validation results during pre-create and pre-apply event.

File

core/modules/package_manager/tests/src/Kernel/PhpExtensionsValidatorTest.php, line 69

Class

PhpExtensionsValidatorTest
@covers \Drupal\package_manager\Validator\PhpExtensionsValidator @group package_manager @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testPhpExtensionsValidation(array $loaded_extensions, array $expected_status_check_results, array $expected_life_cycle_results) : void {
    $state = $this->container
        ->get('state');
    // @see \Drupal\package_manager\Validator\PhpExtensionsValidator::isExtensionLoaded()
    $state->set('package_manager_loaded_php_extensions', $loaded_extensions);
    $this->assertStatusCheckResults($expected_status_check_results);
    $this->assertResults($expected_life_cycle_results, PreCreateEvent::class);
    // To test pre-apply delete the loaded extensions in state which will allow
    // the pre-create event to run without a validation error.
    $state->delete('package_manager_loaded_php_extensions');
    // On post-create set the loaded extensions in state so that the pre-apply
    // event will have the expected validation error.
    $this->addEventTestListener(function () use ($state, $loaded_extensions) {
        $state->set('package_manager_loaded_php_extensions', $loaded_extensions);
    }, PostCreateEvent::class);
    $this->assertResults($expected_life_cycle_results, PreApplyEvent::class);
}

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