From 03654c35a48016fecab38620b11852409761db3c Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Mon, 20 Jul 2026 14:36:07 +0200 Subject: [PATCH] chore: fix notices and warnings in tests --- .github/workflows/php.yml | 7 ++++++- .../bootstrap/fixtures/license-MIT-blue.svg | 2 +- .../fixtures/license-MIT-blue_plastic.svg | 19 +------------------ src/Render/LocalSvgRenderer.php | 7 +++++++ tests/Render/SvgFlatRenderTest.php | 2 +- tests/Render/SvgFlatSquareRenderTest.php | 2 +- tests/Render/SvgForTheBadgeRendererTest.php | 2 +- tests/Render/SvgPlasticRenderTest.php | 2 +- tests/Render/SvgSocialRenderTest.php | 2 +- 9 files changed, 20 insertions(+), 25 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5ddd7f20..b15d69ae 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -56,4 +56,9 @@ jobs: uses: ramsey/composer-install@v4 - name: Run tests - run: bin/phpunit --display-warnings --do-not-fail-on-warning + run: bin/phpunit --display-warnings + + - name: Run Behat + if: matrix.php-version == '8.4' + run: php -d error_reporting='E_ALL & ~E_DEPRECATED' bin/behat --snippets-for + diff --git a/features/bootstrap/fixtures/license-MIT-blue.svg b/features/bootstrap/fixtures/license-MIT-blue.svg index 39839a47..a4c497f5 100644 --- a/features/bootstrap/fixtures/license-MIT-blue.svg +++ b/features/bootstrap/fixtures/license-MIT-blue.svg @@ -1 +1 @@ -licenselicenseMITMIT \ No newline at end of file +license: MITlicenseMIT diff --git a/features/bootstrap/fixtures/license-MIT-blue_plastic.svg b/features/bootstrap/fixtures/license-MIT-blue_plastic.svg index 5d9d8563..f6d73465 100644 --- a/features/bootstrap/fixtures/license-MIT-blue_plastic.svg +++ b/features/bootstrap/fixtures/license-MIT-blue_plastic.svg @@ -1,18 +1 @@ - - - - - - - - - - - - - license - license - MIT - MIT - - \ No newline at end of file +license: MITlicenseMIT diff --git a/src/Render/LocalSvgRenderer.php b/src/Render/LocalSvgRenderer.php index a689cdde..4d0e0d03 100644 --- a/src/Render/LocalSvgRenderer.php +++ b/src/Render/LocalSvgRenderer.php @@ -101,12 +101,19 @@ private function renderSvg(string $render, array $parameters, string $style): Im $render = \preg_replace('/\s+/', ' ', $render); $render = \str_replace('> <', '><', $render); + $useInternalErrors = \libxml_use_internal_errors(true); + try { $xml = new \SimpleXMLElement($render); } catch (\Exception $e) { + \libxml_clear_errors(); + \libxml_use_internal_errors($useInternalErrors); throw new \RuntimeException('Generated string is not a valid XML: ' . $e->getMessage()); } + \libxml_clear_errors(); + \libxml_use_internal_errors($useInternalErrors); + if ('svg' !== $xml->getName()) { throw new \RuntimeException('Generated xml is not a SVG'); } diff --git a/tests/Render/SvgFlatRenderTest.php b/tests/Render/SvgFlatRenderTest.php index 90967814..48cdfd79 100644 --- a/tests/Render/SvgFlatRenderTest.php +++ b/tests/Render/SvgFlatRenderTest.php @@ -17,7 +17,7 @@ class SvgFlatRenderTest extends TestCase protected function setUp(): void { - $this->calculator = $this->createMock(TextSizeCalculatorInterface::class); + $this->calculator = $this->createStub(TextSizeCalculatorInterface::class); $this->calculator->method('calculateWidth')->willReturn(20.0); $this->render = new SvgFlatRender($this->calculator); } diff --git a/tests/Render/SvgFlatSquareRenderTest.php b/tests/Render/SvgFlatSquareRenderTest.php index 577f6b19..d106cffd 100644 --- a/tests/Render/SvgFlatSquareRenderTest.php +++ b/tests/Render/SvgFlatSquareRenderTest.php @@ -17,7 +17,7 @@ class SvgFlatSquareRenderTest extends TestCase protected function setUp(): void { - $this->calculator = $this->createMock(TextSizeCalculatorInterface::class); + $this->calculator = $this->createStub(TextSizeCalculatorInterface::class); $this->calculator->method('calculateWidth')->willReturn(20.0); $this->render = new SvgFlatSquareRender($this->calculator); } diff --git a/tests/Render/SvgForTheBadgeRendererTest.php b/tests/Render/SvgForTheBadgeRendererTest.php index 6a49ceb0..ab177170 100644 --- a/tests/Render/SvgForTheBadgeRendererTest.php +++ b/tests/Render/SvgForTheBadgeRendererTest.php @@ -17,7 +17,7 @@ class SvgForTheBadgeRendererTest extends TestCase protected function setUp(): void { - $this->calculator = $this->createMock(TextSizeCalculatorInterface::class); + $this->calculator = $this->createStub(TextSizeCalculatorInterface::class); $this->calculator->method('calculateWidth')->willReturnCallback(static function (string $text): float { $widths = [ 'VERSION' => 53.0, diff --git a/tests/Render/SvgPlasticRenderTest.php b/tests/Render/SvgPlasticRenderTest.php index 4db2c9e7..6f4ef587 100644 --- a/tests/Render/SvgPlasticRenderTest.php +++ b/tests/Render/SvgPlasticRenderTest.php @@ -17,7 +17,7 @@ class SvgPlasticRenderTest extends TestCase protected function setUp(): void { - $this->calculator = $this->createMock(TextSizeCalculatorInterface::class); + $this->calculator = $this->createStub(TextSizeCalculatorInterface::class); $this->calculator->method('calculateWidth')->willReturn(20.0); $this->render = new SvgPlasticRender($this->calculator); } diff --git a/tests/Render/SvgSocialRenderTest.php b/tests/Render/SvgSocialRenderTest.php index 05a933e7..1495f20d 100644 --- a/tests/Render/SvgSocialRenderTest.php +++ b/tests/Render/SvgSocialRenderTest.php @@ -17,7 +17,7 @@ class SvgSocialRenderTest extends TestCase protected function setUp(): void { - $this->calculator = $this->createMock(TextSizeCalculatorInterface::class); + $this->calculator = $this->createStub(TextSizeCalculatorInterface::class); $this->calculator->method('calculateWidth')->willReturnCallback(static function (string $text): float { $widths = [ 'twitter' => 46.0,