From d05d070136c7c2599550a213996daa9e4c0ef627 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Mon, 30 Nov 2020 15:02:32 +0000 Subject: [PATCH 1/8] feat: add support for Composer 2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 598a967..a136c3d 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "composer-plugin-api": "~1.0", + "composer-plugin-api": "^1.0 || ^2.0", "symfony/filesystem": "^3.0" }, "require-dev": { From e257f5f3fc386cd19aadea0a5d811144ece598e3 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Fri, 4 Jun 2021 10:51:12 +0100 Subject: [PATCH 2/8] chore: update to support Composer 2.x --- composer.json | 6 +++--- src/AssetsInstallerPlugin.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a136c3d..e0f1493 100644 --- a/composer.json +++ b/composer.json @@ -10,11 +10,11 @@ ], "require": { "composer-plugin-api": "^1.0 || ^2.0", - "symfony/filesystem": "^3.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": { diff --git a/src/AssetsInstallerPlugin.php b/src/AssetsInstallerPlugin.php index 9713097..c1894de 100644 --- a/src/AssetsInstallerPlugin.php +++ b/src/AssetsInstallerPlugin.php @@ -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) + { + } } From db30a11756190379cd1f9d9b70ff038aa2f009d8 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Fri, 4 Jun 2021 10:51:45 +0100 Subject: [PATCH 3/8] tests: update PHPUnit configuration --- phpunit.xml.dist | 20 +++++--------------- tests/phpunit.xml | 34 ---------------------------------- 2 files changed, 5 insertions(+), 49 deletions(-) delete mode 100644 tests/phpunit.xml diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3cfcbb0..47dedce 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" > @@ -17,18 +16,9 @@ - - - ../src/AssetsInstaller - - vendor - - - - - - - - + + + src/AssetsInstaller + + diff --git a/tests/phpunit.xml b/tests/phpunit.xml deleted file mode 100644 index 68dccbc..0000000 --- a/tests/phpunit.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - . - - - - - - ../src/AssetsInstaller - - vendor - - - - - - - - - From ba5bfbd8be51a996afae82f0c9ccdbd74d4c794c Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Fri, 4 Jun 2021 10:53:48 +0100 Subject: [PATCH 4/8] ci: update to test against current PHP versions --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 446cf43..f8f3f34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,8 @@ language: php php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 + - 7.3 + - 7.4 + - 8.0 before_script: composer install From ff221cfe790a0182ded48c4bae1073408bd65fc2 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Fri, 4 Jun 2021 11:01:53 +0100 Subject: [PATCH 5/8] tests: update tests --- phpunit.xml.dist | 2 +- tests/bootstrap.php | 12 --------- tests/src/AssetsInstallerTest.php | 44 +++++++++++-------------------- 3 files changed, 17 insertions(+), 41 deletions(-) delete mode 100644 tests/bootstrap.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 47dedce..57e51ac 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,7 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -$loader = require __DIR__.'/../vendor/autoload.php'; \ No newline at end of file diff --git a/tests/src/AssetsInstallerTest.php b/tests/src/AssetsInstallerTest.php index 1e61955..a474459 100644 --- a/tests/src/AssetsInstallerTest.php +++ b/tests/src/AssetsInstallerTest.php @@ -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'; @@ -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); @@ -231,12 +235,7 @@ private function getMockPackage($packageNs = self::NS_DEFAULT, $linksNs = self:: { $mockPackageData = $this->mockPackage[$packageNs]; - $jsonFileReader = $this->getMock('JsonFile', 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')); $package->expects($this->any()) ->method('getExtra') ->will($this->returnValue($mockPackageData['extra'])); @@ -249,22 +248,19 @@ private function getMockPackage($packageNs = self::NS_DEFAULT, $linksNs = self:: $package->expects($this->any()) ->method('getRequires') ->will($this->returnValue($this->getMockPackagesLinks($linksNs))); - $package->expects($this->any()) - ->method('getJsonFile') - ->will($this->returnValue($jsonFileReader)); return $package; } 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)); @@ -277,7 +273,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'])); @@ -301,18 +297,10 @@ private function getMockPackagesLinks($mockLinksNs) private function getMockPackageLink($mockLinkData) { - $jsonFileReader = $this->getMock('JsonFile', 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')); $link->expects($this->any()) ->method('getTarget') ->will($this->returnValue($mockLinkData['target'])); - $link->expects($this->any()) - ->method('getJsonFile') - ->will($this->returnValue($jsonFileReader)); return $link; } From 129b2af4f85e0fffe46036d4e93ba998b0867c68 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Thu, 10 Jun 2021 12:40:58 +0100 Subject: [PATCH 6/8] ci: update to use GitHub Actions --- .github/workflows/tests.yml | 36 ++++++++++++++++++++++++++++++++++++ .travis.yml | 8 -------- 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..748f9f6 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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-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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f8f3f34..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: php - -php: - - 7.3 - - 7.4 - - 8.0 - -before_script: composer install From 1a249c73df28bd76aae37d3e017093289025ed00 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Thu, 10 Jun 2021 12:53:04 +0100 Subject: [PATCH 7/8] tests: revert certain mock usages --- tests/src/AssetsInstallerTest.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/src/AssetsInstallerTest.php b/tests/src/AssetsInstallerTest.php index a474459..a1bf99e 100644 --- a/tests/src/AssetsInstallerTest.php +++ b/tests/src/AssetsInstallerTest.php @@ -235,7 +235,12 @@ private function getMockPackage($packageNs = self::NS_DEFAULT, $linksNs = self:: { $mockPackageData = $this->mockPackage[$packageNs]; - $package = $this->createPartialMock(Package::class, array('getExtra', 'getName', 'getRequires', 'getTarget')); + $jsonFileReader = $this->createPartialMock(JsonFile::class, array('read')); + $jsonFileReader->expects($this->any()) + ->method('read') + ->will($this->returnValue($mockPackageData['jsonFile'])); + + $package = $this->createPartialMock(Package::class, array('getExtra', 'getName', 'getRequires', 'getTarget', 'getJsonFile')); $package->expects($this->any()) ->method('getExtra') ->will($this->returnValue($mockPackageData['extra'])); @@ -248,6 +253,9 @@ private function getMockPackage($packageNs = self::NS_DEFAULT, $linksNs = self:: $package->expects($this->any()) ->method('getRequires') ->will($this->returnValue($this->getMockPackagesLinks($linksNs))); + $package->expects($this->any()) + ->method('getJsonFile') + ->will($this->returnValue($jsonFileReader)); return $package; } @@ -297,10 +305,18 @@ private function getMockPackagesLinks($mockLinksNs) private function getMockPackageLink($mockLinkData) { - $link = $this->createPartialMock(Link::class, array('getTarget')); + $jsonFileReader = $this->createPartialMock(JsonFile::class, array('read')); + $jsonFileReader->expects($this->any()) + ->method('read') + ->will($this->returnValue($mockLinkData['jsonFile'])); + + $link = $this->createPartialMock(Link::class, array('getTarget', 'getJsonFile')); $link->expects($this->any()) ->method('getTarget') ->will($this->returnValue($mockLinkData['target'])); + $link->expects($this->any()) + ->method('getJsonFile') + ->will($this->returnValue($jsonFileReader)); return $link; } From 468e1a727101b21117c9a32f216daee7d8bf676d Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Thu, 10 Jun 2021 14:07:19 +0100 Subject: [PATCH 8/8] ci: test against lowest dependencies --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 748f9f6..d949314 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: matrix: os: [ubuntu-latest] php: ['7.3', '7.4', '8.0'] - dependency-version: [prefer-stable] + dependency-version: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}