Skip to content

Commit

Permalink
Create test for symlink package
Browse files Browse the repository at this point in the history
See #74
  • Loading branch information
jigarius committed Dec 24, 2024
1 parent 7304506 commit f6ff7cf
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
/tests/fixtures/custom-vendor/foo
/tests/fixtures/default/web
/tests/fixtures/default/vendor
/tests/fixtures/*/composer.lock
/tests/fixtures/**/composer.lock
/tests/fixtures/symlink-package/drupal/*
/tests/fixtures/symlink-package/package/vendor
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@
"scripts": {
"install-fixtures": [
"cd tests/fixtures/custom-vendor && composer install",
"cd tests/fixtures/default && composer install"
"cd tests/fixtures/default && composer install",
"cd tests/fixtures/symlink-package/drupal && composer install",
"cd tests/fixtures/symlink-package/package && composer install"
],
"uninstall-fixtures": [
"rm -rf tests/fixtures/*/composer.lock",
"rm -rf tests/fixtures/**/composer.lock",
"rm -rf tests/fixtures/custom-vendor/foo",
"rm -rf tests/fixtures/default/web",
"rm -rf tests/fixtures/default/vendor"
"rm -rf tests/fixtures/default/vendor",
"rm -rf tests/fixtures/symlink-package/drupal/web",
"rm -rf tests/fixtures/symlink-package/drupal/vendor",
"rm -rf tests/fixtures/symlink-package/package/vendor"
],
"reinstall-fixtures": [
"@uninstall-fixtures",
Expand Down
26 changes: 26 additions & 0 deletions tests/DrupalFinderComposerRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,30 @@ public function testCustomVendor() {
$this->assertSame($result['getDrupalRoot'], $basePath . '/foo/bar/drupal');
}

/**
* @runInSeparateProcess
*/
public function testSymlinkPackage() {
$drupalPath = realpath(__DIR__ . '/fixtures/symlink-package/drupal');
$this->assertDirectoryExists("$drupalPath/vendor", static::installFixtures);
$this->assertDirectoryExists("$drupalPath/web", static::installFixtures);

$packagePath = realpath(__DIR__ . '/fixtures/symlink-package/package');
$this->assertDirectoryExists("$packagePath/vendor", static::installFixtures);

$process = new Process(['composer', 'exec', 'symlink-package'], $drupalPath);
$process->run();

// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}

$result = json_decode($process->getOutput(), TRUE);
var_dump($result);
// $this->assertSame($result['getComposerRoot'], $drupalPath);
// $this->assertSame($result['getVendorDir'], $drupalPath . '/vendor');
// $this->assertSame($result['getDrupalRoot'], $drupalPath . '/web');
}

}
44 changes: 44 additions & 0 deletions tests/fixtures/symlink-package/drupal/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"description": "A Drupal project that refers to the local package 'webflo/foo'.",
"type": "project",
"license": "GPL-2.0-or-later",
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
},
"drupal-finder": {
"type": "path",
"url": "../../../"
},
"symlink-package": {
"type": "path",
"url": "../package",
"options": {
"symlink": true
}
}
},
"require": {
"composer/installers": "^2.0",
"drupal/core": "^10",
"webflo/foo": "*"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"allow-plugins": {
"composer/installers": true
}
},
"extra": {
"installer-paths": {
"web/core": [
"type:drupal-core"
]
}
}
}
17 changes: 17 additions & 0 deletions tests/fixtures/symlink-package/package/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "webflo/foo",
"description": "The package that depends on Drupal Finder.",
"repositories": {
"drupal-finder": {
"type": "path",
"url": "../../../"
}
},
"require": {
"webflo/drupal-finder": "*"
},
"bin": [
"symlink-package"
],
"minimum-stability": "dev"
}
14 changes: 14 additions & 0 deletions tests/fixtures/symlink-package/package/symlink-package
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';

use DrupalFinder\DrupalFinderComposerRuntime;

$finder = new DrupalFinderComposerRuntime();

echo json_encode([
'getComposerRoot' => $finder->getComposerRoot(),
'getVendorDir' => $finder->getVendorDir(),
'getDrupalRoot' => $finder->getDrupalRoot(),
]);

0 comments on commit f6ff7cf

Please sign in to comment.