public function DiskSpaceValidatorTest::testDiskSpaceValidation in Automatic Updates 8.2
Tests disk space validation.
@dataProvider providerDiskSpaceValidation
Parameters
bool $shared_disk: Whether the root and vendor directories are on the same logical disk.
array $free_space: The free space that should be reported for various locations. The keys are the locations (only 'root', 'vendor', and 'temp' are supported), and the values are the space that should be reported, in a format that can be parsed by \Drupal\Component\Utility\Bytes::toNumber().
\Drupal\automatic_updates\Validation\ValidationResult[] $expected_results: The expected validation results.
File
- tests/
src/ Kernel/ ReadinessValidation/ DiskSpaceValidatorTest.php, line 153
Class
Namespace
Drupal\Tests\automatic_updates\Kernel\ReadinessValidationCode
public function testDiskSpaceValidation(bool $shared_disk, array $free_space, array $expected_results) : void {
$path_locator = $this
->prophesize('\\Drupal\\automatic_updates\\PathLocator');
$path_locator
->getProjectRoot()
->willReturn('root');
$path_locator
->getVendorDirectory()
->willReturn('vendor');
// Create a mocked version of the validator which can be rigged up to return
// specific values for various filesystem checks.
$validator = new class($path_locator
->reveal(), $this->container
->get('string_translation')) extends DiskSpaceValidator {
/**
* Whether the root and vendor directories are on the same logical disk.
*
* @var bool
*/
public $sharedDisk;
/**
* The amount of free space, keyed by location.
*
* @var float[]
*/
public $freeSpace = [];
/**
* {@inheritdoc}
*/
protected function stat(string $path) : array {
return [
'dev' => $this->sharedDisk ? 'disk' : uniqid(),
];
}
/**
* {@inheritdoc}
*/
protected function freeSpace(string $path) : float {
return $this->freeSpace[$path];
}
/**
* {@inheritdoc}
*/
protected function temporaryDirectory() : string {
return 'temp';
}
};
$validator->sharedDisk = $shared_disk;
$validator->freeSpace = array_map([
Bytes::class,
'toNumber',
], $free_space);
$this->container
->set('automatic_updates.disk_space_validator', $validator);
$this
->assertCheckerResultsFromManager($expected_results, TRUE);
}