From 6cd38d219c2b15539aaf1157a47708c62aaeb187 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:06:32 +1300 Subject: [PATCH] MNT Don't expect class when its module isn't installed (#11488) --- tests/php/Forms/FormFieldTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/php/Forms/FormFieldTest.php b/tests/php/Forms/FormFieldTest.php index 0611999e6e0..647c1adcfec 100644 --- a/tests/php/Forms/FormFieldTest.php +++ b/tests/php/Forms/FormFieldTest.php @@ -2,6 +2,7 @@ namespace SilverStripe\Forms\Tests; +use Composer\InstalledVersions; use LogicException; use ReflectionClass; use SilverStripe\Core\ClassInfo; @@ -932,9 +933,6 @@ public function testFieldValidatorConfig(): void SelectionGroup_Item::class => [ CompositeFieldValidator::class, ], - SegmentField::class => [ - StringFieldValidator::class, - ], SingleLookupField::class => [], Tab::class => [ CompositeFieldValidator::class, @@ -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)) { @@ -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