I've been using devsense for a short period, and so far, so good (I love it), unfortunately, when using PestPHP as testing framework, using $this in the callbacks does not give access to the protected methods of the base test case. I tried with PHPstan like docs and I have not made them work. I tend to disable it with phpcs:ignorefile but it seems to be an overkill for something that should be included in the extension.
This is the output without annotations, with param-closure-this TestCase docblock and with var TestCase $this docblock ( usingTests\TestCase in the imports):
it('can run prune command', function () {
$this->artisan('model:prune')
->assertOk();
});
it('can prune activity model', function () {
/** @param-closure-this TestCase */
$class = Activity::class;
$model = new Activity;
$pruneInPeriod = 10;
$instanceFile = new InstanceFileService;
$demo = $instanceFile->get('demo');
$demo['demo']['pruneInDays'] = $pruneInPeriod;
$instanceFile->update($demo);
Activity::factory(state: ['created_at' => now()->subDays($pruneInPeriod)])->createMany(5);
$this->assertDatabaseCount('activity_log', 5);
$this->artisan('model:prune', ['--model' => [$class]])
->assertOk();
unset($demo['demo']['pruneInDays']);
$instanceFile->update($demo);
$this->assertDatabaseEmpty('activity_log');
});
it('does not prune when prune period does not exist or is 0', function () {
/** @var TestCase $this */
$instanceFile = new InstanceFileService;
$demo = $instanceFile->get('demo');
if (isset($demo['demo']['pruneInDays'])) {
$demo['demo']['pruneInDays'] = 0;
$instanceFile->update($demo);
}
Activity::factory(state: ['created_at' => now()->subDays(10)])->createMany(5);
$this->assertDatabaseCount('activity_log', 5);
$this->artisan('model:prune', ['--model' => [Activity::class]])
->assertOk();
$this->assertDatabaseCount('activity_log', 5);
});
I've been using devsense for a short period, and so far, so good (I love it), unfortunately, when using PestPHP as testing framework, using $this in the callbacks does not give access to the protected methods of the base test case. I tried with PHPstan like docs and I have not made them work. I tend to disable it with phpcs:ignorefile but it seems to be an overkill for something that should be included in the extension.
This is the output without annotations, with param-closure-this TestCase docblock and with var TestCase $this docblock ( using
Tests\TestCasein the imports):