LARAVEL Quality Control & Assurance 5 — Questions and Answers
Question 1: Which assertion verifies that a Laravel job was pushed onto a specific queue name?
- Queue::assertPushedOn (Correct answer)
- Queue::assertDispatched
- Queue::assertQueued
- Bus::assertQueued
Correct answer: Queue::assertPushedOn
assertPushedOn accepts a queue name and a job class to confirm a job was dispatched to that specific queue.
Question 2: What does the `--parallel` flag do when running `php artisan test --parallel`?
- Runs test files concurrently across multiple processes (Correct answer)
- Runs each test method in a separate thread
- Splits the test suite into two halves
- Enables parallel database transactions
Correct answer: Runs test files concurrently across multiple processes
The --parallel flag uses multiple worker processes to run test files simultaneously, reducing total test suite time.
Question 3: In Laravel Pest, which function creates a shareable test helper that can be reused across multiple describe blocks?
- uses() (Correct answer)
- beforeAll()
- shared()
- helpers()
Correct answer: uses()
uses() applies traits or test case classes to a test file or describe block, enabling shared setup across tests.
Question 4: Which method on a `TestResponse` asserts that a redirect goes to a named route?
- assertRedirectToRoute (Correct answer)
- assertRedirect
- assertNamedRedirect
- assertRouteRedirect
Correct answer: assertRedirectToRoute
assertRedirectToRoute resolves the named route and checks that the response Location header points to it.
Question 5: What is the purpose of defining a `definition()` method in a Laravel model factory?
- It returns the default attribute array used when making or creating model instances (Correct answer)
- It specifies which database table the factory targets
- It defines validation rules for the factory
- It sets the factory's Faker locale
Correct answer: It returns the default attribute array used when making or creating model instances
definition() must return an associative array of attribute defaults that the factory uses to populate model fields.
Question 6: Which Laravel test assertion checks that exactly zero exceptions were thrown during a request?
- There is no built-in assertion; use withoutExceptionHandling and expect no exception (Correct answer)
- assertNoExceptions()
- assertClean()
- assertSucceeded()
Correct answer: There is no built-in assertion; use withoutExceptionHandling and expect no exception
Laravel has no assertNoExceptions(); instead, withoutExceptionHandling() lets any thrown exception fail the test naturally.
Question 7: Which code quality tool checks Laravel code for style violations based on PSR-12 and Laravel coding standards?
- Laravel Pint (Correct answer)
- PHPStan
- Larastan
- Rector
Correct answer: Laravel Pint
Laravel Pint is an opinionated PHP code style fixer built on PHP-CS-Fixer that enforces Laravel's own coding standards.
Which assertion verifies that a Laravel job was pushed onto a specific queue name?