-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drastically simplify using Composer Runtime API (#65)
--------- Co-authored-by: Moshe Weitzman <[email protected]>
- Loading branch information
Showing
15 changed files
with
206 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/composer.lock | ||
/vendor/ | ||
/.phpunit.result.cache | ||
/tests/fixtures/custom-vendor/foo | ||
/tests/fixtures/default/web | ||
/tests/fixtures/default/vendor | ||
/tests/fixtures/*/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \DrupalFinder\DrupalFinderComposerRuntime. | ||
*/ | ||
|
||
namespace DrupalFinder; | ||
|
||
use Composer\InstalledVersions; | ||
|
||
class DrupalFinderComposerRuntime | ||
{ | ||
/** | ||
* Get the Drupal root path. | ||
*/ | ||
public function getDrupalRoot(): ?string | ||
{ | ||
$core = InstalledVersions::getInstallPath('drupal/core'); | ||
return $core ? realpath(dirname($core)) : null; | ||
} | ||
|
||
/** | ||
* Get the path to the Composer root directory. | ||
*/ | ||
public function getComposerRoot(): ?string | ||
{ | ||
$root = InstalledVersions::getRootPackage(); | ||
return realpath($root['install_path']); | ||
} | ||
|
||
/** | ||
* Get the vendor path. | ||
*/ | ||
public function getVendorDir(): ?string | ||
{ | ||
$reflection = new \ReflectionClass(InstalledVersions::class); | ||
return realpath(dirname(dirname($reflection->getFileName()))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace DrupalFinder\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class DrupalFinderComposerRuntimeTest extends TestCase { | ||
|
||
protected const installFixtures = 'Execute "composer install-fixtures" first.'; | ||
|
||
/** | ||
* @runInSeparateProcess | ||
*/ | ||
public function testDefault() { | ||
$basePath = realpath( __DIR__ . '/fixtures/default'); | ||
$this->assertDirectoryExists($basePath . '/vendor', static::installFixtures); | ||
$this->assertDirectoryExists($basePath . '/web', static::installFixtures); | ||
|
||
$result = json_decode(require $basePath . '/drupal-finder.php', TRUE); | ||
$this->assertSame($result['getComposerRoot'], $basePath); | ||
$this->assertSame($result['getVendorDir'], $basePath . '/vendor'); | ||
$this->assertSame($result['getDrupalRoot'], $basePath . '/web'); | ||
} | ||
|
||
/** | ||
* @runInSeparateProcess | ||
*/ | ||
public function testCustomVendor() { | ||
$basePath = realpath( __DIR__ . '/fixtures/custom-vendor'); | ||
$this->assertDirectoryExists($basePath . '/foo/bar', static::installFixtures); | ||
$this->assertDirectoryExists($basePath . '/foo/bar/drupal', static::installFixtures); | ||
|
||
$result = json_decode(require $basePath . '/drupal-finder.php', TRUE); | ||
$this->assertSame($result['getComposerRoot'], $basePath); | ||
$this->assertSame($result['getVendorDir'], $basePath . '/foo/bar'); | ||
$this->assertSame($result['getDrupalRoot'], $basePath . '/foo/bar/drupal'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"repositories": { | ||
"drupal-finder": { | ||
"type": "path", | ||
"url": "../../../" | ||
} | ||
}, | ||
"require": { | ||
"webflo/drupal-finder": "*", | ||
"drupal/core": "^10" | ||
}, | ||
"config": { | ||
"vendor-dir": "foo/bar" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
use DrupalFinder\DrupalFinderComposerRuntime; | ||
|
||
require __DIR__ . '/foo/bar/autoload.php'; | ||
|
||
$finder = new DrupalFinderComposerRuntime(); | ||
|
||
return json_encode([ | ||
'getComposerRoot' => $finder->getComposerRoot(), | ||
'getVendorDir' => $finder->getVendorDir(), | ||
'getDrupalRoot' => $finder->getDrupalRoot(), | ||
] | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"repositories": { | ||
"drupal-finder": { | ||
"type": "path", | ||
"url": "../../../" | ||
} | ||
}, | ||
"require": { | ||
"composer/installers": "^2.2", | ||
"drupal/core": "^10", | ||
"webflo/drupal-finder": "*" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"composer/installers": true | ||
} | ||
}, | ||
"extra": { | ||
"installer-paths": { | ||
"web/core": [ | ||
"type:drupal-core" | ||
] | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
use DrupalFinder\DrupalFinderComposerRuntime; | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
|
||
$finder = new DrupalFinderComposerRuntime(); | ||
|
||
return json_encode([ | ||
'getComposerRoot' => $finder->getComposerRoot(), | ||
'getVendorDir' => $finder->getVendorDir(), | ||
'getDrupalRoot' => $finder->getDrupalRoot(), | ||
] | ||
); |