phpunitが古いバージョンで使われていたので、新しくしたいなと思いまして、最新のバージョン(この記事を書いたときはphpunit 9.3.10が最新だった)にバージョンアップをしてみました。 ただ、composer周りの経験がなかったので、躓いてしまったので、この記事にメモとして残していきたいと思います。

バージョンアップ前
まずは、バージョンアップする前のバージョンを確認します。
$ phpunit --version PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
バージョンアップ前は7.5.20です。
バージョンアップする
では、早速バージョンアップしていきましょう。
phpunitをアンインストールする
とりあえず古いバージョンは削除しておきます。
$ composer remove phpunit/phpunit --dev
再びphpunitをインストールする
ここでは最新のphpunitを入れたいので、バージョンを指定せずにコマンドを叩きます。
$ composer require phpunit/phpunit --dev
Using version ^9.3 for phpunit/phpunit
./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
- Conclusion: don't install phpunit/phpunit 9.3.10
- Conclusion: don't install phpunit/phpunit 9.3.9
- Conclusion: don't install phpunit/phpunit 9.3.8
- Conclusion: don't install phpunit/phpunit 9.3.7
- Conclusion: don't install phpunit/phpunit 9.3.6
- Conclusion: don't install phpunit/phpunit 9.3.5
- Conclusion: don't install phpunit/phpunit 9.3.4
- Conclusion: don't install phpunit/phpunit 9.3.3
- Conclusion: don't install phpunit/phpunit 9.3.2
- Conclusion: don't install phpunit/phpunit 9.3.1
- Conclusion: don't install phpunit/phpunit 9.3.0
- Conclusion: don't install phpunit/phpunit 9.4.x-dev
- Conclusion: remove nikic/php-parser v4.5.0
- Installation request for phpunit/phpunit ^9.3 -> satisfiable by phpunit/phpunit[9.3.0, 9.3.1, 9.3.10, 9.3.2, 9.3.3, 9.3.4, 9.3.5, 9.3.6, 9.3.7, 9.3.8, 9.3.9, 9.3.x-dev, 9.4.x-dev].
- Conclusion: don't install nikic/php-parser v4.5.0
- phpunit/phpunit 9.3.x-dev requires phpunit/php-code-coverage ^9.1.10 -> satisfiable by phpunit/php-code-coverage[9.1.10, 9.1.11, 9.1.x-dev].
- phpunit/php-code-coverage 9.1.10 requires nikic/php-parser ^4.8 -> satisfiable by nikic/php-parser[4.9.x-dev, v4.8.0, v4.9.0, v4.9.1].
- phpunit/php-code-coverage 9.1.11 requires nikic/php-parser ^4.8 -> satisfiable by nikic/php-parser[4.9.x-dev, v4.8.0, v4.9.0, v4.9.1].
- phpunit/php-code-coverage 9.1.x-dev requires nikic/php-parser ^4.8 -> satisfiable by nikic/php-parser[4.9.x-dev, v4.8.0, v4.9.0, v4.9.1].
- Can only install one of: nikic/php-parser[4.9.x-dev, v4.5.0].
- Can only install one of: nikic/php-parser[v4.8.0, v4.5.0].
- Can only install one of: nikic/php-parser[v4.9.0, v4.5.0].
- Can only install one of: nikic/php-parser[v4.9.1, v4.5.0].
- Installation request for nikic/php-parser (locked at v4.5.0) -> satisfiable by nikic/php-parser[v4.5.0].
Installation failed, reverting ./composer.json to its original content.
エラーが発生して失敗しました。
どうらや、phpunit/php-code-coverageとnikic/php-parserのそれなりの新しいバージョンが必要そうです。ここでは、それぞれインストールしてなかったので、インストールしていきます。
ただ、以下のように、まずはnikic/php-parserを先にインストールしたほうが良さそうなものが書いてあるので、そちらからインストールしていきます。
- phpunit/php-code-coverage 9.1.x-dev requires nikic/php-parser ^4.8 -> satisfiable by nikic/php-parser[4.9.x-dev, v4.8.0, v4.9.0, v4.9.1].
ちなみに先にphpunit/php-code-coverageをインストールしようとすると以下のように想定通りのエラーが出ました。
$ composer require phpunit/php-code-coverage --dev
Using version ^9.1 for phpunit/php-code-coverage
./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
- Conclusion: don't install phpunit/php-code-coverage 9.1.11
- Conclusion: don't install phpunit/php-code-coverage 9.1.10
- Conclusion: don't install phpunit/php-code-coverage 9.1.9
- Conclusion: don't install phpunit/php-code-coverage 9.1.8
- Conclusion: don't install phpunit/php-code-coverage 9.1.7
- Conclusion: don't install phpunit/php-code-coverage 9.1.6
- Conclusion: don't install phpunit/php-code-coverage 9.1.5
- Conclusion: don't install phpunit/php-code-coverage 9.1.4
- Conclusion: don't install phpunit/php-code-coverage 9.1.3
- Conclusion: don't install phpunit/php-code-coverage 9.1.2
- Conclusion: don't install phpunit/php-code-coverage 9.1.1
- Conclusion: don't install phpunit/php-code-coverage 9.1.0
- Conclusion: remove nikic/php-parser v4.5.0
- Installation request for phpunit/php-code-coverage ^9.1 -> satisfiable by phpunit/php-code-coverage[9.1.0, 9.1.1, 9.1.10, 9.1.11, 9.1.2, 9.1.3, 9.1.4, 9.1.5, 9.1.6, 9.1.7, 9.1.8, 9.1.9, 9.1.x-dev].
- Conclusion: don't install nikic/php-parser v4.5.0
- phpunit/php-code-coverage 9.1.x-dev requires nikic/php-parser ^4.8 -> satisfiable by nikic/php-parser[4.9.x-dev, v4.8.0, v4.9.0, v4.9.1].
- Can only install one of: nikic/php-parser[4.9.x-dev, v4.5.0].
- Can only install one of: nikic/php-parser[v4.8.0, v4.5.0].
- Can only install one of: nikic/php-parser[v4.9.0, v4.5.0].
- Can only install one of: nikic/php-parser[v4.9.1, v4.5.0].
- Installation request for nikic/php-parser (locked at v4.5.0) -> satisfiable by nikic/php-parser[v4.5.0].
Installation failed, reverting ./composer.json to its original content.
nikic/php-parserのインストール
ということで、nikic/php-parserのインストールをしていきます。
$ composer require nikic/php-parser --dev Using version ^4.9 for nikic/php-parser ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 0 installs, 1 update, 0 removals - Updating nikic/php-parser (v4.5.0 => v4.9.1): Loading from cache ... たくさんログが流れて成功
無事インストールできたっぽいです。
php-code-coverageのインストール
次にphp-code-coverageのインストールです。
$ composer require phpunit/php-code-coverage --dev Using version ^9.1 for phpunit/php-code-coverage ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 9 installs, 0 updates, 0 removals - Installing theseer/tokenizer (1.2.0): Loading from cache - Installing sebastian/version (3.0.1): Loading from cache - Installing sebastian/lines-of-code (1.0.0): Loading from cache - Installing sebastian/environment (5.1.2): Loading from cache - Installing sebastian/complexity (2.0.0): Loading from cache - Installing sebastian/code-unit-reverse-lookup (2.0.2): Loading from cache - Installing phpunit/php-text-template (2.0.2): Loading from cache - Installing phpunit/php-file-iterator (3.0.4): Loading from cache - Installing phpunit/php-code-coverage (9.1.11): Downloading (100%) phpunit/php-code-coverage suggests installing ext-pcov (*) ... たくさんログが流れて成功
無事こちらもインストールができました。
phpunit/phpunitのインストール
そして、やっとphpunitのインストールですね。
$ composer require phpunit/phpunit --dev Using version ^9.3 for phpunit/phpunit ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 23 installs, 0 updates, 0 removals - Installing sebastian/type (2.2.1): Loading from cache - Installing sebastian/resource-operations (3.0.2): Loading from cache - Installing sebastian/recursion-context (4.0.2): Loading from cache - Installing sebastian/object-reflector (2.0.2): Loading from cache - Installing sebastian/object-enumerator (4.0.2): Loading from cache - Installing sebastian/global-state (5.0.0): Loading from cache - Installing sebastian/exporter (4.0.2): Loading from cache - Installing sebastian/diff (4.0.2): Loading from cache - Installing sebastian/comparator (4.0.3): Loading from cache - Installing sebastian/code-unit (1.0.5): Loading from cache - Installing sebastian/cli-parser (1.0.0): Loading from cache - Installing phpunit/php-timer (5.0.1): Loading from cache - Installing phpunit/php-invoker (3.1.0): Loading from cache - Installing phpdocumentor/reflection-common (2.2.0): Loading from cache - Installing phpdocumentor/type-resolver (1.4.0): Loading from cache - Installing doctrine/instantiator (1.3.1): Loading from cache - Installing webmozart/assert (1.8.0): Loading from cache - Installing phpdocumentor/reflection-docblock (5.1.0): Loading from cache - Installing phpspec/prophecy (1.11.1): Loading from cache - Installing phar-io/version (3.0.2): Loading from cache - Installing phar-io/manifest (2.0.1): Loading from cache - Installing myclabs/deep-copy (1.10.1): Loading from cache - Installing phpunit/phpunit (9.3.10): Loading from cache sebastian/global-state suggests installing ext-uopz (*) phpunit/php-invoker suggests installing ext-pcntl (*) phpunit/phpunit suggests installing ext-soap (*) .... たくさんログが流れて成功
バージョンアップ後
といことで、バージョンアップが完了したはずです。
$ phpunit --version PHPUnit 9.3.10 by Sebastian Bergmann and contributors.
無事、phpunitのバージョンを7.5.20から9.3.10にアップすることができました。
phpunitを実行してみよう
では、バージョンアップしたので、実行していきましょう。
phpunit PHPUnit 9.3.10 by Sebastian Bergmann and contributors. Warning: Your XML configuration validates against a deprecated schema. Suggestion: Migrate your XML configuration using "--migrate-configuration"! .....^C
おや、Warningが出ました。
phpunit.xmlのマイグレーション
サジェストに書いてあるように、--migrate-configurationをつけてxml構成のマイグレーションが必要っぽいです。
$ phpunit --migrate-configuration PHPUnit 9.3.10 by Sebastian Bergmann and contributors. Created backup: /var/www/phpunit.xml.bak Migrated configuration: /var/www/phpunit.xml
お、無事新しいphpunit.xmlが作成されました。 .bakのファイルとdiffを取ったりして比べてみるとわかりますが、微妙にxmlの書き方が変わっています。
今度こそphpunitの実行
phpunit PHPUnit 9.3.10 by Sebastian Bergmann and contributors. .............^C
ということで無事phpunitのバージョンアップに成功しました。