A project to test your CodinGame PHP code. It is not intended to have solutions. It only contains PHPUnit tests to let you code in your favorite IDE, outside of the CodinGame web site.
This project now uses PHP 8.4. Unfortunaly, CodinGame is still on PHP 7.3 which is not supported anymore. If you want to run your code on PHP 7.3, you can use a version up to 3.x of this software which do not receive further update.
This project uses Git to download/update the project and Docker to run the code. You can use this software without Git and Docker, but no support will be provided to that end.
Download the project :
user@host ~$ cd [PATH_WHERE_TO_PUT_THE_PROJECT] # E.g. ~/projects/
user@host projects$ git clone https://github.com/cyrilverloop/codingame-php-tests.git
user@host projects$ cd codingame-php-testsCopy some configuration files for Docker and PHPUnit :
user@host projects$ cp ./ci/phpunit.dist.xml ./ci/phpunit.xml
user@host projects$ cp ./.env.dist ./.env
user@host projects$ cp ./.ashrc.dist ./.ashrc
user@host projects$ cp ./compose.override.yaml.dist ./compose.override.yamlEdit the ./.env to add your user to the container.
The ./ci/phpunit.xml, ./.ashrc, ./.env and ./compose.override.yaml files are ignored by git, you can modify them to your needs.
The ./.ashrc and ./compose.override.yaml add some aliases to your container.
Install the dependencies :
user@host codingame-php-tests$ docker compose run --rm app composer install -o
user@host codingame-php-tests$ docker compose run --rm app phive install --trust-gpg-keys 4AA394086372C20A,12CE0F1D262429A5,5E6DDE998AB73B8E,C5095986493B4AA0Generate the code and test files :
user@host codingame-php-tests$ docker compose run --rm app bin/generate-testsExisting code, test, input and output files will not be overwritten. To generate a file again, you must delete it first.
Every classes in ./src/**/*CGCode.php files have an execute() method with the default CodinGame code.
A test executes the CGCode::execute() method. You can add your code in and arround it.
Launch a container and connect to it :
user@host codingame-php-tests$ docker compose run --rm app ashExecute all the tests :
phpunitExecute tests of a group :
phpunit --group [GROUP_NAME]To view the list of test groups :
phpunit --list-groupsYou can also execute tests from outside of the container :
user@host codingame-php-tests$ docker compose run --rm app ./tools/phpunit -c ./ci/phpunit.xmlTip : to activate HTML coverage report and testdox logging, you can uncomment their configuration in phpunit.xml.
Every tests in ./tests/**/CGTest.php files include the tests from CodinGame.
You can add your own tests and add them to a group with the Group attribute.
When you copy your code back to CodinGame, you must change every $stdin in fscanf(), stream_get_line(), ...
by STDIN :
// In this project :
fscanf($stdin, "%d", $N);// On CodinGame :
fscanf(STDIN, "%d", $N);The maximum time allowed may differ from CodinGame.