Bill Check — Testing

Test a village biogas bill calculator with PHPUnit and Pest: test names, TDD, the office's CI. 16 levels, played right in the browser with nothing to install.

What the levels ask

  1. Last month Riko changed Tagihan::hitung so the slip prints the amount as text. Pak Tono's cash book checks $dibayar === $tagihan, so Bu Yanti, who paid exactly Rp 15,000, was written down as unpaid. Pick the assertion for the 10 m³ test so it is green for the office calculator and red when the bill comes back as text or as a float.
  2. Bu Sari used exactly 20 m³ and Riko's calculator charged her Rp 1,500 per m³. The rule: up to 10 m³ is Rp 1,000, up to 20 m³ is Rp 1,200, above that Rp 1,500, and a number exactly on a boundary belongs to the cheaper tier. Fill in the data provider rows and how they are wired in, so one test checks every row and catches it when the 10 or 20 m³ boundary shifts.
  3. Pak Tono records this month's bills in BukuTagihan. Mas Fahri wrote two tests for it, and both use $this->buku. Pick how the ledger is prepared so both tests pass in any order and catch the copy of jumlah() that skips the first row.
  4. Nenek Marni's gas meter was replaced this week: the old reading was 412, the new meter starts from 3. The calculator rejects a meter that goes backwards with InvalidArgumentException, and the office form catches that exception to ask for a new reading. Arrange the test so it is green for the office calculator and red for the copy without the guard and for the copy that throws a different kind of exception.
  5. Mas Fahri installed Pest in the same project. His first test checks Bu Yanti's bill for 12.4 m³: 12.4 times Rp 1,200 plus the abonemen, Rp 19,880. Pick the matcher and the number so the test is green for the office calculator and red for the copies that return text or a float.
  6. The tier boundaries move to Pest. The rows are registered once in tests/Datasets/Golongan.php under the name batas golongan, so other tests can use them. Pick the test function's parameters and the dataset it uses, so the copies that shift the 10 and 20 m³ boundaries are caught.
  7. The ledger tests are rewritten in Pest. Pick how $this->buku is prepared so both tests pass in any order and the copy of jumlah() that skips the first row is caught.
  8. Mak Ijah paid on the 11th, so her bill is the Rp 5,000 abonemen plus a Rp 2,000 late fee. Riko wrote the late fee test in PHPUnit, Mas Fahri wrote it in Pest. Pick the check in both files so both runners give the same verdict on every calculator, and both are red for the text and float copies.
  9. Pak Tono does not read code; he reads the --testdox report, one sentence per test. The late fee tests are already written with Given, When, Then. Name both methods so that when one late fee rule is broken, the red line Pak Tono reads names that rule.
  10. The RW meeting wants proof that every billing rule is guarded by its own test. Mas Fahri breaks one rule at a time: the abonemen becomes Rp 4,000, 10 m³ falls into the middle tier, the late fee disappears. Fill in the three tests so each broken copy turns exactly one test red, the one whose name says that rule.
  11. The RW meeting decided the elderly (lansia) pay no abonemen. The office form already sends lansia: true, and rincian() already takes $lansia but does not use it yet. Write the test first: pick its contents so the first run is red because the elderly rule is not there yet, not because of a typo, a class that does not exist, or a test that checks nothing.
  12. The elderly test is red. Pick the change to rincian() so every test is green and every changed line is one a test asked for: Mas Fahri will take back each changed line one at a time, and each time some test has to go red.

And more, 16 levels in all.