- Install Docker
- Fork this repo (please do so in a private repository, they're free now!)
- Choose a code editor
- We recommend the PhpStorm EAP
- It's free, and we share configuration in this repository to get you up and running quickly
- But feel free to use whatever you're comfortable with
- (optional) Install Postman to easily test the API manually
To get setup and ready to go, run the following commands in the root of the repository.
# Build the necessary docker containers
# It might take a few minutes, so grab a coffee (or a beer, it's 5 o'clock somewhere!)
$ docker compose build
# Start the docker containers so that you can access the environment
$ docker compose up
# Install PHP dependencies with Composer
$ docker compose run composer install
# Create the database (but not the schema)
$ docker compose run php make create-db
# Run the database migrations to create the schema
$ docker compose run php make migrate
# Load some fixtures into the database so that you have something to play with
$ docker compose run php make fixtures
# Create the test database and schema (fixtures are loaded and refreshed automatically for tests)
$ docker compose run php make test-db
You can now access the application at http://localhost:8080!
# Get into interactive PHP
$ docker compose run php
# Get a shell into a PHP container
$ docker compose run php sh
# Run the entire test suite
$ docker compose run php make test
# Run Psalm static analysis
$ docker compose run php make psalm
Xdebug is configured to connect to your IDE over port 9000. Once you set a breakpoint, you will probably have to:
- Enable xdebug in your IDE (tell it to start listening for connections)
- Set the XDEBUG_SESSION GET parameter (not necessary for tests)
Now you should be able to run the code with either PhpUnit or by hitting an endpoint. At this point, your IDE might
ask you to set up path mappings or servers. You need to map the repository root to /var/www/html
. This is how it's
configured in PhpStorm:
See the following sections for more details on using Xdebug.
To get started quickly you can import the Mobjack Postman collection by following this guide.
The Postman collection contains endpoints to create, patch and list subcontractors. You can easily tweak the request data to manually test your implementation.
If you want to use Xdebug with Postman, you can enable the XDEBUG_SESSION GET parameter on each request:
In order to run tests within PhpStorm, you likely need to set up an interpreter and test runner.
An interpreter is the PHP executable for PhpStorm to use to run your tests. We use a remote interpreter in docker so that we all run tests on the same version of PHP with the same configuration.
- Open Preferences (called Settings in Linux/Windows).
- Go to PHP.
- In the CLI Interpreter dropdown, choose the only option
- Click the three dots next to the dropdown (
...
) - Ensure the
Server
option is configured (PhpStorm will probably show an error if it's not)
Now that we have an interpreter, we need to set up the test runner.
- Go to PHP -> Test Frameworks.
- Click the
+
button and choose PHPUnit by Remote Interpreter. - From the dropdown, select the docker interpreter, click Ok.
Now you can run individual tests easily. Just open a PhpUnit test, click the green "play" button on the left hand side, then choose the "Run ..." option.
If you want to use Xdebug, choose the "Debug ..." option.
Accessing the development database in PhpStorm is an easy way to check if your endpoints are working.
- Click the
Database
toolbar icon on the right hand side - Open a console window for the
app@localhost
database