PHPUnit version does not match version in Composer - php

I'm trying to update my phpunit version, however it doesn't seem to be working with the regular composer install.
My composer.json file is as follows:
{
"require": {
...
},
"require-dev": {
"phpunit/phpunit": "4.*",
"phpunit/php-invoker": "^1.1",
"phpunit/dbunit": "^2.0"
}
}
And running both composer install and update as php composer.phar install and php composer.phar update (I don't have composer installed globally which might be the issue?) I get
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
When I check to see the phpunit version, I get
$ phpunit --version
PHPUnit 3.7.28 by Sebastian Bergmann.
My PHP version is 5.6 which does seem to rule out the solution from this very similar issue.
My best guess is that there is a global version of phpunit installed and overriding my local one. But I haven't been able to find any guidance as to how to fix this without making too many changes to the rest of the global environment.

The command by itself phpunit will search in your shell's path for a PHPUnit executable. A composer install will place it into the composer bin dir, which is vendor/bin by default. You can execute the script directly with ./vendor/bin/phpunit, or allow composer to execute it for you, resolving the proper path for your project with composer exec phpunit

Related

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.4.22

Locally I have installed php 8
my composer.json looks like this
"require": {
"php": "^8.0",
I deleted the composer.lock and run composer install and I get the above error.
I tried to add
platform-check:false
delete composer.lock
run composer install
but then I get an error because I use Constructor property promotion in my codebase
So it seems that when I add platform-check:false, for some reason it runs on php < 8
P.S I didn't have that problem before, I just cloned my git repo and tried to run my app.
Your phpinfo() maybe having different version than 8.0. If so
Try
sudo apt-get install libapache2-mod-php8.0
Then restart your web server

Installing or updating symfony/flex via Composer silently fails

I have a project using symfony/flex in which I cannot run composer install or composer update. I also can't create a new composer project with symfony/flex as a dependency as the failure is the same. For example;
mkdir foo && cd foo && composer require symfony/flex -vvv
Always has the following output;
...
Package operations: 1 install, 0 updates, 0 removals
Installs: symfony/flex:v1.2.6
- Installing symfony/flex (v1.2.6): Reading /Users/me/.composer/cache/files/symfony/flex/17b622276922e6347ea129acd6238ae1c41d96b6.zip from cache
Loading from cache
Extracting archiveExecuting command (CWD): unzip -qq '/Users/me/projects/foo/vendor/symfony/flex/2064a553f7cdf064ba8c1b62c7087ec6' -d '/Users/me/projects/foo/vendor/composer/65215880'
Loading plugin Symfony\Flex\Flex
Downloading https://flex.symfony.com/versions.json
The download hangs for a few seconds at the point of downloading versions.json before silently failing. vendor/symfony/flex exists.
What could be the cause of this failure? My colleague can run the same command successfully so I'm assuming an issue with my local composer. I have attempted reinstall composer and clearing the cache with no success.
Edit: now when running composer update -vvv in an existing project I get the following output
...
Downloading https://repo.packagist.org/packages.json
Where it also hangs, so it looks like composer cannot download certain JSON files? Packages download fine so it doesn't look like a lack of internet.
Edit 2: I can also confirm using composer update --no-plugins does work within the existing project.
When composer isn't working as expected, you should reset it and update it like this. First
$ composer clearcache
Then update
$ composer self-update
Then run a diagnostic
$ composer diagnose
Then cd to where you have composer.json located and do
$ composer dump-autoload
Then
$ composer install
Should fix this issue. Another approach includes
$ composer update symfony/flex --no-plugins --no-scripts
Also, this can arise due to a conflict between symfony/flex and symfony/symfony. To remove that conflict follow these steps
$ composer remove symfony/symfony
then edit your composer.json file like
{
"require": {
"symfony/flex": "^1.0",
},
"conflict": {
"symfony/symfony": "*"
}
}
Old Flex infrastructure is being shut down, you need to update Flex to AT LEAST 1.17.1: symfony.com/blog/upgrade-flex-on-your-symfony-projects
To do that, you need to run:
composer update symfony/flex --no-plugins --no-scripts
Run this, solved my issue
> composer update symfony/flex --no-plugins --no-scripts
then keep this config in my composer.json
{
"require": {
"symfony/flex": "^1.1",
},
"conflict": {
"symfony/symfony": "*"
}
}
Since my experience is with the same issue and thus not deserving of a standalone Q&A, I'll just post it as an answer to this, as the core problem is exactly the same, Symfony flex servers being shut down.
In my dockered project, dependencies were not being installed during build and after some investigation I found out, that composer install would always fail due to being unable to reach the Symfony flex server. It looked like a DNS problem at first, but it ended up being a problem with Symfony flex servers being shut down and an old version (1.3) of "symfony/flex" in composer.json.
I did pretty much everything in the most upvoted answer, but
$ composer update symfony/flex --no-plugins --no-scripts
returned an error due to a dependency of the symfony/flex package hitting the API limit. However as suggested I created a Personal access token and everything went smoothly from there.
I had the same problem.
I added cloudflare dns 1.1.1.1 to my dns.
This solved it for me

Install PHPUnit 3.5.x without pear

Since the phpunit channel was shut down in 2014, I am looking for a way to install phpunit version 3.5.x without pear. The only answers that I have found explain how to use it with composer, but version 3.5.x does not exist as a composer package.
I do have the 3.5.10 source code for PHPUnit, but I am struggling on how to install it so that I can use it as a command line tool.
PHPUnit 3.7 was the first version to support Composer and PHAR. With PHPUnit 3.5 you are out of luck.
I use phpunit 4.8.* it supports composer and is very easy to install it. Using netbeans makes it even more easy because netbeans creates tests for you.
Put the following lines in the composer.json
"require-dev": {
"phpunit/phpunit-skeleton-generator": "*",
"phpunit/phpunit": "4.8.*"
},
Now update the composer via command and it will install. Using git it will be something like this.
composer update
composer install
To get the composer.phar
curl -sS https://getcomposer.org/installer | php
Now configure phpunit and you're good to go.

Install dependency (doctrine/dbal) on composer laravel

I am trying to execute a migration to rename some columns and I got an exception.
As I read on the documentation I have to add the doctrine/dbal dependency to my composer.json file. How do I do that? Which is the correct composer.json file. I have many in my application. Is the one that is on the same level as the folders app,bootstrap, public and vendor.
If so how do I add that dependency. Do I have to download anything?
By the way im using easyphp, not wamp!
Edit 1
After doing that the console throws this error
1) To install dependency , run this command
composer require doctrine/dbal
2) For 'git' is not recognized error, either you don't have git installed or the PATH is not added in the environment variables.
Install git for windows.
To add this dependency open the composer.json at the root of your project (in the same level as app, public etc.) and in the require section add the doctrine/dbal package like:
"require": {
"laravel/framework": "4.1.*",
"doctrine/dbal": "v2.4.2"
},
Save the file and run composer update
Edit
You probably installed git with the default settings and it's not in your PATH env.
Open Git Bash (it was installed with git - you will find it in your programs) and do composer update. By the way it's far better that windows command prompt.
If you are getting error while running migration try this
composer require doctrine/dbal:2.*

Install PHPUNIT with Composer

I have project on Symfony 2 and i would like use PHPUNIT on Windows 7.
On githut phpunit is:
Composer
Simply add a dependency on phpunit/phpunit to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPUnit 3.7:
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
For a system-wide installation via Composer, you can run:
composer global require 'phpunit/phpunit=3.7.*'
Make sure you have ~/.composer/vendor/bin/ in your path.
First i use system-wide installation but i dont know when this installed.
Next i add to my composer.json require-dev.
This installed phpunit in C:/wamp/www/myproject/vendor/symfony. Next i try commands:
composer install --dev
And i can't use phpunit. In cmd.exe i enter "phpunit" and i have error:
'phpunit' is not recognized as an internal or external command operable program or batch file
How can i use phpunit? I have Windows 7, Wamp server and php 5.4.12.
When you install PHP-Unit in windows via composer, the global installation will create files in
C:\Users\YOUR_USERNAME\AppData\Roaming\Composer
To execute phpunit easily via command line you need to add path of phpunit.bat file in windows Environment Variables. For this:
Right click My Computer
Go to Properties -> Advance system settings and
Click Environment variables from the Advance tab.
Now add C:\Users\YOUR_USERNAME\AppData\Roaming\Composer\vendor\bin to the windows PATH.
You can now run the phpunit from command. Note that you may need to restart your command prompt for the changes to take effect.
The bin file of packages are put in the configured bin directory. By default, this is vendor/bin and when you use the symfony standard edition, this is the bin folder.
To execute this bin file, run ./bin/phpunit (or ./vendor/bin/phpunit when not using the Symfony Standard Edition)
Windows users have to put this in double quotes: "bin/phpunit" (or "vendor/bin/phpunit")
composer require --dev phpunit/phpunit ^7
The above example assumes, composer is already on your $PATH variable.
You composer.json should look similar to;
{
"name": "vendor_name/package_name",
"description": "This project is for practicing writing php unit tests",
"minimum-stability": "stable",
"license": "proprietary",
"authors": [
{
"name": "Umair Anwar",
"email": "umair.anwar#gmail.com"
}
],
"autoload": {
"classmap": [
"src/"
]
},
"require-dev": {
"phpunit/phpunit": "^7",
"phpunit/dbunit": "^4.0"
}
}
Easiest way to install phpunit via composer is to run from project root.
$ composer require phpunit/phpunit
What this would do is, it will create a phpunit folder inside vendor/bin
and you can run unit tests like this..
$ ./vendor/bin/phpunit
Too simple operation on Windows with composer and works for me following way:
Install composer
https://getcomposer.org/doc/00-intro.md#installation-windows Go to
your symphony folder e.g C:\wamp64\www\symfony\UserManagement where is
composer.json and run this command.
Should be register with global to not have issue $phpunit bash: phpunit: command not found
//old version is 5.7 new 6.4 or put newest version.
composer global require --dev phpunit/phpunit ^5.7
I remember futzing around with the composer dependency stuff for phpunit and never could get it to work.
Instead, from your git bash shell:
mkdir ~/bin
cd ~/bin
curl https://phar.phpunit.de/phpunit.phar > phpunit
chmod +x phpunit
exit out of bash and then start a new bash session.
And you should be good to go. You can echo $PATH to verify you have a path to ~/bin but one seems to added by default.
https://phar.phpunit.de/phpunit.phar
I also came across the same issue and find out the solution by following steps
To run PHPUnit in Windows 7 under WAMP installation
Composer Install
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
Simply Set Environment Variable
The php unit will be install in a vendor dir in vendor/bin
Path : C:\wamp\www\myproject\vendor\bin;
Open a new Command Prompt
C:\Users\guny >phpunit --version
PHPUnit 3.7.30 by Sebastain Bergmann

Categories