Skip to content

Commit

Permalink
MNT Don't expect class when its module isn't installed
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Dec 2, 2024
1 parent 4161aa4 commit 6ae5e36
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tests/php/Forms/FormFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Forms\Tests;

use Composer\InstalledVersions;
use LogicException;
use ReflectionClass;
use SilverStripe\Core\ClassInfo;
Expand Down Expand Up @@ -932,9 +933,6 @@ public function testFieldValidatorConfig(): void
SelectionGroup_Item::class => [
CompositeFieldValidator::class,
],
SegmentField::class => [
StringFieldValidator::class,
],
SingleLookupField::class => [],
Tab::class => [
CompositeFieldValidator::class,
Expand Down Expand Up @@ -967,6 +965,11 @@ public function testFieldValidatorConfig(): void
StringFieldValidator::class,
],
];
if (InstalledVersions::isInstalled('silverstripe/segment-field')) {
$expectedFieldValidators[SegmentField::class] = [
StringFieldValidator::class,
];
}
$count = 0;
foreach ($this->getFormFieldClasses() as $class) {
if (!array_key_exists($class, $expectedFieldValidators)) {
Expand All @@ -983,7 +986,7 @@ public function testFieldValidatorConfig(): void
}
// Assert that we have tested all classes e.g. namespace wasn't changed, no new classes were added
// that haven't been tested
$this->assertSame(58, $count);
$this->assertSame(count($expectedFieldValidators), $count);
}

private function instantiateFormField(string $class): FormField
Expand Down

0 comments on commit 6ae5e36

Please sign in to comment.