From 8f1a5e15e4b2ca3073956fb733d3b2ed61a2c17b Mon Sep 17 00:00:00 2001 From: Giorgio Sironi Date: Thu, 12 Dec 2024 10:17:03 +0000 Subject: [PATCH] Allow code to handle a case allowed by the schema https://github.com/elifesciences/issues/issues/9034 --- src/ViewModel/Converter/TeaserTermsBuilder.php | 6 +++++- test/ViewModel/Converter/TeaserTermsBuilderTest.php | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ViewModel/Converter/TeaserTermsBuilder.php b/src/ViewModel/Converter/TeaserTermsBuilder.php index 8e223d86..a82dfdfa 100644 --- a/src/ViewModel/Converter/TeaserTermsBuilder.php +++ b/src/ViewModel/Converter/TeaserTermsBuilder.php @@ -12,7 +12,11 @@ public function build(ElifeAssessment $elifeAssessment) { $significance = $this->buildTerms($elifeAssessment->getSignificance()); $strength = $this->buildTerms($elifeAssessment->getStrength()); - return new TeaserTerms(array_merge($significance, $strength)); + $arrayOfTerms = array_merge($significance, $strength); + if (count($arrayOfTerms) === 0) { + return null; + } + return new TeaserTerms($arrayOfTerms); } private function buildTerms($terms) diff --git a/test/ViewModel/Converter/TeaserTermsBuilderTest.php b/test/ViewModel/Converter/TeaserTermsBuilderTest.php index 3fd01700..3eca8ccb 100644 --- a/test/ViewModel/Converter/TeaserTermsBuilderTest.php +++ b/test/ViewModel/Converter/TeaserTermsBuilderTest.php @@ -35,7 +35,6 @@ final public function it_does_not_build_significance_terms_when_none_are_availab $builder = new TeaserTermsBuilder(); $elifeAssessment = new ElifeAssessment([], null); - $this->markTestSkipped('tries to build a TeaserTerms object that is empty, which is invalid'); $result = $builder->build($elifeAssessment); $this->assertNull($result);