first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Drupal\TestTools\Extension;
use Drupal\Core\Serialization\Yaml;
/**
* Writes the info file and ensures the mtime changes.
*
* @see \Drupal\Component\FileCache\FileCache
* @see \Drupal\Core\Extension\InfoParser
*/
trait InfoWriterTrait {
/**
* Writes the info file and ensures the mtime changes.
*
* @param string $file_path
* The info file path.
* @param array $info
* The info array.
*
* @return void
*/
private function writeInfoFile(string $file_path, array $info): void {
$mtime = file_exists($file_path) ? filemtime($file_path) : FALSE;
file_put_contents($file_path, Yaml::encode($info));
// Ensure mtime changes.
if ($mtime === filemtime($file_path)) {
touch($file_path, max($mtime + 1, time()));
}
}
}

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Drupal\TestTools\Extension;
use Symfony\Component\Process\ExecutableFinder;
/**
* Ensures Composer executable is available, skips test otherwise.
*/
trait RequiresComposerTrait {
/**
* @beforeClass
*/
public static function requiresComposer(): void {
if (!((new ExecutableFinder())->find('composer'))) {
static::markTestSkipped('This test requires the Composer executable to be accessible.');
}
}
}

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Drupal\TestTools\Extension;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Provides methods to access modules' schema.
*/
class SchemaInspector {
/**
* Returns the module's schema specification.
*
* This function can be used to retrieve a schema specification provided by
* hook_schema(), so it allows you to derive your tables from existing
* specifications.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $handler
* The module handler to use for calling schema hook.
* @param string $module
* The module to which the table belongs.
*
* @return array
* An array of schema definition provided by hook_schema().
*
* @see \hook_schema()
*/
public static function getTablesSpecification(ModuleHandlerInterface $handler, string $module): array {
if ($handler->loadInclude($module, 'install')) {
return $handler->invoke($module, 'schema') ?? [];
}
return [];
}
}