From f18419fde3009d6a882286f36085afcf3722fc57 Mon Sep 17 00:00:00 2001 From: Damien Lagae Date: Sat, 27 Jan 2024 20:03:27 +0100 Subject: [PATCH 1/2] :bug: Allow sf7 and fix tests --- composer.json | 4 ++-- tests/Unit/FileStorageTest.php | 12 ++++++------ tests/Unit/XliffConverterTest.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index dd3160d..0a5718c 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,11 @@ "require": { "php": "^7.2 || ^8.0", "php-translation/common": "^3.0", - "symfony/translation": "^3.4 || ^4.2 || ^5.0 || ^6.0" + "symfony/translation": "^3.4 || ^4.2 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { "phpunit/phpunit": ">=8.5.20", - "symfony/framework-bundle": " ^3.4 || ^4.2 || ^5.0 || ^6.0" + "symfony/framework-bundle": " ^3.4 || ^4.2 || ^5.0 || ^6.0 || ^7.0" }, "autoload": { "psr-4": { diff --git a/tests/Unit/FileStorageTest.php b/tests/Unit/FileStorageTest.php index 4a9639c..b68acc8 100644 --- a/tests/Unit/FileStorageTest.php +++ b/tests/Unit/FileStorageTest.php @@ -41,7 +41,7 @@ public function testConstructorEmptyArray() public function testCreateNewCatalogue() { $writer = $this->getMockBuilder(TranslationWriter::class) - ->setMethods([$this->getMethodNameToWriteTranslations()]) + ->onlyMethods([$this->getMethodNameToWriteTranslations()]) ->disableOriginalConstructor() ->getMock(); $writer->expects($this->once()) @@ -56,7 +56,7 @@ public function testCreateNewCatalogue() $storage->create(new Message('key', 'domain', 'en', 'Message')); $writer = $this->getMockBuilder(TranslationWriter::class) - ->setMethods([$this->getMethodNameToWriteTranslations()]) + ->onlyMethods([$this->getMethodNameToWriteTranslations()]) ->disableOriginalConstructor() ->getMock(); $writer->expects($this->once()) @@ -74,7 +74,7 @@ public function testCreateNewCatalogue() public function testCreateExistingCatalogue() { $writer = $this->getMockBuilder(TranslationWriter::class) - ->setMethods([$this->getMethodNameToWriteTranslations()]) + ->onlyMethods([$this->getMethodNameToWriteTranslations()]) ->disableOriginalConstructor() ->getMock(); $writer->expects($this->once()) @@ -117,7 +117,7 @@ public function testGet() public function testUpdate() { $writer = $this->getMockBuilder(TranslationWriter::class) - ->setMethods([$this->getMethodNameToWriteTranslations()]) + ->onlyMethods([$this->getMethodNameToWriteTranslations()]) ->disableOriginalConstructor() ->getMock(); $writer->expects($this->exactly(2)) @@ -139,7 +139,7 @@ public function testUpdate() public function testDelete() { $writer = $this->getMockBuilder(TranslationWriter::class) - ->setMethods([$this->getMethodNameToWriteTranslations()]) + ->onlyMethods([$this->getMethodNameToWriteTranslations()]) ->disableOriginalConstructor() ->getMock(); @@ -163,7 +163,7 @@ public function testDelete() public function testImport() { $writer = $this->getMockBuilder(TranslationWriter::class) - ->setMethods([$this->getMethodNameToWriteTranslations()]) + ->onlyMethods([$this->getMethodNameToWriteTranslations()]) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Unit/XliffConverterTest.php b/tests/Unit/XliffConverterTest.php index 31d6d7f..c7ffb66 100644 --- a/tests/Unit/XliffConverterTest.php +++ b/tests/Unit/XliffConverterTest.php @@ -36,6 +36,6 @@ public function testCatalogueToContent() $catalogue->add(['foobar' => 'bar']); $content = XliffConverter::catalogueToContent($catalogue, 'messages'); - $this->assertRegExp('|foobar|', $content); + $this->assertMatchesRegularExpression('/foobar/', $content); } } From cc80d278a6dae5648a602590d8add4df7d2a072c Mon Sep 17 00:00:00 2001 From: Damien Lagae Date: Sat, 27 Jan 2024 20:08:08 +0100 Subject: [PATCH 2/2] :bug: Fix test --- tests/Unit/XliffConverterTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Unit/XliffConverterTest.php b/tests/Unit/XliffConverterTest.php index c7ffb66..b43d84b 100644 --- a/tests/Unit/XliffConverterTest.php +++ b/tests/Unit/XliffConverterTest.php @@ -36,6 +36,11 @@ public function testCatalogueToContent() $catalogue->add(['foobar' => 'bar']); $content = XliffConverter::catalogueToContent($catalogue, 'messages'); - $this->assertMatchesRegularExpression('/foobar/', $content); + // If PHPUnit 9.0 or higher is used, use assertMatchesRegularExpression() instead + if (method_exists($this, 'assertMatchesRegularExpression')) { + $this->assertMatchesRegularExpression('/foobar/', $content); + } else { + $this->assertRegExp('|foobar|', $content); + } } }