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

Support PHP 8 #4325

Closed
31 tasks done
sebastianbergmann opened this issue Jun 26, 2020 · 57 comments
Closed
31 tasks done

Support PHP 8 #4325

sebastianbergmann opened this issue Jun 26, 2020 · 57 comments
Assignees
Milestone

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Jun 26, 2020

PHPUnit 9 is being tested against nightly builds of PHP 8 for quite a while and it is safe to say that -- as of right now -- PHPUnit 9 works on PHP 8. While some things might still change until PHP 8.0.0 is released, it is time to make the support for PHP 8 official.

However, this is not as simple as applying

diff --git a/composer.json b/composer.json
index 0f8416d1d..2bf0fa21e 100644
--- a/composer.json
+++ b/composer.json
@@ -22,7 +22,7 @@
     "prefer-stable": true,
     "minimum-stability": "dev",
     "require": {
-        "php": "^7.3",
+        "php": "^7.3 || ^8.0",

to this repository for phpunit/phpunit.

PHP 8.0 also needs to be allowed in the composer.json files of PHPUnit's dependencies:

  • phpunit/php-code-coverage
  • phpunit/php-file-iterator
  • phpunit/php-invoker
  • phpunit/php-text-template
  • phpunit/php-timer
  • phpunit/php-token-stream
  • sebastian/code-unit
  • sebastian/code-unit-reverse-lookup
  • sebastian/comparator
  • sebastian/diff
  • sebastian/environment
  • sebastian/exporter
  • sebastian/global-state
  • sebastian/object-enumerator
  • sebastian/object-reflector
  • sebastian/recursion-context
  • sebastian/resource-operations
  • sebastian/type
  • sebastian/version
  • doctrine/instantiator (has "php": "^7.1 || ^8.0" in 1.3.1)
  • symfony/polyfill-ctype (has "php": ">=5.3.3" in 1.17.1)
  • myclabs/deep-copy CC @mnapoli and @theofidry
  • phar-io/manifest CC @theseer
  • phar-io/version CC @theseer
  • phpdocumentor/reflection-common CC @jaapio and @mvriel
  • phpdocumentor/reflection-docblock CC @jaapio and @mvriel
  • phpdocumentor/type-resolver CC @jaapio and @mvriel
  • phpspec/prophecy-phpunit CC @ciaranmcnulty and @stof
  • phpspec/prophecy CC @ciaranmcnulty and @stof
  • theseer/tokenizer CC @theseer
  • webmozart/assert CC @webmozart
$ composer info | sort -d
doctrine/instantiator              1.3.1             A small, lightweight utility to instantiate objects in PHP without invoking their constructors
myclabs/deep-copy                  1.9.5             Create deep copies (clones) of your objects
phar-io/manifest                   1.0.3             Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                    2.0.1             Library for handling version information and constraints
phpdocumentor/reflection-common    2.1.0             Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock  5.1.0             With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver        1.2.0             A PSR-5 based resolver of Class names, Types and Structural Element Names
phpspec/prophecy-phpunit           v2.0.0            PhpUnit test case integrating the Prophecy mocking library
phpspec/prophecy                   v1.10.3           Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage          9.0.x-dev 4b3293f Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          3.0.2             FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                3.0.1             Invoke callables with a timeout
phpunit/php-text-template          2.0.1             Simple template engine.
phpunit/php-timer                  5.0.0             Utility class for timing
phpunit/php-token-stream           4.0.2             Wrapper around PHP's tokenizer extension.
sebastian/code-unit                1.0.3             Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup 2.0.1             Looks up which function or method a line of code belongs to
sebastian/comparator               4.0.2             Provides the functionality to compare PHP values for equality
sebastian/diff                     4.0.1             Diff implementation
sebastian/environment              5.1.1             Provides functionality to handle HHVM/PHP environments
sebastian/exporter                 4.0.1             Provides the functionality to export PHP variables for visualization
sebastian/global-state             5.0.x-dev 836ce3a Snapshotting of global state
sebastian/object-enumerator        4.0.1             Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector         2.0.1             Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context        4.0.1             Provides functionality to recursively process PHP variables
sebastian/resource-operations      3.0.1             Provides a list of PHP built-in functions that operate on resources
sebastian/type                     2.1.0             Collection of value objects that represent the types of the PHP type system
sebastian/version                  3.0.0             Library that helps with managing the version number of Git-hosted PHP projects
symfony/polyfill-ctype             v1.17.1           Symfony polyfill for ctype functions
theseer/tokenizer                  1.1.3             A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert                   1.9.0             Assertions to validate method input/output with nice error messages.

Of course, I will take care of all dependencies that live in the sebastian/ and phpunit/ namespaces myself.

@sebastianbergmann
Copy link
Owner Author

sebastianbergmann commented Jun 26, 2020

In the meantime, here is how you can install PHPUnit 9 with Composer 2 for PHP 8:

$ php-80 --version                                                                                                                                  
PHP 8.0.0-dev (cli) (built: Jun 26 2020 09:26:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0-dev, Copyright (c), by Zend Technologies
$ php-80 /usr/local/bin/composer --version
Composer version 2.0-dev (2.0-dev+4a2ea3c67aa49a3dce68ef5a56614e1941d68965) 2020-06-25 07:16:23
$ php-80 /usr/local/bin/composer require --dev phpunit/phpunit
Using version ^5.2 for phpunit/phpunit
./composer.json has been created
Running composer update phpunit/phpunit
Loading composer repositories with package information
Updating dependencies
Lock file operations: 22 installs, 0 updates, 0 removals
  - Locking doctrine/instantiator (1.3.1)
  - Locking myclabs/deep-copy (1.6.1)
  - Locking phpdocumentor/reflection-docblock (2.0.5)
  - Locking phpspec/prophecy (v1.5.0)
  - Locking phpunit/php-code-coverage (3.2.0)
  - Locking phpunit/php-file-iterator (1.4.5)
  - Locking phpunit/php-text-template (1.2.1)
  - Locking phpunit/php-timer (1.0.8)
  - Locking phpunit/php-token-stream (1.4.12)
  - Locking phpunit/phpunit (5.2.7)
  - Locking phpunit/phpunit-mock-objects (3.1.3)
  - Locking sebastian/code-unit-reverse-lookup (1.0.0)
  - Locking sebastian/comparator (1.2.4)
  - Locking sebastian/diff (1.4.1)
  - Locking sebastian/environment (1.3.7)
  - Locking sebastian/exporter (1.2.2)
  - Locking sebastian/global-state (1.1.1)
  - Locking sebastian/recursion-context (1.0.5)
  - Locking sebastian/resource-operations (1.0.0)
  - Locking sebastian/version (2.0.1)
  - Locking symfony/polyfill-ctype (v1.17.1)
  - Locking symfony/yaml (v3.4.42)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 22 installs, 0 updates, 0 removals
  - Downloading phpdocumentor/reflection-docblock (2.0.5)
  - Downloading phpunit/php-token-stream (1.4.12)
  - Downloading symfony/yaml (v3.4.42)
  - Downloading sebastian/environment (1.3.7)
  - Downloading sebastian/diff (1.4.1)
  - Downloading phpunit/phpunit-mock-objects (3.1.3)
  - Downloading phpunit/php-timer (1.0.8)
  - Downloading sebastian/code-unit-reverse-lookup (1.0.0)
  - Downloading phpunit/php-code-coverage (3.2.0)
  - Downloading phpspec/prophecy (v1.5.0)
  - Downloading myclabs/deep-copy (1.6.1)
  - Downloading phpunit/phpunit (5.2.7)
  - Installing phpdocumentor/reflection-docblock (2.0.5): Extracting archive
  - Installing phpunit/php-token-stream (1.4.12): Extracting archive
  - Installing symfony/polyfill-ctype (v1.17.1): Extracting archive
  - Installing symfony/yaml (v3.4.42): Extracting archive
  - Installing sebastian/version (2.0.1): Extracting archive
  - Installing sebastian/resource-operations (1.0.0): Extracting archive
  - Installing sebastian/global-state (1.1.1): Extracting archive
  - Installing sebastian/recursion-context (1.0.5): Extracting archive
  - Installing sebastian/exporter (1.2.2): Extracting archive
  - Installing sebastian/environment (1.3.7): Extracting archive
  - Installing sebastian/diff (1.4.1): Extracting archive
  - Installing sebastian/comparator (1.2.4): Extracting archive
  - Installing phpunit/php-text-template (1.2.1): Extracting archive
  - Installing doctrine/instantiator (1.3.1): Extracting archive
  - Installing phpunit/phpunit-mock-objects (3.1.3): Extracting archive
  - Installing phpunit/php-timer (1.0.8): Extracting archive
  - Installing phpunit/php-file-iterator (1.4.5): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (1.0.0): Extracting archive
  - Installing phpunit/php-code-coverage (3.2.0): Extracting archive
  - Installing phpspec/prophecy (v1.5.0): Extracting archive
  - Installing myclabs/deep-copy (1.6.1): Extracting archive
  - Installing phpunit/phpunit (5.2.7): Extracting archive
6 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
3 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

PHPUnit 5.2.7 has

"php": ">=5.6"

in its composer.json.

That is not a version constraint.

$ rm -rf composer.json composer.lock vendor
$ php-80 /usr/local/bin/composer require --dev phpunit/phpunit ^9.2

                                                                                                        
  [RuntimeException]                                                                                    
  No composer.json present in the current directory, this may be the cause of the following exception.  
                                                                                                        

                                                                                                                                         
  [InvalidArgumentException]                                                                                                             
  Package phpunit/phpunit at version ^9.2 has a PHP requirement incompatible with your PHP version, PHP extensions and Composer version  
                                                                                                                                         

require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...

PHPUnit 9.2.5 has

"php": "^7.3"

in its composer.json.

Until this ticket is closed, you can use the following:

$ php-80 /usr/local/bin/composer require --dev --ignore-platform-req=php phpunit/phpunit ^9.2
./composer.json has been created
Running composer update phpunit/phpunit
Loading composer repositories with package information
Updating dependencies
Lock file operations: 31 installs, 0 updates, 0 removals
  - Locking doctrine/instantiator (1.3.1)
  - Locking myclabs/deep-copy (1.9.5)
  - Locking phar-io/manifest (1.0.3)
  - Locking phar-io/version (2.0.1)
  - Locking phpdocumentor/reflection-common (2.1.0)
  - Locking phpdocumentor/reflection-docblock (4.3.4)
  - Locking phpdocumentor/type-resolver (1.2.0)
  - Locking phpspec/prophecy (v1.10.3)
  - Locking phpunit/php-code-coverage (8.0.2)
  - Locking phpunit/php-file-iterator (3.0.2)
  - Locking phpunit/php-invoker (3.0.1)
  - Locking phpunit/php-text-template (2.0.1)
  - Locking phpunit/php-timer (5.0.0)
  - Locking phpunit/php-token-stream (4.0.2)
  - Locking phpunit/phpunit (9.2.5)
  - Locking sebastian/code-unit (1.0.3)
  - Locking sebastian/code-unit-reverse-lookup (2.0.1)
  - Locking sebastian/comparator (4.0.2)
  - Locking sebastian/diff (4.0.1)
  - Locking sebastian/environment (5.1.1)
  - Locking sebastian/exporter (4.0.1)
  - Locking sebastian/global-state (4.0.0)
  - Locking sebastian/object-enumerator (4.0.1)
  - Locking sebastian/object-reflector (2.0.1)
  - Locking sebastian/recursion-context (4.0.1)
  - Locking sebastian/resource-operations (3.0.1)
  - Locking sebastian/type (2.1.0)
  - Locking sebastian/version (3.0.0)
  - Locking symfony/polyfill-ctype (v1.17.1)
  - Locking theseer/tokenizer (1.1.3)
  - Locking webmozart/assert (1.9.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 31 installs, 0 updates, 0 removals
  - Downloading phpunit/phpunit (9.2.5)
  - Installing symfony/polyfill-ctype (v1.17.1): Extracting archive
  - Installing webmozart/assert (1.9.0): Extracting archive
  - Installing phpdocumentor/reflection-common (2.1.0): Extracting archive
  - Installing phpdocumentor/type-resolver (1.2.0): Extracting archive
  - Installing phpdocumentor/reflection-docblock (4.3.4): Extracting archive
  - Installing phpunit/php-token-stream (4.0.2): Extracting archive
  - Installing sebastian/version (3.0.0): Extracting archive
  - Installing sebastian/type (2.1.0): Extracting archive
  - Installing sebastian/resource-operations (3.0.1): Extracting archive
  - Installing sebastian/recursion-context (4.0.1): Extracting archive
  - Installing sebastian/object-reflector (2.0.1): Extracting archive
  - Installing sebastian/object-enumerator (4.0.1): Extracting archive
  - Installing sebastian/global-state (4.0.0): Extracting archive
  - Installing sebastian/exporter (4.0.1): Extracting archive
  - Installing sebastian/environment (5.1.1): Extracting archive
  - Installing sebastian/diff (4.0.1): Extracting archive
  - Installing sebastian/comparator (4.0.2): Extracting archive
  - Installing sebastian/code-unit (1.0.3): Extracting archive
  - Installing phpunit/php-timer (5.0.0): Extracting archive
  - Installing phpunit/php-text-template (2.0.1): Extracting archive
  - Installing phpunit/php-invoker (3.0.1): Extracting archive
  - Installing phpunit/php-file-iterator (3.0.2): Extracting archive
  - Installing theseer/tokenizer (1.1.3): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.1): Extracting archive
  - Installing phpunit/php-code-coverage (8.0.2): Extracting archive
  - Installing doctrine/instantiator (1.3.1): Extracting archive
  - Installing phpspec/prophecy (v1.10.3): Extracting archive
  - Installing phar-io/version (2.0.1): Extracting archive
  - Installing phar-io/manifest (1.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.9.5): Extracting archive
  - Installing phpunit/phpunit (9.2.5): Extracting archive
4 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
20 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
$ php-80 ./vendor/bin/phpunit --version                                                      
PHPUnit 9.2.5 by Sebastian Bergmann and contributors.

@mvriel
Copy link

mvriel commented Jun 26, 2020

@sebastianbergmann thanks for mentioning us; @jaapio and I will look into this!

sebastianbergmann added a commit to sebastianbergmann/php-code-coverage that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/php-file-iterator that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/php-invoker that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/php-text-template that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/php-timer that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/php-token-stream that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/code-unit that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/code-unit-reverse-lookup that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/comparator that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/environment that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/exporter that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/global-state that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/object-enumerator that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/object-reflector that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/recursion-context that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/resource-operations that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/type that referenced this issue Jun 26, 2020
sebastianbergmann added a commit to sebastianbergmann/version that referenced this issue Jun 26, 2020
sebastianbergmann added a commit that referenced this issue Jun 26, 2020
@sebastianbergmann sebastianbergmann added this to the PHPUnit 9.3 milestone Jun 26, 2020
@jaapio
Copy link
Contributor

jaapio commented Jun 27, 2020

phpdocumentor/reflection-common is upgraded, 2.2.0 supports php 8.

@sebastianbergmann
Copy link
Owner Author

phpdocumentor/reflection-common is upgraded, 2.2.0 supports php 8.

Thank you, @jaapio.

@jaapio
Copy link
Contributor

jaapio commented Jun 27, 2020

phpdocumentor/type-resolver is now also upgraded, from version 1.3.0

@theseer
Copy link
Collaborator

theseer commented Jul 13, 2020

While I'm not fully happy with the implementation, theseer/tokenizer has been updated and should now work with 7.2+ and 8.0+.

@sebastianbergmann
Copy link
Owner Author

theseer/tokenizer has been updated and should now work with 7.2+ and 8.0+.

Thank you, Arne.

@ciaranmcnulty
Copy link
Contributor

I spoke too soon about Prophecy, but it is now passing its nightly build if we force phpunit and phpdocumentor to their @dev versions.

I'll add PHP8 to the composer.json after feature freeze and when phpdocumentor is tagged (if we wait for phpunit that'll presumably cause a deadlock?)

@jaapio
Copy link
Contributor

jaapio commented Jul 20, 2020

I just released https://github.com/phpDocumentor/ReflectionDocBlock/releases/tag/5.2.0 should be good to go as far as I was able to check. This should clear the road for others to update.

@ciaranmcnulty
Copy link
Contributor

Thanks @jaapio that fixed the prophecy issues 👍

@sebastianbergmann
Copy link
Owner Author

We now use nikic/php-parser which has not been updated for php/php-src@7a3dcc3 yet. This is why the build currently fails on PHP 8.

@sebastianbergmann
Copy link
Owner Author

I would like to thank everyone who has contributed to the effort of making PHPUnit itself as well as its dependencies (and their dependencies ...) installable on PHP 8.

@TeBoring
Copy link

This is awesome! When will it be available?

@GrahamCampbell
Copy link
Contributor

August 7th, though note that you may still have to ignore platform requirements when installing PHPUnit with composer, even after that release, since not all PHPUnit's dependencies actually allow PHP 8 yet, however all of them at least work well enough so that PHPUnit and it's test suite can run.

@sebastianbergmann
Copy link
Owner Author

not all PHPUnit's dependencies actually allow PHP 8 yet

The only dependencies that do not have releases yet that allow PHP 8 are phpunit/php-code-coverage and sebastian/global-state :

$ composer install                                                                
No lock file found. Updating dependencies instead of installing from lock file. Use composer update over composer install if you do not have a lock file.
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires phpunit/php-code-coverage ^9.0, found phpunit/php-code-coverage[dev-master, 9.0.x-dev (alias of dev-master)] but it does not match your minimum-stability.
  Problem 2
    - Root composer.json requires sebastian/global-state ^5.0, found sebastian/global-state[dev-master, 5.0.x-dev (alias of dev-master)] but it does not match your minimum-stability.

You are using a snapshot build of Composer 2, which may be the cause of the problem. Run `composer self-update --stable` and then try again. In case it solves the problem, please report an issue mentioning Composer 2.

Versions of these packages that allow PHP 8 will be tagged when PHPUnit 9.3 is tagged.

@mfn
Copy link

mfn commented Aug 3, 2020

Awesome preparations done so head of time! Although I'm not involved, I did enjoy the level of enthusiasm and professionalism how things are done and looking forward.

Thank you all ❤️

@GrahamCampbell
Copy link
Contributor

GrahamCampbell commented Aug 3, 2020

not all PHPUnit's dependencies actually allow PHP 8 yet

Prophecy doesn't allow PHP 8 yet. It requires ^7.2 still.

@tuupola
Copy link

tuupola commented Sep 7, 2020

Maybe in the future prophecy could be considered to be an optional dependency? Currently there are too many hoops to jump through to test code with multiple versions of PHP if testing with PHP 8 is included. Not a biggie if testing only with PHP 8.

@stof
Copy link
Contributor

stof commented Sep 8, 2020

@tuupola removing support for Prophecy in core is planned for the future, which is why phpspec/prophecy-phpunit was resurrected.

@dereuromark
Copy link

dereuromark commented Sep 18, 2020

Ran into the same issue today with https://travis-ci.org/github/milesj/decoda/jobs/728420774 and PHP8 being untestable.

//EDIT: using --ignore-platform-reqs works as a workaround for now.

@ciaranmcnulty
Copy link
Contributor

Prophecy 1.12.0 was just tagged which allows php 8.0

@praad
Copy link

praad commented Nov 27, 2020

Composer update on Mac Osx Big Sur

Problem 1
- phploc/phploc[6.0.0, ..., 6.0.2] require php ^7.3 -> your php version (8.0.0) does not satisfy that requirement.
- Root composer.json requires phploc/phploc ^6.0 -> satisfiable by phploc/phploc[6.0.0, 6.0.1, 6.0.2].

sadafrangian3 pushed a commit to sadafrangian3/Laravel-unit-reverse-lookup that referenced this issue Nov 2, 2022
sadafrangian3 pushed a commit to sadafrangian3/php-file-iterator-build that referenced this issue Nov 2, 2022
gregoryross1211 added a commit to gregoryross1211/Laravel-build-unit-reverse-lookup that referenced this issue Nov 11, 2022
sadafrangian3 added a commit to sadafrangian3/file-iterator-php that referenced this issue Apr 6, 2023
sadafrangian3 added a commit to sadafrangian3/object-reflector-php that referenced this issue Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests