Update custom composer package fails if the packages require each other - php

I am working with multiple composer packages as a library and sometimes those packages require each other. For example, in modolib/phpunit I have:
"require": {
"modolib/doctrine": "~1.2",
}
and in the package modolib/doctrine I have:
"require-dev": {
// ...
"modolib/phpunit": "~1.3"
},
To version the packages, I use tags. Calling git tag for modolib/phpunit in branch master puts out:
// ...
1.2.8
1.2.9
1.2.10
1.3.0
1.3.1
// ...
1.3.10
and git tag for modolib/doctrine at branch master puts out:
// ...
1.2.8
1.2.9
1.2.10
1.2.11
1.2.12
However, a composer update in modolib/phpunit will perfectly work, but an update in modolib/doctrine will throw this error:
Problem 1
- modolib/phpunit 1.3.9 requires moodlib/doctrine ~1.2 -> no matching packages found
- modolib/phpunit 1.3.8 requires moodlib/doctrine ~1.2 -> no matching packages found
- modolib/phpunit 1.3.7 requires moodlib/doctrine ~1.2 -> no matching packages found
- modolib/phpunit 1.3.5 requires moodlib/doctrine 1.2.* -> no matching packages found
- modolib/phpunit 1.3.4 requires moodlib/doctrine 1.2.* -> no matching packages found
- modolib/phpunit 1.3.3 requires moodlib/doctrine 1.2.* -> no matching packages found
- modolib/phpunit 1.3.2 requires moodlib/doctrine 1.2.* -> no matching packages found
- modolib/phpunit 1.3.10 requires moodlib/doctrine 1.*.* -> no matching packages found
- modolib/phpunit 1.3.1 requires moodlib/doctrine 1.2.* -> no matching packages found
- modolib/phpunit 1.3.0 requires moodlib/doctrine 1.2.* -> no matching packages found
- Installation request for modolib/phpunit ~1.3 -> satisfiable by modolib/phpunit[1.3.0, 1.3.1, 1.3.10, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.7, 1.3.8, 1.3.9]
The current version of modolib/doctrine is 1.2.12 and no commits have been added since I created this tag except for the merge to master (I am using git flow).
Now it seems like the expression "modolib/doctrine": "~1.2" is correct, since I can update the packages in modolib/phpunit itself, but the composer has problems with noticing I am working in the package it is trying to request. Or could it have something to do with the difference between require and require-dev?
How can I solve this error and update my packages in modolib/doctrine?
UPDATE:
The reason why the update in modolib/phpunit worked is because modolib/doctrine requires modolib/phpunit in require-dev, but the composer does not load the require-dev sections of the packages it's loading during the update. Therefore, from the view of modolib/phpunit the packages do not require each other. Only modolib/doctrine is loaded, but it does not try to load modolib/phpunit while working in this repository.

The composer does notice if the requirement is the package you are currently working in. What it does not notice is the tagged version. Of course Composer can not read your repository tags, so you need to provide them in the composer.json:
"name": "modolib/doctrine",
"version": "1.2.12",
// ...
"require-dev": {
// ...
"modolib/phpunit": "~1.3"
},
Now composer knows both name and version of your package and can validate the dependency.

Related

Failed to install symfony/mailer because of friendsofsymfony/user-bundle

I have problem in using mailer in symfony. I want to follow the instruction on symfony website. When I write composer require symfony/mailer in the terminal, I get an error:
Using version ^2.1 for friendsofsymfony/user-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "5.0.*"
Your requirements could not be resolved to an installable set of packages.
Problem 1
- friendsofsymfony/user-bundle v2.1.2 requires symfony/form ^2.8 || ^3.0 || ^4.0 -> no matching package found.
- friendsofsymfony/user-bundle v2.1.1 requires symfony/form ^2.8 || ^3.0 || ^4.0 -> no matching package found.
- friendsofsymfony/user-bundle v2.1.0 requires symfony/form ^2.8 || ^3.0 || ^4.0 -> no matching package found.
- Installation request for friendsofsymfony/user-bundle ^2.1 -> satisfiable by friendsofsymfony/user-bundle[v2.1.0, v2.1.1, v2.1.2].
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
- It's a private package and you forgot to add a custom repository to find it
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content.
when I check the symfony version in terminal:
Symfony CLI version v4.11.3 (c) 2017-2019 Symfony SAS
Symfony CLI helps developers manage projects, from local code to remote infrastructure
can you please help me to solve this problem?
I don't know about the symfony 4.11 version.
The last version maintained by symfony is the 4.4.
I think you should work on 4.4 version for more stability.
When you read docs, look at the version. Here there is no doc for symfony 4.11
So you're bundle will probably not work on your version.
On packagist you can see the bundle can work on 4.4 or 5 version.
https://packagist.org/packages/symfony/mailer

Conflict on composer require of behat/mink

When I try to install Mink (using composer require --dev behat/mink) I get the message:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- behat/mink v1.7.1 requires symfony/css-selector ~2.1|~3.0 -> no matching package found.
- behat/mink v1.7.0 requires symfony/css-selector ~2.1 -> no matching package found.
- Installation request for behat/mink ^1.7 -> satisfiable by behat/mink[v1.7.0, v1.7.1].
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
- It's a private package and you forgot to add a custom repository to find it
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content
What I found is that there is a conflict with symfony/css-selector.
If I run composer show symfony/css-selector the version shown is v4.2.1, so I think this is the problem.
Also, when I run composer why symfony/css-selector it returns:
symfony/test-pack v1.0.5 requires symfony/css-selector (*)
Is there any way of solving this conflict without removing the symfony/test-pack?
According to https://github.com/minkphp/Mink/pull/749#issuecomment-351402449, Mink has support for Symfony 4, but not released yet. You can using "behat/mink": "~1.7#dev" to install latest dev code for trial.

API Platform v1.1.1 & Symfony 3.2.8 composer conflict

I have Symfony Demo Application up and running and now I'm trying to install API Platform as a standalone bundle.
I'm using PHP 7.0.10 with latest composer, but my previous test was using PHP 5.6.20.
When I try to add API Platform Core as a dependency, I get the following error message:
$ composer require api-platform/core
Using version ^1.1 for api-platform/core
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for symfony/symfony (locked at v3.2.8, required as ^3
.2) -> satisfiable by symfony/symfony[v3.2.8].
- api-platform/core v1.1.0 requires phpdocumentor/reflection ^1.0.7 -> satis
fiable by phpdocumentor/reflection[1.0.7].
- api-platform/core v1.1.1 requires phpdocumentor/reflection ^1.0.7 -> satis
fiable by phpdocumentor/reflection[1.0.7].
- Conclusion: don't install phpdocumentor/reflection 1.0.7
- Installation request for api-platform/core ^1.1 -> satisfiable by api-plat
form/core[v1.1.0, v1.1.1].
Installation failed, reverting ./composer.json to its original content.
In your composer.json file:
Find:
"symfony/symfony": "3.2.*",
Replace with:
"symfony/symfony": "3.3.*",
...or:
"symfony/symfony": "^3.2.*",
You'll probably need (want) to run composer update first, THEN add your api-platform package with composer require api-platform/core so you have all the dependencies properly loaded, but it's not essential.
With PHP 7.x, you should be using ^2.0, e.g.
composer require api-platform/core ^2.0
Note: To workaround PHP 7.x requirements, you can try to add --ignore-platform-reqs.
If you get the error about minimum-stability, change it to beta in your composer.json file.
Source: Compatibility issue when using composer require with symfony 3.1.4 at GitHub.
See: Installing API Platform Core.

composer error: Installation failed, reverting ./composer.json to its original content

I try install https://github.com/google/google-api-php-client for my php project via composer.
composer.json:
{
"require": {
"Intervention/image": "~2.3.7",
"intervention/image": "^2.3",
"guzzlehttp/guzzle": "^6.2"
}
}
I run this command:
composer require google/apiclient:^2.0
And result:
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- google/apiclient v2.0.0 requires google/auth 0.8 -> satisfiable by google/auth[v0.8].
- Installation request for google/apiclient 2.0 -> satisfiable by google/apiclient[v2.0.0].
- Conclusion: remove guzzlehttp/psr7 1.3.0
- Conclusion: don't install guzzlehttp/psr7 1.3.0
- google/auth v0.8 requires guzzlehttp/psr7 1.2.* -> satisfiable by guzzlehttp/psr7[1.2.0, 1.2.1, 1.2.2, 1.2.3].
- Can only install one of: guzzlehttp/psr7[1.2.0, 1.3.0].
- Can only install one of: guzzlehttp/psr7[1.2.1, 1.3.0].
- Can only install one of: guzzlehttp/psr7[1.2.2, 1.3.0].
- Can only install one of: guzzlehttp/psr7[1.2.3, 1.3.0].
- Installation request for guzzlehttp/psr7 (locked at 1.3.0) -> satisfiable by guzzlehttp/psr7[1.3.0].
Installation failed, reverting ./composer.json to its original content.
Also I installed php composer.phar require guzzlehttp/guzzle before...
I would try removing your project's requirement of guzzlehttp/guzzle and let your Google dependency tell composer what version it wants to pull in. Google's package (for some reason) has a version floor of 1.2 for guzzlehttp/psr7, and composer is complaining that it can't figure out how to satisfy this requirement.
Since your new dependency (the Google package) also requires guzzlehttp/guzzle, you don't need to specifically require it, so I would just remove it and try composer update again.

Composer not getting the most up to date version with wildcard

I have a Composer package that requires OtherPackage vs 1.0.*. I know that version 1.0.3 exists, but it keeps downloading version 1.0.1. I can't figure out why it is not getting the latest version.
my composer.json file:
"require": {
"MyVendor/OtherPackage": "1.0.*",
}
I figured this out because I tried to force version 1.0.3 and got the following error:
Your requirements could not be resolved to an installable set of packages.
- Installation request for myVendor/OtherPackage 1.0.3 -> satisfiable by MyVendor/OtherPackage[1.0.3]
- MyVendor/OtherPackage 1.0.3 requires OtherVendor/ThirdPackage 1.0.1 -> no matching package found.
So that's when I remembered that MyVendor/OtherPackage 1.0.1 didn't have the ThirdPackage dependency, while 1.0.2 and 1.0.3 did. I didn't include ThirdPackage in my composer.json requirements. As a result Composer was smart enough to get the latest version of OtherPackage that was satisfiable for all of my current dependencies.
My solution was just to add OtherVendor/ThirdPackage 1.0.1 to my requires declaration in composer.json.
My new composer.json
"require": {
"MyVendor/OtherPackage": "1.0.*",
"OtherVendor/ThridPackage":"1.0.1"
},

Categories