DB State testing release
Features
- New predefined filters
app(UserService::class)->search(['age_lte' => 16]); //return users with `age` field less or equals 16
app(UserService::class)->search(['age_gte' => 21]); //return users with `age` field greater or equals 21
app(UserService::class)->search(['age_lt' => 16]); //return users with `age` field greater than 16
app(UserService::class)->search(['age_gt' => 21]); //return users with `age` field less than 21
- Ability to test changes in DB table state instead of has/missing data
Native syntax
public function testClearExpiredCodes()
{
$this->artisan('clear:verification-codes');
$this->assertDatabaseMissing('verification_codes', [
'is_expired' => true
]);
}
2.6 syntax
class VerificationCodeTest extends TestCase
protected static ModelTestState $verificationCodesState;
public function setUp(): void
{
parent::setUp();
self::$verificationCodesState ??= new ModelTestState(VerificationCodeModel::class);
}
public function testClearExpiredCodes()
{
$this->artisan('clear:verification-codes');
self::$verificationCodesState->assertChangesEqualsFixture('clear_codes_command');
}
Deprecated
_from
/_to
predefined filters now deprecated and will be removed with the next release
2.4 syntax
app(UserService::class)->search(['created_at_from' => $date]);
app(UserService::class)->search(['age_to' => 18]);
2.5 syntax
app(UserService::class)->search(['created_at_gt' => $date]);
app(UserService::class)->search(['age_lt' => 18]);