function LockFileValidatorTest::testLockFileChanged

Tests validation when the lock file has changed.

@dataProvider providerValidateStageEvents

File

core/modules/package_manager/tests/src/Kernel/LockFileValidatorTest.php, line 106

Class

LockFileValidatorTest
@coversDefaultClass \Drupal\package_manager\Validator\LockFileValidator[[api-linebreak]] @group package_manager @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testLockFileChanged(string $event_class) : void {
  // Add a listener with an extremely high priority to the same event that
  // should raise the validation error. Because the validator uses the default
  // priority of 0, this listener changes lock file before the validator
  // runs.
  $this->addEventTestListener(function () {
    $lock = json_decode(file_get_contents($this->activeDir . '/composer.lock'), TRUE, flags: JSON_THROW_ON_ERROR);
    $lock['extra']['key'] = 'value';
    file_put_contents($this->activeDir . '/composer.lock', json_encode($lock, JSON_THROW_ON_ERROR));
  }, $event_class);
  $result = ValidationResult::createError([
    $this->t('Unexpected changes were detected in the active lock file (@file), which indicates that other Composer operations were performed since this Package Manager operation started. This can put the code base into an unreliable state and therefore is not allowed.', [
      '@file' => $this->activeDir . '/composer.lock',
    ]),
  ], $this->t('Problem detected in lock file during stage operations.'));
  $stage = $this->assertResults([
    $result,
  ], $event_class);
  // A status check should agree that there is an error here.
  $this->assertStatusCheckResults([
    $result,
  ], $stage);
}

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