Skip to content

Commit 4d98a97

Browse files
committed
Implement composer v2 support
Refactor testsuite to make sure composer v2 is fully compatible and change the constraints. Remove const private qualifier to fix php 5.6 compat Fix travis unwritable bindir problem Reduce the nr of PHP versions tested Fix travis script Cleanup Fixit
1 parent 1474d84 commit 4d98a97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2107
-998
lines changed

.travis.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,39 @@ sudo: false
33
dist: trusty
44

55
cache:
6-
directories:
7-
- vendor
8-
- $HOME/.composer/cache
6+
directories:
7+
- vendor
8+
- $HOME/.composer/cache
9+
10+
env:
11+
global:
12+
- COMPOSER_SANDBOX_TMPDIR="$HOME/.tmp"
13+
- COMPOSER_SANDBOX_EXTRA_ARGS="-vv"
14+
- IGNORE_PLATFORM_REQS=""
15+
jobs:
16+
- COMPOSER_VERSION="1"
17+
- COMPOSER_VERSION="2"
918

1019
php:
1120
- 5.6
1221
- 7.0
13-
- 7.1
14-
- 7.2
15-
- 7.3
16-
- nightly
22+
- 7.4
23+
24+
jobs:
25+
include:
26+
# Test PHP 8.0+ only with composer v2 while ignoring platform reqs
27+
# so conflicting dependencies like Symfony polyfills are not installed.
28+
- php: 8.0
29+
env: COMPOSER_VERSION="2" IGNORE_PLATFORM_REQS="--ignore-platform-reqs"
30+
- php: nightly
31+
env: COMPOSER_VERSION="2" IGNORE_PLATFORM_REQS="--ignore-platform-reqs"
1732

1833
matrix:
1934
allow_failures:
2035
- php: nightly
36+
- php: 8.0
2137

22-
install:
23-
- travis_retry composer install --ansi --prefer-dist --no-interaction --optimize-autoloader --no-suggest --no-progress
38+
install: travis_retry bin/install-project
2439

25-
script: ./vendor/bin/phpunit --debug --testdox
40+
script: bin/tests-run
41+

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
[![Build Status](https://travis-ci.org/mageops/php-composer-plugin-patchset.svg?branch=master)](https://travis-ci.org/mageops/php-composer-plugin-patchset)
1+
[![Build Status](https://travis-ci.com/mageops/php-composer-plugin-patchset.svg?branch=master)](https://travis-ci.com/mageops/php-composer-plugin-patchset)
22

33
Composer Plugin For Applying Patchsets
44
======================================
55

6+
> ‼️ **NEW** Supports both composer branches _v1.x_ and _v2.x_.
7+
68
This plugin can automatically apply patches to any dependency of your project.
79

810
One of the most distinguishing features is that it can apply patches from special composer packages of type `patchset`.
@@ -92,13 +94,13 @@ plugins have done their work so patching source files in vendor will have no eff
9294

9395
## Why no remote patches
9496

95-
This plugin will not download patches from external sources directly (http). I consider this a bad practice and will
96-
never support it. I won't even comment on downloading patches using unencrypted connection without SHA check. Also what
97-
if somebody wants to use your software in 2 years and the patches are no longer available?
98-
99-
Also you will not be able to specify patches in any composer package. You have to use a dedicated packages for this
100-
purpose. I can hardly imagine a legit use case when it would be desirable that installing package X will automatically
101-
patch some other package Y in your project without explicitly being advertised as a patchset.
97+
This plugin will not download patches from external sources directly (http). I consider this a bad practice and will
98+
never support it. I won't even comment on downloading patches using unencrypted connection without SHA check. Also what
99+
if somebody wants to use your software in 2 years and the patches are no longer available?
100+
101+
Also you will not be able to specify patches in any composer package. You have to use a dedicated packages for this
102+
purpose. I can hardly imagine a legit use case when it would be desirable that installing package X will automatically
103+
patch some other package Y in your project without explicitly being advertised as a patchset.
102104

103105

104106

bin/composer-installer

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
include __DIR__ . '/../vendor/autoload.php';
5+
6+
use Pinkeen\ComposerPharInstaller\ComposerPharInstaller;
7+
8+
ComposerPharInstaller::passthru();

bin/install-composer

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
define('COMPOSER_PHAR_INSTALLER_NO_AUTO_PASSTHRU', 1);
5+
6+
include __DIR__ . '/../tests/installer/ComposerPharInstaller.php';
7+
8+
use Pinkeen\ComposerPharInstaller\ComposerPharInstaller;
9+
10+
if (!$composerVersion = getenv('COMPOSER_VERSION')) {
11+
$composerVersion = '2';
12+
}
13+
14+
15+
if (!$tempRootDir = getenv('COMPOSER_SANDBOX_TMPDIR')) {
16+
$tempRootDir = sys_get_temp_dir();
17+
}
18+
19+
$composerPharInstallDir = $tempRootDir . '/' . uniqid('composer-phar-');
20+
$composerPharFilename = "composer-v$composerVersion.phar";
21+
$composerPharFilepath = "$composerPharInstallDir/$composerPharFilename";
22+
23+
if (false === mkdir($composerPharInstallDir, 0775, true)) {
24+
fprintf(STDERR, "Could not create composer installation temp dir: %s \n", $composerPharInstallDir);
25+
exit(1);
26+
}
27+
28+
ComposerPharInstaller::setComposerHome($composerPharInstallDir);
29+
ComposerPharInstaller::mustInstall(
30+
$composerVersion,
31+
$composerPharInstallDir,
32+
$composerPharFilename,
33+
true
34+
);

bin/install-project

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
include_once(__DIR__ . '/install-composer');
5+
6+
passthru(
7+
sprintf(
8+
"%s update --working-dir %s --ansi --prefer-dist --no-interaction --optimize-autoloader --no-progress --no-plugins",
9+
escapeshellarg($composerPharFilepath),
10+
escapeshellarg(realpath(__DIR__ . '/../'))
11+
),
12+
$code
13+
);
14+
15+
return $code;

bin/tests-run

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (!file_exists(__DIR__ . '/../vendor/autoload.php') || getenv('FORCE_PROJECT_INSTALL')) {
5+
if (0 !== $code = include(__DIR__ . '/install-project')) {
6+
exit($code);
7+
}
8+
}
9+
10+
include_once(__DIR__ . '/install-composer');
11+
12+
putenv("COMPOSER_SANDBOX_COMPOSER=$composerPharFilepath");
13+
putenv("COMPOSER_SANDBOX_TMPDIR=$tempRootDir");
14+
15+
$phpUnitCmdStr = sprintf('%s --debug --verbose %s',
16+
realpath(__DIR__ . '/../vendor/bin/phpunit'),
17+
implode(' ', array_map('escapeshellarg', array_slice($argv, 1)))
18+
);
19+
20+
21+
fprintf(STDOUT, "Running phpunit: %s\n", $phpUnitCmdStr);
22+
23+
passthru($phpUnitCmdStr, $code);
24+
25+
exit($code);
26+

composer.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@
1212
"require": {
1313
"ext-json": "*",
1414
"php": ">=5.6.0",
15-
"composer-plugin-api": "^1.1"
15+
"composer-plugin-api": "~1.1 | ^2.0"
1616
},
1717
"require-dev": {
18-
"composer/composer": "~1.0",
19-
"composer/satis": "~1.0",
20-
"phpunit/phpunit": "^4.8.35 || ^5.7"
18+
"composer/composer": "^2.0",
19+
"phpunit/phpunit": "~5.7",
20+
"symfony/process": "^3"
2121
},
2222
"autoload": {
2323
"psr-4": {"Creativestyle\\Composer\\Patchset\\": "src"}
2424
},
2525
"autoload-dev": {
26-
"psr-4": {"Creativestyle\\Composer\\Patchset\\Tests\\": "tests"}
26+
"psr-4": {
27+
"Creativestyle\\Composer\\TestingSandbox\\": "tests/sandbox",
28+
"Creativestyle\\Composer\\Patchset\\Tests\\Functional\\": "tests/functional"
29+
},
30+
"classmap": [
31+
"tests/installer/ComposerPharInstaller.php"
32+
]
2733
},
2834
"extra": {
2935
"class": "Creativestyle\\Composer\\Patchset\\Plugin"

docs/testing.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
## Composer sandbox
44

5-
This plugin uses a special sandbox which allows it to run composer as a separate process during testing.
6-
7-
A fake local packagist repository is created from [package definitions](/tests/Functional/Fixtures/Packages)
8-
for the purpose of testing by using internally [Satis](https://github.com/composer/satis) as a library.
5+
This plugin uses a special sandbox which allows it to run composer as a separate process during testing which creates:
6+
- Fake local composer repository in `/repo/packages.json` with all packages defined [package fixtures](/tests/Functional/Fixtures/Packages/).
7+
- Isolated `COMPOSER_HOME` with configuration in `/composer/config.json` that disabled packagist and configures the above repository.
8+
- Project directories in `/project/{test_run}` used for storing dynamically constructed
9+
project used for testing.
910

1011
See the [ComposerSandbox](/tests/Functional/Fixtures/ComposerSandbox.php) class for the details.
1112

@@ -18,4 +19,34 @@ vendor/bin/phpunit --debug
1819
```
1920

2021
It's nice to also add the `--testdox` switch then.
22+
23+
### Override test sandbox settings via environment variables
24+
25+
#### `COMPOSER_SANDBOX_TMPDIR="{{ sys_get_temp_dir() }}"` - Base temporary dir
26+
27+
_Path to base directory used to store temporary files needed for running the tests._
28+
29+
> **Warning!** Never place `TEST_TMP` dir inside your project's working tree as this
30+
> will cause composer to attempt recursively install its own files and all
31+
> hell breaks loose.
32+
#### `COMPOSER_SANDBOX_PHP="{{ PHP_BIN }}"` - Path to php binary
33+
34+
_Path to php used for running composer._
35+
36+
#### `COMPOSER_SANDBOX_COMPOSER="composer"` - Path to composer
37+
38+
_Path to composer binary to use for running the tests._
39+
40+
#### `COMPOSER_SANDBOX_EXTRA_ARGS=""` - Extra arguments for composer
41+
42+
_String that will be appended to every invocation of composer command._
43+
44+
> **Warning!** Arguments passed through env vars must must be space-delimited
45+
> and each argument cannot contain space characters even if they are escaped.
46+
47+
48+
#### `COMPOSER_SANDBOX_TEST_DEBUG` - Enable extra debugging features
49+
50+
If enabled sandbox directories of failed tests are preserved and composer
51+
command output is flushed for every test.
2152

src/Plugin.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
use Composer\Composer;
66
use Composer\EventDispatcher\EventSubscriberInterface;
77
use Composer\IO\IOInterface;
8-
use Composer\Package\PackageInterface;
98
use Composer\Plugin\PluginInterface;
10-
use Composer\Repository\ArrayRepository;
119
use Composer\Script\ScriptEvents;
1210
use Composer\Script\Event as ScriptEvent;
13-
1411
use Composer\Util\ProcessExecutor;
1512
use Psr\Log\LoggerInterface;
1613

@@ -35,13 +32,39 @@ public function activate(Composer $composer, IOInterface $io)
3532
$this->logger = new IOLogger($io);
3633
}
3734

35+
/**
36+
* Remove any hooks from Composer
37+
*
38+
* This will be called when a plugin is deactivated before being
39+
* uninstalled, but also before it gets upgraded to a new version
40+
* so the old one can be deactivated and the new one activated.
41+
*
42+
* @param Composer $composer
43+
* @param IOInterface $io
44+
*/
45+
public function deactivate(Composer $composer, IOInterface $io)
46+
{
47+
}
48+
49+
/**
50+
* Prepare the plugin to be uninstalled
51+
*
52+
* This will be called after deactivate.
53+
*
54+
* @param Composer $composer
55+
* @param IOInterface $io
56+
*/
57+
public function uninstall(Composer $composer, IOInterface $io)
58+
{
59+
}
60+
3861
/**
3962
* {@inheritdoc}
4063
*/
4164
public static function getSubscribedEvents()
4265
{
4366
return [
44-
ScriptEvents::PRE_AUTOLOAD_DUMP => 'onPreAutoloadDump'
67+
ScriptEvents::PRE_AUTOLOAD_DUMP => 'onPreAutoloadDump',
4568
];
4669
}
4770

0 commit comments

Comments
 (0)