Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
added back php 7.0 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
clxmstaab committed Jun 21, 2019
1 parent e799c52 commit 954a37c
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 110 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ language: php
sudo: false

php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4snapshot

env:
- DEPENDENCIES=""
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- DEPENDENCIES="--classmap-authoritative"
- DEPENDENCIES="--no-scripts"

before_script:
Expand Down
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@ $version = \PackageVersions\Versions::getVersion('ocramius/package-versions');
var_dump($version); // 1.0.0@0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
```

[![Build Status](https://travis-ci.org/Ocramius/PackageVersions.svg?branch=master)](https://travis-ci.org/Ocramius/PackageVersions)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Ocramius/PackageVersions/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Ocramius/PackageVersions/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/Ocramius/PackageVersions/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Ocramius/PackageVersions/?branch=master)
[![Downloads](https://img.shields.io/packagist/dt/ocramius/package-versions.svg)](https://packagist.org/packages/ocramius/package-versions)
[![Packagist](https://img.shields.io/packagist/v/ocramius/package-versions.svg)](https://packagist.org/packages/ocramius/package-versions)
[![Dependencies](https://tidelift.com/badges/github/packagist/ocramius%2Fpackage-versions)](https://tidelift.com/subscription/pkg/packagist-ocramius%2Fpackage-versions?utm_source=packagist-ocramius%2Fpackage-versions&utm_medium=readme)

### Installation

```sh
composer require ocramius/package-versions
composer require complex/package-versions
```

It is suggested that you use [an optimized composer autoloader](https://getcomposer.org/doc/06-config.md#optimize-autoloader) (to prevent autoload I/O when accessing the `PackageVersions\Versions` API) in your composer.json:
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
{
"name": "ocramius/package-versions",
"name": "complex/package-versions",
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"type": "composer-plugin",
"license": "MIT",
"authors": [
{
"name": "Marco Pivetta",
"email": "[email protected]"
},
{
"name": "Markus Staab",
"email": "[email protected]"
}
],
"require": {
"php": "^7.2.0",
"php": "^7.0.0",
"composer-plugin-api": "^1.0.0"
},
"require-dev": {
"phpunit/phpunit": "^8.2.2",
"phpunit/phpunit": "^6",
"infection/infection": "^0.7.1",
"composer/composer": "^1.8.6",
"ext-zip": "*",
"doctrine/coding-standard": "^6.0.0"
"ext-zip": "*"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/PackageVersions/FallbackVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
final class FallbackVersions
{
public const ROOT_PACKAGE_NAME = 'unknown/root-package@UNKNOWN';
const ROOT_PACKAGE_NAME = 'unknown/root-package@UNKNOWN';

private function __construct()
{
Expand Down
26 changes: 13 additions & 13 deletions src/PackageVersions/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ final class Installer implements PluginInterface, EventSubscriberInterface
namespace PackageVersions;
/**
* This class is generated by ocramius/package-versions, specifically by
* This class is generated by complex/package-versions, specifically by
* @see \PackageVersions\Installer
*
* This file is overwritten at every run of `composer install` or `composer update`.
*/
%s
{
public const ROOT_PACKAGE_NAME = '%s';
const ROOT_PACKAGE_NAME = '%s';
/**
* Array of all available composer packages.
* Dont read this array from your calling code, but use the \PackageVersions\Versions::getVersion() method instead.
*
* @var array<string, string>
* @internal
*/
public const VERSIONS = %s;
const VERSIONS = %s;
private function __construct()
{
Expand Down Expand Up @@ -83,7 +83,7 @@ public static function getVersion(string $packageName) : string
/**
* {@inheritDoc}
*/
public function activate(Composer $composer, IOInterface $io) : void
public function activate(Composer $composer, IOInterface $io)
{
// Nothing to do here, as all features are provided through event listeners
}
Expand All @@ -101,15 +101,15 @@ public static function getSubscribedEvents() : array
/**
* @throws RuntimeException
*/
public static function dumpVersionsClass(Event $composerEvent) : void
public static function dumpVersionsClass(Event $composerEvent)
{
$composer = $composerEvent->getComposer();
$rootPackage = $composer->getPackage();
$versions = iterator_to_array(self::getVersions($composer->getLocker(), $rootPackage));

if (! array_key_exists('ocramius/package-versions', $versions)) {
if (! array_key_exists('complex/package-versions', $versions)) {
//plugin must be globally installed - we only want to generate versions for projects which specifically
//require ocramius/package-versions
//require complex/package-versions
return;
}

Expand All @@ -134,25 +134,25 @@ private static function generateVersionsClass(string $rootPackageName, array $ve
/**
* @throws RuntimeException
*/
private static function writeVersionClassToFile(string $versionClassSource, Composer $composer, IOInterface $io) : void
private static function writeVersionClassToFile(string $versionClassSource, Composer $composer, IOInterface $io)
{
$installPath = self::locateRootPackageInstallPath($composer->getConfig(), $composer->getPackage())
. '/src/PackageVersions/Versions.php';

if (! file_exists(dirname($installPath))) {
$io->write('<info>ocramius/package-versions:</info> Package not found (probably scheduled for removal); generation of version class skipped.');
$io->write('<info>complex/package-versions:</info> Package not found (probably scheduled for removal); generation of version class skipped.');

return;
}

$io->write('<info>ocramius/package-versions:</info> Generating version class...');
$io->write('<info>complex/package-versions:</info> Generating version class...');

$installPathTmp = $installPath . '_' . uniqid('tmp', true);
file_put_contents($installPathTmp, $versionClassSource);
chmod($installPathTmp, 0664);
rename($installPathTmp, $installPath);

$io->write('<info>ocramius/package-versions:</info> ...done generating version class');
$io->write('<info>complex/package-versions:</info> ...done generating version class');
}

/**
Expand All @@ -162,11 +162,11 @@ private static function locateRootPackageInstallPath(
Config $composerConfig,
RootPackageInterface $rootPackage
) : string {
if (self::getRootPackageAlias($rootPackage)->getName() === 'ocramius/package-versions') {
if (self::getRootPackageAlias($rootPackage)->getName() === 'complex/package-versions') {
return dirname($composerConfig->get('vendor-dir'));
}

return $composerConfig->get('vendor-dir') . '/ocramius/package-versions';
return $composerConfig->get('vendor-dir') . '/complex/package-versions';
}

private static function getRootPackageAlias(RootPackageInterface $rootPackage) : PackageInterface
Expand Down
38 changes: 19 additions & 19 deletions test/PackageVersionsTest/E2EInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class E2EInstallerTest extends TestCase
/** @var string */
private $tempArtifact;

public function setUp() : void
public function setUp()
{
$this->tempGlobalComposerHome = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true) . '/global';
$this->tempLocalComposerHome = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true) . '/local';
Expand All @@ -62,7 +62,7 @@ public function setUp() : void
putenv('COMPOSER_HOME=' . $this->tempGlobalComposerHome);
}

public function tearDown() : void
public function tearDown()
{
$this->rmDir($this->tempGlobalComposerHome);
$this->rmDir($this->tempLocalComposerHome);
Expand All @@ -71,14 +71,14 @@ public function tearDown() : void
putenv('COMPOSER_HOME');
}

public function testGloballyInstalledPluginDoesNotGenerateVersionsForLocalProject() : void
public function testGloballyInstalledPluginDoesNotGenerateVersionsForLocalProject()
{
$this->createPackageVersionsArtifact();

$this->writeComposerJsonFile(
[
'name' => 'package-versions/e2e-global',
'require' => ['ocramius/package-versions' => '1.0.0'],
'require' => ['complex/package-versions' => '1.0.0'],
'repositories' => [
['packagist' => false],
[
Expand Down Expand Up @@ -110,11 +110,11 @@ public function testGloballyInstalledPluginDoesNotGenerateVersionsForLocalProjec

$this->execComposerInDir('update', $this->tempLocalComposerHome);
$this->assertFileNotExists(
$this->tempLocalComposerHome . '/vendor/ocramius/package-versions/src/PackageVersions/Versions.php'
$this->tempLocalComposerHome . '/vendor/complex/package-versions/src/PackageVersions/Versions.php'
);
}

public function testRemovingPluginDoesNotAttemptToGenerateVersions() : void
public function testRemovingPluginDoesNotAttemptToGenerateVersions()
{
$this->createPackageVersionsArtifact();
$this->createArtifact();
Expand All @@ -124,7 +124,7 @@ public function testRemovingPluginDoesNotAttemptToGenerateVersions() : void
'name' => 'package-versions/e2e-local',
'require' => [
'test/package' => '2.0.0',
'ocramius/package-versions' => '1.0.0',
'complex/package-versions' => '1.0.0',
],
'repositories' => [
['packagist' => false],
Expand All @@ -139,29 +139,29 @@ public function testRemovingPluginDoesNotAttemptToGenerateVersions() : void

$this->execComposerInDir('update', $this->tempLocalComposerHome);
$this->assertFileExists(
$this->tempLocalComposerHome . '/vendor/ocramius/package-versions/src/PackageVersions/Versions.php'
$this->tempLocalComposerHome . '/vendor/complex/package-versions/src/PackageVersions/Versions.php'
);

$this->execComposerInDir('remove ocramius/package-versions', $this->tempLocalComposerHome);
$this->execComposerInDir('remove complex/package-versions', $this->tempLocalComposerHome);

$this->assertFileNotExists(
$this->tempLocalComposerHome . '/vendor/ocramius/package-versions/src/PackageVersions/Versions.php'
$this->tempLocalComposerHome . '/vendor/complex/package-versions/src/PackageVersions/Versions.php'
);
}

/**
* @group #41
* @group #46
*/
public function testRemovingPluginWithNoDevDoesNotAttemptToGenerateVersions() : void
public function testRemovingPluginWithNoDevDoesNotAttemptToGenerateVersions()
{
$this->createPackageVersionsArtifact();
$this->createArtifact();

$this->writeComposerJsonFile(
[
'name' => 'package-versions/e2e-local',
'require-dev' => ['ocramius/package-versions' => '1.0.0'],
'require-dev' => ['complex/package-versions' => '1.0.0'],
'repositories' => [
['packagist' => false],
[
Expand All @@ -175,17 +175,17 @@ public function testRemovingPluginWithNoDevDoesNotAttemptToGenerateVersions() :

$this->execComposerInDir('update', $this->tempLocalComposerHome);
$this->assertFileExists(
$this->tempLocalComposerHome . '/vendor/ocramius/package-versions/src/PackageVersions/Versions.php'
$this->tempLocalComposerHome . '/vendor/complex/package-versions/src/PackageVersions/Versions.php'
);

$this->execComposerInDir('install --no-dev', $this->tempLocalComposerHome);

$this->assertFileNotExists(
$this->tempLocalComposerHome . '/vendor/ocramius/package-versions/src/PackageVersions/Versions.php'
$this->tempLocalComposerHome . '/vendor/complex/package-versions/src/PackageVersions/Versions.php'
);
}

private function createPackageVersionsArtifact() : void
private function createPackageVersionsArtifact()
{
$zip = new ZipArchive();

Expand Down Expand Up @@ -226,7 +226,7 @@ static function (SplFileInfo $file) use ($zip) {
$zip->close();
}

private function createArtifact() : void
private function createArtifact()
{
$zip = new ZipArchive();

Expand All @@ -247,7 +247,7 @@ private function createArtifact() : void
/**
* @param mixed[] $config
*/
private function writeComposerJsonFile(array $config, string $directory) : void
private function writeComposerJsonFile(array $config, string $directory)
{
file_put_contents(
$directory . '/composer.json',
Expand All @@ -269,7 +269,7 @@ private function execComposerInDir(string $command, string $dir) : array
return $output;
}

private function rmDir(string $directory) : void
private function rmDir(string $directory)
{
if (! is_dir($directory)) {
unlink($directory);
Expand All @@ -278,7 +278,7 @@ private function rmDir(string $directory) : void
}

array_map(
function ($item) use ($directory) : void {
function ($item) use ($directory) {
$this->rmDir($directory . '/' . $item);
},
array_filter(
Expand Down
6 changes: 3 additions & 3 deletions test/PackageVersionsTest/FallbackVersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
final class FallbackVersionsTest extends TestCase
{
public function testWillFailWithoutValidComposerLockLocation() : void
public function testWillFailWithoutValidComposerLockLocation()
{
rename(__DIR__ . '/../../composer.lock', __DIR__ . '/../../composer.lock.backup');

Expand All @@ -46,7 +46,7 @@ public function testWillFailWithoutValidComposerLockLocation() : void
}
}

public function testValidVersions() : void
public function testValidVersions()
{
$lockData = json_decode(file_get_contents(__DIR__ . '/../../composer.lock'), true);

Expand All @@ -62,7 +62,7 @@ public function testValidVersions() : void
}
}

public function testInvalidVersionsAreRejected() : void
public function testInvalidVersionsAreRejected()
{
$this->expectException(OutOfBoundsException::class);

Expand Down
Loading

0 comments on commit 954a37c

Please sign in to comment.