Fixtures example

/** * @coversDefaultClass \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldFileCollection * * @group Scaffold */
class ScaffoldFileCollectionTest extends TestCase {

  /** * @covers ::__construct */
  public function testCreate() {
    $fixtures = new Fixtures();
    $locationReplacements = $fixtures->getLocationReplacements();
    $scaffold_file_fixtures = [
      'fixtures/drupal-assets-fixture' => [
        '[web-root]/index.php' => $fixtures->replaceOp('drupal-assets-fixture', 'index.php'),
        '[web-root]/.htaccess' => $fixtures->replaceOp('drupal-assets-fixture', '.htaccess'),
        '[web-root]/robots.txt' => $fixtures->replaceOp('drupal-assets-fixture', 'robots.txt'),
        '[web-root]/sites/default/default.services.yml' => $fixtures->replaceOp('drupal-assets-fixture', 'default.services.yml'),
      ],
      'fixtures/drupal-profile' => [
        '[web-root]/sites/default/default.services.yml' => $fixtures->replaceOp('drupal-profile', 'profile.default.services.yml'),
      ],
      

  protected $fixtures;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    $this->fileSystem = new Filesystem();
    $this->fixtures = new Fixtures();
    $this->fixtures->createIsolatedComposerCacheDir();
    $this->projectRoot = $this->fixtures->projectRoot();
    // The directory used for creating composer projects to test can be     // configured using the SCAFFOLD_FIXTURE_DIR environment variable. Otherwise     // a directory will be created in the system's temporary directory.     $this->fixturesDir = getenv('SCAFFOLD_FIXTURE_DIR');
    if (!$this->fixturesDir) {
      $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    }
  }

  
/** * The Fixtures directory. * * @var string */
  protected string $fixturesDir;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    $this->fixtures = new Fixtures();
    $this->fixtures->createIsolatedComposerCacheDir();
  }

  /** * Tests upgrading the Composer Scaffold plugin. */
  public function testScaffoldUpgrade() {
    $composerVersionLine = exec('composer --version');
    if (str_contains($composerVersionLine, 'Composer version 2')) {
      $this->markTestSkipped('We cannot run the scaffold upgrade test with Composer 2 until we have a stable version of drupal/core-composer-scaffold to start from that we can install with Composer 2.x.');
    }
    

class AppendOpTest extends TestCase {
  use PhpUnitWarnings;

  /** * @covers ::process */
  public function testProcess() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $options = ScaffoldOptions::create([]);
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());

    // Create a file.     file_put_contents($destination->fullPath(), "# This is a test\n");

    $prepend = $fixtures->sourcePath('drupal-drupal-test-append', 'prepend-to-robots.txt');
    $append = $fixtures->sourcePath('drupal-drupal-test-append', 'append-to-robots.txt');
    $sut = new AppendOp($prepend$append, TRUE);
    

  protected $fixtures;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->fileSystem = new Filesystem();
    $this->fixtures = new Fixtures();
    $this->fixtures->createIsolatedComposerCacheDir();
    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()];
    $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    // Remove any temporary directories et. al. that were created.

  protected $fixtures;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    $this->fileSystem = new Filesystem();
    $this->fixtures = new Fixtures();
    $this->fixtures->createIsolatedComposerCacheDir();
    $this->projectRoot = $this->fixtures->projectRoot();
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    // Remove any temporary directories et. al. that were created.     $this->fixtures->tearDown();
  }

  
$bootstrapper = (new TestBootstrapper())
            ->setOutput(new ConsoleOutput())
            ->setForceInstall(static::parseEnvVar('FORCE_INSTALL', true))
            ->setForceInstallPlugins(static::parseEnvVar('FORCE_INSTALL_PLUGINS', true))
            ->setPlatformEmbedded(static::parseEnvVar('PLATFORM_EMBEDDED'))
            ->setBypassFinals(static::parseEnvVar('BYPASS_FINALS'))
            ->setEnableCommercial(static::parseEnvVar('ENABLE_COMMERCIAL'))
            ->setLoadEnvFile(static::parseEnvVar('LOAD_ENV_FILE', true))
            ->setProjectDir($_ENV['PROJECT_DIR'] ?? null)
            ->bootstrap();

        (new Fixtures())->load(__DIR__ . '/data.json');

        // TODO: Resolve autoloading to [Commercial]/tests/performance/bench so native phpbench `core.extensions` can be used         $fixturePath = $bootstrapper->getProjectDir() . '/custom/plugins/SwagCommercial/tests/performance/bench/Common';
        $symfonyContainer = KernelLifecycleManager::getKernel()->getContainer();
        $container->register('symfony-container', fn () => $symfonyContainer);
        $runGroup = $this->getRunGroup();
        $originalClasses = get_declared_classes();
        foreach ($this->findFixtures($fixturePath) as $fixtureFile) {
            require $fixtureFile;
            $declared = get_declared_classes();
            /** @var string $currentFixtureClass */
            

class SkipOpTest extends TestCase {
  use PhpUnitWarnings;

  /** * @covers ::process */
  public function testProcess() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $options = ScaffoldOptions::create([]);
    $sut = new SkipOp();
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());
    // Test the system under test.     $sut->process($destination$fixtures->io()$options);
    // Assert that the target file was not created.     $this->assertFileDoesNotExist($destination->fullPath());
    // Confirm that expected output was written to our io fixture.     $output = $fixtures->getOutput();
    

class ReplaceOpTest extends TestCase {
  use PhpUnitWarnings;

  /** * @covers ::process */
  public function testProcess() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $source = $fixtures->sourcePath('drupal-assets-fixture', 'robots.txt');
    $options = ScaffoldOptions::create([]);
    $sut = new ReplaceOp($source, TRUE);
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());
    // Test the system under test.     $sut->process($destination$fixtures->io()$options);
    // Assert that the target file was created.     $this->assertFileExists($destination->fullPath());
    // Assert the target contained the contents from the correct scaffold file.


    ];
  }

  /** * Tests all of the various kinds of builders. * * @dataProvider builderTestData */
  public function testBuilder($builderClass$expected) {
    $fixtures = new Fixtures();
    $drupalCoreInfo = $fixtures->drupalCoreComposerFixture();

    $builder = new $builderClass($drupalCoreInfo);
    $generatedJson = $builder->getPackage();

    $this->assertEquals($expected$generatedJson);
  }

}
protected OptionsResolver $resolver;

    /** * Should only be called if the phpbench run matches the TARGET_GROUP const (isolate commercial features) * If fixtures are to be created a "data.json" file must be situated in the same directory * * {@inheritDoc} */
    public function load(Container $container): void
    {
        $dataPath = __DIR__ . '/data.json';
        (new Fixtures())->load($dataPath);
    }

    /** * {@inheritDoc} */
    public function configure(OptionsResolver $resolver): void
    {
    }
}
Home | Imprint | This part of the site doesn't use cookies.