Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drastically simplify using Composer Runtime API #64

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['7.2', '7.3', '7.4', '8.0']
php-versions: ['8.1']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -21,5 +21,8 @@ jobs:
- name: Install dependencies
run: composer install

- name: Install fixtures
run: composer install-fixtures

- name: Run unit tests
run: ./vendor/bin/phpunit
4 changes: 4 additions & 0 deletions .gitignore
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
25 changes: 1 addition & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,13 @@ Drupal Finder provides a class to locate a Drupal installation in a given path.
## Usage

```PHP
$drupalFinder = new \DrupalFinder\DrupalFinder(getcwd());
$drupalFinder = new \DrupalFinder\DrupalFinder();

$drupalRoot = $drupalFinder->getDrupalRoot();
$composerRoot = $drupalFinder->getComposerRoot();
$vendorDir = $drupalFinder->getVendorDir();
```

### Environment variables

If a set of environment variables is specified, then Drupal Finder uses those
values to determine the paths of the pertinent directories:

- `DRUPAL_FINDER_DRUPAL_ROOT`
- `DRUPAL_FINDER_COMPOSER_ROOT`
- `DRUPAL_FINDER_VENDOR_DIR`

For example:

- `DRUPAL_FINDER_DRUPAL_ROOT=/var/www/web`
- `DRUPAL_FINDER_COMPOSER_ROOT=/var/www`
- `DRUPAL_FINDER_VENDOR_DIR=/var/www/vendor`

This is useful for situations where you are containerizing an application,
directories may be in odd places, or a composer.json might be missing since it
is unneeded in a final build artifact.

You are not required to set all the environment variables to use this
feature. If you set an environment variable, then its associated getter
function will return the value assigned to the environment variable.

## Examples

- [Drupal Console Launcher](https://github.com/hechoendrupal/drupal-console-launcher)
Expand Down
35 changes: 28 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webflo/drupal-finder",
"description": "Helper class to locate a Drupal installation from a given path.",
"description": "Helper class to locate a Drupal installation.",
"license": "GPL-2.0-or-later",
"type": "library",
"authors": [
Expand All @@ -10,20 +10,41 @@
}
],
"require": {
"ext-json": "*"
"composer-runtime-api": "^2.2",
"php": ">=8.1"
},
"autoload": {
"classmap": [
"src/DrupalFinder.php"
]
"psr-4": {
"DrupalFinder\\": "src/"
weitzman marked this conversation as resolved.
Show resolved Hide resolved
}
},
"autoload-dev": {
"psr-4": {
"DrupalFinder\\Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^8.5.14",
"mikey179/vfsstream": "^1.6"
"phpunit/phpunit": "^10.4"
},
"config": {
"platform": {
"php": "8.1"
}
},
"scripts": {
"install-fixtures": [
"cd tests/fixtures/custom-vendor && composer install",
"cd tests/fixtures/default && composer install"
],
"uninstall-fixtures": [
"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"
],
"reinstall-fixtures": [
"@uninstall-fixtures",
"@install-fixtures"
]
}
}
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<testsuites>
<testsuite name="DrupalFinder Test Suite">
<directory>./tests</directory>
<exclude>./tests/fixtures</exclude>
</testsuite>
</testsuites>
</phpunit>
Loading
Loading