LARAVEL Quality Control & Assurance 3 — Questions and Answers
Question 1: When using `Http::fake()` in Laravel tests, what happens to real HTTP requests that don't match a faked URL?
- They throw a ConnectionException by default (Correct answer)
- They are silently ignored and return 200
- They hit the real endpoint
- They return an empty response
Correct answer: They throw a ConnectionException by default
By default, Http::fake() throws an exception for any unmatched URL to prevent accidental real HTTP calls during tests.
Question 2: Which method in a Laravel test asserts that a specific notification was NOT sent to a user?
- Notification::assertNotSentTo (Correct answer)
- Notification::assertNothingSent
- Notification::assertMissing
- Notification::assertSkipped
Correct answer: Notification::assertNotSentTo
assertNotSentTo verifies that a given notifiable model did not receive a specific notification class.
Question 3: In Laravel's Pest testing framework, what does `beforeEach()` replace from PHPUnit?
- setUp() (Correct answer)
- setUpBeforeClass()
- tearDown()
- dataProvider()
Correct answer: setUp()
Pest's beforeEach() hook runs before every test in a describe block, equivalent to PHPUnit's setUp() method.
Question 4: What static analysis tool integrates with Laravel via the larastan package?
- PHPStan (Correct answer)
- Psalm
- Phan
- Rector
Correct answer: PHPStan
Larastan is a PHPStan extension that adds Laravel-specific type inference so PHPStan can analyze Laravel projects accurately.
Question 5: Which command runs only tests that have been marked with a specific PHPUnit group annotation?
- php artisan test --group=groupname (Correct answer)
- php artisan test --filter=groupname
- php artisan test --tag=groupname
- php artisan test --suite=groupname
Correct answer: php artisan test --group=groupname
The --group flag filters PHPUnit test execution to only those tests annotated with the matching @group value.
Question 6: When faking events in Laravel tests, which method verifies an event was dispatched a specific number of times?
- Event::assertDispatchedTimes (Correct answer)
- Event::assertCount
- Event::assertTimesDispatched
- Event::assertFiredCount
Correct answer: Event::assertDispatchedTimes
assertDispatchedTimes accepts an event class and an integer, asserting it was fired exactly that many times.
Question 7: Which `make:test` flag generates a unit test instead of a feature test in Laravel?
- --unit (Correct answer)
- --type=unit
- --class=unit
- --no-feature
Correct answer: --unit
php artisan make:test FooTest --unit places the test in tests/Unit and extends PHPUnit\Framework\TestCase directly.
When using `Http::fake()` in Laravel tests, what happens to real HTTP requests that don't match a faked URL?