levelmax World 0 Tutorial
  1. 0
  2. 1
  3. 2
  4. 3
L
Level 0.1 ~8 min Target: PHPStan level 0

The sandbox

Every exercise in this course runs real PHPUnit and real PHPStan. Nothing is simulated in your browser, and nothing runs on your machine. Before the climb starts, it's worth knowing what happens when you click a button.

What happens when you click Submit

flowchart TB
  accTitle: What happens when you click Submit
  accDescr: The editor sends only your editable files to the levelmax web app, which forwards them to the runner. The runner adds the read-only files, hidden tests, and PHPStan configuration from its own copy of the course, starts a brand-new container with no network access, and runs PHPUnit and PHPStan. Results come back to the page.
  you([Your editable files]) --> app[levelmax web app]
  app --> runner[Runner service]
  runner --> add[Adds read-only files, hidden tests, and PHPStan config]
  add --> box[Brand-new container: no network, time and memory limits]
  box --> phpunit{{PHPUnit}}
  box --> phpstan{{PHPStan}}
  phpunit --> results([Results, per test and per diagnostic])
  phpstan --> results

A few things follow from that:

  • Run tests runs PHPUnit. Analyse runs PHPStan at the level's target. Submit runs both, and the level clears only when both pass.
  • Only editable files are sent. Read-only files are there to read: the runner uses its own copy, so editing them couldn't help even if you could.
  • Tests are usually hidden. They check behaviour, not your exact code, so any correct fix passes. This level shows its tests so you can see what they look like.
  • Every run gets a fresh container with no network and a time limit of a few seconds. Nothing carries over between runs.
  • Your code autosaves in your browser, so a refresh won't lose it. Reset puts the current file back to the starter.
  • Hints unlock one at a time. After three failed submits you can reveal the solution. It still counts. Everyone peeks.
You, 23:47"It passes locally."
The runner, 23:47Fresh container. Pinned PHP. Same PHPStan as everyone else.
You, 23:48"Ah. It passes somewhere."

The files you'll see

Exercises use plain PHP classes in src/, with PHPUnit tests in tests/. There's no framework, no Composer, and no phpunit.xml to fiddle with: the runner provides those.

Tab What it is
Editable files The code you change. Most levels have one.
READ ONLY Trusted helpers and rules. Read them: they often hold the answer.
TESTS Shown only when a level wants you to read them.

Quick check

1. What does Submit need before a level clears?
2. Why can't you clear this level by changing FREE_SHIPPING_FROM_PENCE in ShopRules?

CHALLENGE

The shop promises free delivery on orders of £50 or more. A customer with exactly £50.00 in their basket is being charged £3.99.

Read ShopRules (read only), then fix Shipping::costFor() in src/Shipping.php. Click Run tests first to see the failure, then Submit.

Running on PHP 8.3…

Run the tests, run PHPStan, or submit for both. Ctrl/⌘ + Enter submits from the editor.