diff --git a/test/Annotation/AbstractBuilderTestCase.php b/test/Annotation/AbstractBuilderTestCase.php index 136d4eaf1..f38b69c22 100644 --- a/test/Annotation/AbstractBuilderTestCase.php +++ b/test/Annotation/AbstractBuilderTestCase.php @@ -4,7 +4,6 @@ namespace LaminasTest\Form\Annotation; -use Doctrine\Common\Annotations\AnnotationException; use Generator; use Laminas\Form\Annotation; use Laminas\Form\Element; @@ -24,7 +23,10 @@ use LaminasTest\Form\TestAsset\Annotation\InputFilterInput; use PHPUnit\Framework\TestCase; +use Throwable; + use function getenv; +use function PHPUnit\Framework\assertStringMatchesFormat; abstract class AbstractBuilderTestCase extends TestCase { @@ -407,37 +409,49 @@ public function testInputFilterAnnotationAllowsComposition(): void public function testLegacyComposedObjectAnnotation(): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); - $entity = new TestAsset\Annotation\LegacyComposedObjectAnnotation(); - $builder = $this->createBuilder(); - $builder->createForm($entity); + try { + $entity = new TestAsset\Annotation\LegacyComposedObjectAnnotation(); + $builder = $this->createBuilder(); + $builder->createForm($entity); + self::fail('Neither a deprecation nor an exception were thrown'); + } catch (Throwable $error) { + self::assertMatchesRegularExpression('/Passing a single array .* is deprecated/', $error->getMessage()); + } } public function testLegacyStyleFilterAnnotations(): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); - $entity = new TestAsset\Annotation\LegacyFilterAnnotation(); - $builder = $this->createBuilder(); - $builder->createForm($entity); + try { + $entity = new TestAsset\Annotation\LegacyFilterAnnotation(); + $builder = $this->createBuilder(); + $builder->createForm($entity); + self::fail('Neither a deprecation nor an exception were thrown'); + } catch (Throwable $error) { + self::assertMatchesRegularExpression('/Passing a single array .* is deprecated/', $error->getMessage()); + } } public function testLegacyStyleHydratorAnnotations(): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); - $entity = new TestAsset\Annotation\LegacyHydratorAnnotation(); - $builder = $this->createBuilder(); - $builder->createForm($entity); + try { + $entity = new TestAsset\Annotation\LegacyHydratorAnnotation(); + $builder = $this->createBuilder(); + $builder->createForm($entity); + self::fail('Neither a deprecation nor an exception were thrown'); + } catch (Throwable $error) { + self::assertMatchesRegularExpression('/Passing a single array .* is deprecated/', $error->getMessage()); + } } public function testLegacyStyleValidatorAnnotations(): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); - $entity = new TestAsset\Annotation\LegacyValidatorAnnotation(); - $builder = $this->createBuilder(); - $builder->createForm($entity); + try { + $entity = new TestAsset\Annotation\LegacyValidatorAnnotation(); + $builder = $this->createBuilder(); + $builder->createForm($entity); + self::fail('Neither a deprecation nor an exception were thrown'); + } catch (Throwable $error) { + self::assertMatchesRegularExpression('/Passing a single array .* is deprecated/', $error->getMessage()); + } } }