Extract CanSkipTests trait

This commit is contained in:
Marcus Moore 2024-04-22 10:32:37 -07:00
parent ab45975883
commit 45f5eaac5b
No known key found for this signature in database
4 changed files with 21 additions and 19 deletions

View file

@ -482,16 +482,10 @@ class AssetStoreTest extends TestCase
}); });
} }
public function markIncompleteIfMySQL()
{
if (config('database.default') === 'mysql') {
$this->markTestIncomplete('Custom Fields tests do not work on MySQL');
}
}
public function testEncryptedCustomFieldCanBeStored() public function testEncryptedCustomFieldCanBeStored()
{ {
$this->markIncompleteIfMySQL(); $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$status = Statuslabel::factory()->create(); $status = Statuslabel::factory()->create();
$field = CustomField::factory()->testEncrypted()->create(); $field = CustomField::factory()->testEncrypted()->create();
$superuser = User::factory()->superuser()->create(); $superuser = User::factory()->superuser()->create();

View file

@ -10,18 +10,10 @@ use Tests\TestCase;
class AssetUpdateTest extends TestCase class AssetUpdateTest extends TestCase
{ {
// TODO - this 'helper' is duplicated in AssetStoreTest - we should extract it out if we can figure out how
public function markIncompleteIfMySQL()
{
if (config('database.default') === 'mysql') {
$this->markTestIncomplete('Custom Fields tests do not work on MySQL');
}
}
public function testEncryptedCustomFieldCanBeUpdated() public function testEncryptedCustomFieldCanBeUpdated()
{ {
$this->markIncompleteIfMySQL(); $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$field = CustomField::factory()->testEncrypted()->create(); $field = CustomField::factory()->testEncrypted()->create();
$asset = Asset::factory()->hasEncryptedCustomField($field)->create(); $asset = Asset::factory()->hasEncryptedCustomField($field)->create();
$superuser = User::factory()->superuser()->create(); $superuser = User::factory()->superuser()->create();
@ -39,7 +31,8 @@ class AssetUpdateTest extends TestCase
public function testPermissionNeededToUpdateEncryptedField() public function testPermissionNeededToUpdateEncryptedField()
{ {
$this->markIncompleteIfMySQL(); $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$field = CustomField::factory()->testEncrypted()->create(); $field = CustomField::factory()->testEncrypted()->create();
$asset = Asset::factory()->hasEncryptedCustomField($field)->create(); $asset = Asset::factory()->hasEncryptedCustomField($field)->create();
$normal_user = User::factory()->editAssets()->create(); $normal_user = User::factory()->editAssets()->create();

View file

@ -0,0 +1,13 @@
<?php
namespace Tests\Support;
trait CanSkipTests
{
public function markIncompleteIfMySQL($message = 'Test skipped due to database driver being MySQL.')
{
if (config('database.default') === 'mysql') {
$this->markTestIncomplete($message);
}
}
}

View file

@ -7,6 +7,7 @@ use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use RuntimeException; use RuntimeException;
use Tests\Support\AssertsAgainstSlackNotifications; use Tests\Support\AssertsAgainstSlackNotifications;
use Tests\Support\CanSkipTests;
use Tests\Support\CustomTestMacros; use Tests\Support\CustomTestMacros;
use Tests\Support\InteractsWithAuthentication; use Tests\Support\InteractsWithAuthentication;
use Tests\Support\InitializesSettings; use Tests\Support\InitializesSettings;
@ -14,6 +15,7 @@ use Tests\Support\InitializesSettings;
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
use AssertsAgainstSlackNotifications; use AssertsAgainstSlackNotifications;
use CanSkipTests;
use CreatesApplication; use CreatesApplication;
use CustomTestMacros; use CustomTestMacros;
use InteractsWithAuthentication; use InteractsWithAuthentication;