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

Add support for PHP 8.1 #44

Merged
merged 23 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
221a2a6
Add default value to property projectRoot of ComponentInstaller preve…
arueckauer Sep 30, 2021
c4e1deb
Remove unnecessary value assignment of projectRoot which causes an er…
arueckauer Sep 30, 2021
43046fe
Initialize mocks in test method without the need to rely or alter set…
arueckauer Sep 30, 2021
e7d9369
Add argument type declaration to ensure type safety and null is never…
arueckauer Sep 30, 2021
156d646
Add PHP 8.1 support
arueckauer Sep 30, 2021
9aa08e2
Fix incompatibility with ArrayAccess, Countable and IteratorAggregate
arueckauer Sep 30, 2021
dc446b5
Exclude 8.1 in CI
arueckauer Sep 30, 2021
ad85090
Revert upgrade of dependencies
arueckauer Sep 30, 2021
efe1026
Upgrade laminas/laminas-coding-standard to 2.2.1
arueckauer Sep 30, 2021
a7adba7
Fix import of ReturnTypeWillChange
arueckauer Sep 30, 2021
972fe4a
Upgrade mikey179/vfsstream to 1.6.10 for PHP8.1 compatibility
arueckauer Sep 30, 2021
d43958d
Upgrade lowest version of composer/composer to 1.6.10 for PHP 8.1 com…
arueckauer Sep 30, 2021
b6b1afc
Remove lowest version of composer/composer due to incompatibility wit…
arueckauer Sep 30, 2021
b7d3cb6
Upgrade composer/composer to 2.1.9 and vimeo/psalm to 4.10 for PHP 8.…
arueckauer Oct 5, 2021
71f93ca
Replace usage of internal ExpectationFailedException with self::fail()
arueckauer Oct 6, 2021
39af669
Add MissingConstructor suppression for properties which will be initi…
arueckauer Oct 6, 2021
2d38612
Replace usage of internal ExpectationFailedException with self::fail()
arueckauer Oct 6, 2021
6fc2ef5
Add psalm/plugin-phpunit which makes MissinConstructor suppress direc…
arueckauer Nov 29, 2021
8845f40
Restore caret for version constraint of mikey179/vfsstream
arueckauer Nov 29, 2021
8ad7fdf
feat: bump minimum supported PHP version
weierophinney Dec 2, 2021
19d3a84
qa: apply laminas-coding-standard 2.3 rules and ensure PHPUnit conver…
weierophinney Dec 2, 2021
36d3ef7
fix: allow proper working under PHP 8.1
weierophinney Dec 2, 2021
f8c12e4
qa: Psalm issues
weierophinney Dec 2, 2021
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 .laminas-ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"dependencies": "latest"
}
}
]
],
"ignore_php_platform_requirements": {
"8.1": true
}
}
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
"class": "Laminas\\ComponentInstaller\\ComponentInstaller"
},
"require": {
"php": "^7.3 || ~8.0.0",
"php": "^7.3 || ~8.0.0 || ~8.1.0",
"composer-plugin-api": "^1.0 || ^2.0",
"laminas/laminas-zendframework-bridge": "^1.0"
},
"require-dev": {
"composer/composer": "^1.5.2 || ^2.0",
"laminas/laminas-coding-standard": "~2.1.4",
"composer/composer": "^2.1.9",
"laminas/laminas-coding-standard": "2.2.1",
"malukenho/docheader": "^0.1.6",
"mikey179/vfsstream": "^1.6.7",
"mikey179/vfsstream": "1.6.10",
arueckauer marked this conversation as resolved.
Show resolved Hide resolved
"phpunit/phpunit": "^9.3",
"psalm/plugin-phpunit": "^0.13.0",
"vimeo/psalm": "^4.2",
"vimeo/psalm": "^4.10",
"webmozart/assert": "^1.6"
},
"autoload": {
Expand Down
499 changes: 288 additions & 211 deletions composer.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
use function iterator_to_array;
use function sprintf;

/**
* @use ReturnTypeWillChange
*/
class Collection implements
ArrayAccess,
Countable,
Expand Down Expand Up @@ -184,6 +187,7 @@ public function prepend($value)
* @param string|int $offset
* @return bool
*/
#[ReturnTypeWillChange]
public function offsetExists($offset)
{
return array_key_exists($offset, $this->items);
Expand All @@ -196,6 +200,7 @@ public function offsetExists($offset)
* @return mixed
* @throws OutOfRangeException
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
{
if (! $this->offsetExists($offset)) {
Expand All @@ -217,6 +222,7 @@ public function offsetGet($offset)
* @param mixed $value
* @return void
*/
#[ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (null === $offset) {
Expand All @@ -233,6 +239,7 @@ public function offsetSet($offset, $value)
* @param string|int $offset
* @return void
*/
#[ReturnTypeWillChange]
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
Expand All @@ -245,6 +252,7 @@ public function offsetUnset($offset)
*
* @return int
*/
#[ReturnTypeWillChange]
public function count()
{
return count($this->items);
Expand All @@ -265,6 +273,7 @@ public function isEmpty()
*
* @return ArrayIterator
*/
#[ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->items);
Expand Down
2 changes: 1 addition & 1 deletion src/ComponentInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ComponentInstaller implements
*
* @var string
*/
private $projectRoot;
private $projectRoot = '';

/** @var Closure():PackageProviderDetectionFactory */
private $packageProviderFactory;
Expand Down
4 changes: 1 addition & 3 deletions src/ConfigDiscovery/AbstractDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ abstract class AbstractDiscovery implements DiscoveryInterface
*
* Optionally specify project directory; $configFile will be relative to
* this value.
*
* @param string $projectDirectory
*/
public function __construct($projectDirectory = '')
public function __construct(string $projectDirectory = '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduce compatibility break, because changes public interface

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point.

IIRC I discussed this with @boesing in chat. The @param type hint states parameter is of type string. If implementation is breaking, it is due to a misuse.

Is that correct, @boesing?

Copy link
Member

@boesing boesing Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, __construct has some special behavior if it comes to arguments. So this is actually no BC break until the type-hint matches what we do state in the @var annotation.

(sidenote: imho laminas-component-installer is not a library and thus, semver does not really make sense here at all. But actually, we do not differ between libraries and components like this (composer plugin))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fun-fact: this constructor argument is only added for unit tests so we can pass virtual filesystem directory

{
if ('' !== $projectDirectory && is_dir($projectDirectory)) {
$this->configFile = sprintf(
Expand Down
5 changes: 1 addition & 4 deletions src/ConfigDiscovery/ConfigAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class ConfigAggregator extends AbstractDiscovery
*/
protected $expected = '';

/**
* @param string $projectDirectory
*/
public function __construct($projectDirectory = '')
public function __construct(string $projectDirectory = '')
{
$this->expected = sprintf(
'/new (?:%s?%s)?ConfigAggregator\(\s*(?:array\(|\[)/s',
Expand Down
5 changes: 1 addition & 4 deletions src/ConfigDiscovery/MezzioConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class MezzioConfig extends AbstractDiscovery
*/
protected $expected = '';

/**
* @param string $projectDirectory
*/
public function __construct($projectDirectory = '')
public function __construct(string $projectDirectory = '')
{
$this->expected = sprintf(
'/new (?:%s?%s)?ConfigManager\(\s*(?:array\(|\[)/s',
Expand Down
43 changes: 43 additions & 0 deletions test/ComponentInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,49 @@ public function testOnPostPackageInstallPromptsForConfigOptionsWhenDefinedAsArra
self::assertStringContainsString("'Other\Component'", $config);
}

public function testAddPackageToConfigWillPassProjectRootAsStringToConfigDiscovery(): void
{
/** @psalm-var InstallationManager&MockObject $installationManager */
$installationManager = $this->createMock(InstallationManager::class);

/** @psalm-var Composer&MockObject $composer */
$composer = $this->createMock(Composer::class);
$composer
->method('getInstallationManager')
->willReturn($installationManager);

/** @psalm-var IOInterface&MockObject $io */
$io = $this->createMock(IOInterface::class);
$io
->expects(self::never())
->method(self::anything());

$installer = new ComponentInstaller();
$installer->activate(
$composer,
$io
);

$package = $this->createMock(PackageInterface::class);
$package->method('getName')->willReturn('some/component');
$package->method('getExtra')->willReturn([
'laminas' => [
'component' => 'Some\\Component',
'config-provider' => 'Some\\Component\\ConfigProvider',
'module' => 'Some\\Component',
],
]);

$operation = $this->createMock(InstallOperation::class);
$operation->method('getPackage')->willReturn($package);

$event = $this->createMock(PackageEvent::class);
$event->method('isDevMode')->willReturn(true);
$event->method('getOperation')->willReturn($operation);

$installer->onPostPackageInstall($event);
}

public function testMultipleInvocationsOfOnPostPackageInstallCanPromptMultipleTimes(): void
{
// Do a first pass, with an initial package
Expand Down