Download the PHP package aklump/phpswap without Composer
On this page you can find all versions of the php package aklump/phpswap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpswap
PHP Swap
Summary
Provides a means to easily execute code with PHP versions other than the default. This was first built to run PhpUnit tests within Composer projects across multiple PHP versions. See example below.
Quick Start
This simple code example should give you an idea of how this works.
What It Does
- Temporarily modifies
$PATH
with a different PHP version binary. - If composer.json is present, runs
composer update
so that dependencies appropriate for the swapped PHP version get installed. - Runs the given executable, which can be a command or a script path.
- Lastly, if necessary, runs
composer update
with the original PHP to restore the Composer dependencies.
What PHP Versions Are Supported?
To see the available versions, which will echo those versions provided by MAMP you can use the show
command.
Dependencies
Getting Started
- Ensure you have MAMP installed.
- Download all PHP versions using MAMP that you hope to swap.
composer require aklump/phpswap
in your project.- Use
vendor/bin/phpswap show
to see what versions are available. ./phpswap list
to see all available commands.
Examples with PhpUnit
Here is a pattern you can use to run PhpUnit under PHP 7.1, 7.4 and 8.1.
- Given you have installed phpunit in your project with Composer
- And you run your tests using
./vendor/bin/phpunit -c phpunit.xml
- Then you can implement PhpSwap in the following way:
- See also Controller File Example further down.
CLI Options
-v
In verbose mode you will see the Composer output.
--working-dir
This sets the working directory from which your script is called. This is optional.
Troubleshooting
During execution, a file called composer.lock.phpswap is temporarily created in your project. It contains a copy of the composer.lock file that was in your project before the swap. This file is used to refresh composer.lock at the end of a swap. In some error situations this file may not be deleted. Use the snippet below to recover.
You may also see "Composer detected issues in your platform:" after a swap executed. The same applies here, try the snippet below.
Controller File Example
Here is a complete snippet for controlling tests. Save as _bin/run_unittests.sh and call it like this: bin/run_unit_tests.sh -v
. You may leave off the verbose -v
flag unless troubleshooting.