yoklainterview sim

Backend Php Testing Tooling Interview Questions

75 verified Backend Php Testing Tooling interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Php Testing ToolingDifficulty 1
In PHPUnit, a test class conventionally extends which base class to get assertion methods and the test lifecycle (setUp/tearDown, discovery by the runner)?
  • a\PHPUnit\Framework\TestSuite
  • b\PHPUnit\Framework\TestCase
  • c\PHPUnit\Framework\Assert
  • d\PHPUnit\Runner\BaseTestRunner
Explanation:TestCase provides the familiar assert* methods plus the setUp/tearDown lifecycle, and it's what the test runner discovers and instantiates per test method. Assert only has assertions, without the lifecycle/discovery machinery; TestSuite groups tests together; BaseTestRunner isn't part of the framework namespace.
Php Testing ToolingDifficulty 1
In a PHPUnit test class, what is setUp() used for?
  • aIt runs after each test method, typically used for cleanup work.
  • bIt registers a new test case with the test runner.
  • cIt runs once before the entire test class, sharing state between all test methods.
  • dIt runs before EACH test method, avoiding repeated initialization logic in every test.
Explanation:setUp() is invoked before every single test method in the class, giving each test a fresh, predictable starting point without duplicating initialization code in every method. Running cleanup logic after each test is tearDown()'s job, not setUp()'s; and it's not a once-per-class hook — that would let tests interfere with each other's state.
Php Testing ToolingDifficulty 1
In a PHPUnit test class, what is tearDown() used for?
  • aIt runs after EACH test method, typically releasing resources or state that setUp() created.
  • bIt only runs if the test method throws an uncaught exception.
  • cIt runs once after the entire test class finishes, to close any global connections.
  • dIt runs before each test method, right after setUp().
Explanation:tearDown() runs after every test method (regardless of pass/fail), the natural place to release resources or reset state that setUp() set up, keeping tests independent of each other. It isn't conditional on failures, isn't a once-per-class hook, and doesn't run before the test.
Php Testing ToolingDifficulty 1
class MathTest extends \PHPUnit\Framework\TestCase
{
    public function testIsEven(): void
    {
        $this->assertTrue(is_int(4 / 2));
    }
}

What happens when this test runs?
  • aIt fails, because assertTrue() requires a literal true value, not an expression.
  • bIt throws a TypeError, because is_int() cannot be used inside assertTrue().
  • cIt passes, because 4 / 2 evaluates to the integer 2, and is_int(2) is true.
  • dIt fails, because / always returns a float in PHP regardless of the operands.
Explanation:PHP's / returns an int when both operands are ints and the division is exact; 4 / 2 is 2 (an int), so is_int(2) is true and assertTrue(true) passes. assertTrue() happily accepts any boolean expression, not just a literal, and there's no TypeError here.
Php Testing ToolingDifficulty 1
function findUser(array $users, string $id): ?array
{
    foreach ($users as $u) {
        if ($u['id'] === $id) {
            return $u;
        }
    }
    return null;
}

class UserLookupTest extends \PHPUnit\Framework\TestCase
{
    public function testMissingUser(): void
    {
        $result = findUser([], 'u1');
        $this->assertNull($result);
    }
}

Given an empty $users array, what does this test check?
  • aThat findUser returns false, since PHP functions default to returning false on failure.
  • bThat findUser returns null when no matching user is found, and the test passes.
  • cThat findUser throws an exception when the array is empty, and the test fails because no exception is thrown.
  • dThat findUser returns an empty array [], and assertNull treats [] as null.
Explanation:With an empty $users array, the foreach loop never runs, so findUser falls through to return null;. assertNull($result) checks that $result is exactly null, which it is here, so the test passes. PHP has no implicit 'return false on failure' convention, this function never throws, and [] is not treated as null by assertNull.
Php Testing ToolingDifficulty 1
A project's entry script starts with require __DIR__ . '/vendor/autoload.php';. What does this line actually give you?
  • aIt registers Composer's autoloader, which loads classes on demand per composer.json's mappings (e.g. PSR-4).
  • bIt starts the PHPUnit test runner and loads the phpunit.xml configuration.
  • cIt downloads and installs all of the project's dependencies listed in composer.json.
  • dIt manually loads every PHP class file in the project into memory upfront.
Explanation:vendor/autoload.php is a file Composer generates; requiring it registers an autoload function that knows how to map class/namespace names to files (per PSR-4, classmap, etc.), loading each class file lazily the first time that class is actually used. It has nothing to do with PHPUnit specifically, doesn't install anything (that's composer install), and doesn't eagerly load every file.

Test yourself against the 3300-question Backend bank.

Start interview