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

feat: add support for Composer 2.x #6

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Tests

on: ['push', 'pull_request']

jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
php: ['7.3', '7.4', '8.0']
dependency-version: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer
coverage: none

- name: Setup Problem Matches
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install PHP dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress --ansi

- name: Unit Tests
run: vendor/bin/phpunit --colors=always
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
}
],
"require": {
"composer-plugin-api": "~1.0",
"symfony/filesystem": "^3.0"
"composer-plugin-api": "^1.0 || ^2.0",
"symfony/filesystem": "^3.0 || ^4.0 || ^5.0"
},
"require-dev": {
"composer/composer": "^1.4",
"phpunit/phpunit": "~4.4"
"composer/composer": "^1.10 || ^2.0",
"phpunit/phpunit": "^8.5.12 || ^9.3"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 6 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,22 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
bootstrap="tests/bootstrap.php"
bootstrap="vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Composer Assets Installer test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<file>../src/AssetsInstaller</file>
<exclude>
<directory>vendor</directory>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="log/report" charset="UTF-8"
yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"/>
<log type="testdox-html" target="log/testdox.html" />
</logging>
<coverage>
<include>
<file>src/AssetsInstaller</file>
</include>
</coverage>
</phpunit>
10 changes: 10 additions & 0 deletions src/AssetsInstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ public function onPostInstall(Event $event)
{
$this->assetsInstaller->install();
}

/** {@inheritDoc} */
public function deactivate(Composer $composer, IOInterface $io)
{
}

/** {@inheritDoc} */
public function uninstall(Composer $composer, IOInterface $io)
{
}
}
12 changes: 0 additions & 12 deletions tests/bootstrap.php

This file was deleted.

34 changes: 0 additions & 34 deletions tests/phpunit.xml

This file was deleted.

32 changes: 18 additions & 14 deletions tests/src/AssetsInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
* file that was distributed with this source code.
*/

use ReputationVIP\Composer\AssetsInstaller;
use Composer\Config;
use Composer\Composer;
use Composer\IO\NullIO;
use Composer\Package;
use Composer\Package\Link;
use Composer\Json\JsonFile;
use Composer\Package\Package;
use PHPUnit\Framework\TestCase;
use Composer\Installer\InstallationManager;
use ReputationVIP\Composer\AssetsInstaller;
use ReputationVIP\Composer\DirectoryHandler;
use Symfony\Component\Filesystem\Filesystem;

class AssetsInstallerTest extends \PHPUnit_Framework_TestCase
class AssetsInstallerTest extends TestCase
{
const NS_DEFAULT = 'default';

Expand Down Expand Up @@ -217,9 +223,7 @@ private function getAssetsInstaller($packageNs = self::NS_DEFAULT, $linksNs = se
$directoryHandler = $this->getDirectoryHandler($directoryHandlerNs);
$io = $this->getIO();

$fsStub = $this
->getMockBuilder('Symfony\Component\Filesystem\Filesystem')
->getMock();
$fsStub = $this->createMock(Filesystem::class);
$fsStub
->method('exists')
->willReturn(true);
Expand All @@ -231,12 +235,12 @@ private function getMockPackage($packageNs = self::NS_DEFAULT, $linksNs = self::
{
$mockPackageData = $this->mockPackage[$packageNs];

$jsonFileReader = $this->getMock('JsonFile', array('read'));
$jsonFileReader = $this->createPartialMock(JsonFile::class, array('read'));
$jsonFileReader->expects($this->any())
->method('read')
->will($this->returnValue($mockPackageData['jsonFile']));

$package = $this->getMock('Package', array('getExtra', 'getName', 'getRequires', 'getTarget'));
$package = $this->createPartialMock(Package::class, array('getExtra', 'getName', 'getRequires', 'getTarget', 'getJsonFile'));
$package->expects($this->any())
->method('getExtra')
->will($this->returnValue($mockPackageData['extra']));
Expand All @@ -258,13 +262,13 @@ private function getMockPackage($packageNs = self::NS_DEFAULT, $linksNs = self::
private function getComposer($package, $packageNs = self::NS_DEFAULT)
{
$mockPackageData = $this->mockPackage[$packageNs];
$installationManager = $this->getMock('InstallationManager', array('getInstallPath'));
$installationManager = $this->createPartialMock(InstallationManager::class, array('getInstallPath'));
$installationManager->expects($this->any())
->method('getInstallPath')
//->with($package)
->will($this->returnValue($mockPackageData['installPath']));

$composer = $this->getMock('Composer', array('getPackage', 'getInstallationManager'));
$composer = $this->createPartialMock(Composer::class, array('getPackage', 'getInstallationManager'));
$composer->expects($this->any())
->method('getPackage')
->will($this->returnValue($package));
Expand All @@ -277,7 +281,7 @@ private function getComposer($package, $packageNs = self::NS_DEFAULT)
private function getDirectoryHandler($directoryHandlerNs = self::NS_DEFAULT)
{
$directoryHandlerData = $this->mockDirectoryHandler[$directoryHandlerNs];
$directoryHandler = $this->getMock('DirectoryHandler', array('isDirectory', 'copyDirectory', 'deleteDirectory'));
$directoryHandler = $this->createPartialMock(DirectoryHandler::class, array('isDirectory', 'copyDirectory', 'deleteDirectory'));
$directoryHandler->expects($this->any())
->method('isDirectory')
->will($this->returnValue($directoryHandlerData['isDirectory']));
Expand All @@ -301,12 +305,12 @@ private function getMockPackagesLinks($mockLinksNs)

private function getMockPackageLink($mockLinkData)
{
$jsonFileReader = $this->getMock('JsonFile', array('read'));
$jsonFileReader = $this->createPartialMock(JsonFile::class, array('read'));
$jsonFileReader->expects($this->any())
->method('read')
->will($this->returnValue($mockLinkData['jsonFile']));

$link = $this->getMock('Link', array('getTarget', 'getJsonFile'));
$link = $this->createPartialMock(Link::class, array('getTarget', 'getJsonFile'));
$link->expects($this->any())
->method('getTarget')
->will($this->returnValue($mockLinkData['target']));
Expand Down