PHP Quality Control & Assurance 5 — Questions and Answers
Question 1: Which PHPUnit assertion should you use to verify a string contains a specific substring?
- assertStringIncludes()
- assertContains()
- assertStringContainsString() (Correct answer)
- assertHasSubstring()
Correct answer: assertStringContainsString()
assertStringContainsString($needle, $haystack) is the correct PHPUnit 9+ assertion for substring checks.
Question 2: What is the purpose of the @covers annotation in PHPUnit?
- Mark a test as incomplete
- Restrict coverage credit to only the specified class or method (Correct answer)
- Skip a test on certain PHP versions
- Group tests into a named suite
Correct answer: Restrict coverage credit to only the specified class or method
@covers restricts which code is credited with coverage when a test runs, preventing false coverage from indirect calls.
Question 3: In Psalm (PHP static analyzer), what does the 'errorLevel' setting control?
- The severity of PHPUnit test failures
- How strictly Psalm reports type errors and issues (Correct answer)
- The logging verbosity of the web server
- The PHP error_reporting bitmask
Correct answer: How strictly Psalm reports type errors and issues
Psalm's errorLevel (1–8) determines which categories of issues are reported, with 1 being strictest.
Question 4: What is 'test isolation' and why is it important in PHP unit testing?
- Running tests on an isolated server
- Ensuring each test does not depend on or affect other tests (Correct answer)
- Limiting tests to a single class
- Separating unit tests from integration tests in folders
Correct answer: Ensuring each test does not depend on or affect other tests
Test isolation means each test sets up and tears down its own state so failures are independent and reproducible.
Question 5: Which HTTP status code range should an integration test typically assert for a successful PHP API response?
- 100–199
- 200–299 (Correct answer)
- 300–399
- 400–499
Correct answer: 200–299
2xx status codes indicate success; integration tests assert these to confirm the API handled the request correctly.
Question 6: What does the Infection mutation testing tool report as a 'killed' mutant?
- A mutant that caused a syntax error
- A mutant whose code change was caught by a failing test (Correct answer)
- A mutant that was skipped due to timeout
- A mutant identical to the original code
Correct answer: A mutant whose code change was caught by a failing test
A mutant is 'killed' when at least one test fails as a result of the code change, proving the test suite detects that behavior.
Question 7: Which PHP QA practice involves reviewing code changes with a focus on logic errors before they are merged?
- Continuous deployment
- Peer code review (Correct answer)
- Load testing
- A/B testing
Correct answer: Peer code review
Peer code review is a manual QA step where teammates examine a pull request for bugs, design issues, and adherence to standards.
Which PHPUnit assertion should you use to verify a string contains a specific substring?