Installation:
composer require imanghafoori/laravel-makesure --dev
No additional configuration is required—just publish the facade alias if needed (though the package auto-registers).
First Use Case: Replace a basic HTTP assertion in a test:
// Before (standard Laravel)
$this->get('/api/users')
->assertStatus(200)
->assertJson(['count' => 1]);
// After (MakeSure)
MakeSure::about($this)
->sendingGetRequest('/api/users')
->isRespondedWith()
->statusCode(200)
->json(['count' => 1]);
Where to Look First:
Imanghafoori\MakeSure\Facades\MakeSure (or alias MakeSure).about($this) → HTTP method (e.g., sendingGetRequest()) → assertions (e.g., statusCode(), json()).sendingPostRequest(), isRespondedWith()).Test Initialization:
Always pass $this (the test case instance) to MakeSure::about($this) to maintain context.
HTTP Request Chaining:
MakeSure::about($this)
->sendingPostRequest('/api/users')
->withHeaders(['Accept' => 'application/json'])
->withData(['name' => 'John']);
Assertion Patterns:
->isRespondedWith()
->statusCode(201);
->isRespondedWith()
->json(['key' => 'value']);
->isRedirectedTo('/login');
->throwsException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class);
Dynamic Data: Use helper methods for reusable assertions:
// In a trait or helper
public function assertUserCreatedResponse()
{
return MakeSure::about($this)
->isRespondedWith()
->statusCode(201)
->json(['id' => $this->user->id]);
}
Integration with Laravel Features:
$this->actingAs($user);
MakeSure::about($this)
->sendingGetRequest('/profile')
->isRespondedWith()
->statusCode(200);
JsonTestingTrait for API-specific assertions:
MakeSure::about($this)
->sendingJsonPostRequest('/api/login')
->isRespondedWith()
->statusCode(200)
->header('Content-Type', 'application/json');
Grouping Assertions:
Use group() to organize related assertions:
MakeSure::about($this)
->group('User Creation')
->sendingPostRequest('/users')
->isRespondedWith()
->statusCode(201)
->json(['name' => 'John']);
Context Loss:
$this to about() will break the chain.MakeSure::about($this) at the start of every test.Method Order Sensitivity:
isRespondedWith()) must precede others (e.g., statusCode()).isRespondedWith() → assertions.Facade Alias Conflicts:
MakeSure, manually bind the facade in config/app.php:
'aliases' => [
'MakeSure' => Imanghafoori\MakeSure\Facades\MakeSure::class,
],
JSON Assertions:
->json(['user.profile.name' => 'John']);
Chain Validation:
dd() on intermediate steps to verify the response object:
$response = MakeSure::about($this)
->sendingGetRequest('/api/users')
->getResponse(); // Debug here
Custom Assertions:
namespace App\Tests\Assertions;
use Imanghafoori\MakeSure\Assertions\Assertion;
class CustomAssertion extends Assertion {
public function customCheck($expected) {
return $this->response->assertSee($expected);
}
}
MakeSureServiceProvider (if extending).Performance:
MakeSure for simple tests may reduce readability.Custom HTTP Methods:
sendingCustomRequest()) by extending the MakeSure facade:
public function sendingCustomRequest($uri, $method = 'CUSTOM') {
return $this->newAssertion()
->sendingRequest($uri, $method);
}
Database Assertions:
DatabaseMigrations or DatabaseTransactions traits:
$this->actingAs($admin);
MakeSure::about($this)
->sendingDeleteRequest('/api/users/1')
->isRespondedWith()
->statusCode(200)
->databaseHas('users', ['id' => 1], false); // Custom extension
Mocking:
MakeSure with Mockery or Laravel’s partialMock:
$mock = $this->partialMock(User::class, ['find']);
MakeSure::about($this)
->sendingGetRequest('/api/users/1')
->isRespondedWith()
->statusCode(200)
->mock($mock); // Hypothetical extension
Reporting:
// Example: Custom reporter for MakeSure chains
public function addFailure(MakeSure $makeSure, $description) {
$this->fail($description . "\nChain: " . $makeSure->getChain());
}
How can I help you explore Laravel packages today?