From 987b4860270b07cf51ef044fab8abab3d97a3cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20N=C3=BCtzel?= Date: Fri, 8 Mar 2024 14:09:52 +0100 Subject: [PATCH] Add Rector Config & Apply some rules --- composer.json | 3 +- composer.lock | 58 +++++++++++++++- rector.php | 24 +++++++ .../DeeplBatchTranslationRequestHandler.php | 6 +- .../DeeplTranslationRequestHandler.php | 6 +- tests/DeeplClientFactoryTest.php | 24 +++---- tests/DeeplClientTest.php | 31 ++++----- tests/Handler/DeeplFileRequestHandlerTest.php | 14 ++-- .../DeeplFileSubmissionRequestHandlerTest.php | 19 ++--- ...ileTranslationStatusRequestHandlerTest.php | 14 ++-- tests/Handler/DeeplRequestFactoryTest.php | 69 ++++--------------- .../DeeplTranslationRequestHandlerTest.php | 19 ++--- .../Handler/DeeplUsageRequestHandlerTest.php | 14 ++-- tests/Model/BatchTranslationConfigTest.php | 2 +- tests/Model/BatchTranslationTest.php | 5 +- tests/Model/FileSubmissionTest.php | 10 +-- tests/Model/FileTranslationConfigTest.php | 20 ++---- tests/Model/FileTranslationStatusTest.php | 22 ++---- tests/Model/FileTranslationTest.php | 5 +- tests/Model/GlossaryIdSubmissionTest.php | 5 +- tests/Model/GlossarySubmissionTest.php | 25 ++----- tests/Model/TranslationConfigTest.php | 28 ++++---- tests/Model/TranslationTest.php | 8 +-- tests/Model/UsageTest.php | 10 +-- 24 files changed, 192 insertions(+), 249 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index d664d0c..1f987f2 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "phpstan/phpstan": "^1.4", "phpstan/phpstan-mockery": "^1.0", "phpstan/phpstan-strict-rules": "^1.1", - "phpunit/phpunit": "^11" + "phpunit/phpunit": "^11", + "rector/rector": "^1.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index e029a04..de60c63 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4618001f18a1b10a68f5c850ad996bc5", + "content-hash": "fcf38b2e775f1f77c59672213abbd48f", "packages": [ { "name": "php-http/discovery", @@ -2031,6 +2031,62 @@ }, "time": "2019-03-08T08:55:37+00:00" }, + { + "name": "rector/rector", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "7596fa6da06c6a20c012efe6bb3d9188a9113b11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/7596fa6da06c6a20c012efe6bb3d9188a9113b11", + "reference": "7596fa6da06c6a20c012efe6bb3d9188a9113b11", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0", + "phpstan/phpstan": "^1.10.57" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/1.0.2" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2024-03-03T12:32:31+00:00" + }, { "name": "sebastian/cli-parser", "version": "3.0.1", diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..c326077 --- /dev/null +++ b/rector.php @@ -0,0 +1,24 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withPreparedSets(deadCode: true, codeQuality: true) + ->withRules([ + AddLiteralSeparatorToNumberRector::class, + ClosureToArrowFunctionRector::class, + AssertSameTrueFalseToAssertTrueFalseRector::class, + StaticDataProviderClassMethodRector::class, + AddVoidReturnTypeWhereNoReturnRector::class, + ]); diff --git a/src/Handler/DeeplBatchTranslationRequestHandler.php b/src/Handler/DeeplBatchTranslationRequestHandler.php index 125e9ed..0ae78ea 100644 --- a/src/Handler/DeeplBatchTranslationRequestHandler.php +++ b/src/Handler/DeeplBatchTranslationRequestHandler.php @@ -49,14 +49,14 @@ public function getBody(): StreamInterface [ 'target_lang' => $this->translation->getTargetLang(), 'tag_handling' => implode( - static::SEPARATOR, + self::SEPARATOR, $this->translation->getTagHandling() ), 'non_splitting_tags' => implode( - static::SEPARATOR, + self::SEPARATOR, $this->translation->getNonSplittingTags() ), - 'ignore_tags' => implode(static::SEPARATOR, $this->translation->getIgnoreTags()), + 'ignore_tags' => implode(self::SEPARATOR, $this->translation->getIgnoreTags()), 'split_sentences' => $this->translation->getSplitSentences(), 'preserve_formatting' => $this->translation->getPreserveFormatting(), 'glossary_id' => $this->translation->getGlossaryId(), diff --git a/src/Handler/DeeplTranslationRequestHandler.php b/src/Handler/DeeplTranslationRequestHandler.php index 78e881a..70603ca 100644 --- a/src/Handler/DeeplTranslationRequestHandler.php +++ b/src/Handler/DeeplTranslationRequestHandler.php @@ -49,14 +49,14 @@ public function getBody(): StreamInterface 'target_lang' => $this->translation->getTargetLang(), 'source_lang' => $this->translation->getSourceLang(), 'tag_handling' => implode( - static::SEPARATOR, + self::SEPARATOR, $this->translation->getTagHandling() ), 'non_splitting_tags' => implode( - static::SEPARATOR, + self::SEPARATOR, $this->translation->getNonSplittingTags() ), - 'ignore_tags' => implode(static::SEPARATOR, $this->translation->getIgnoreTags()), + 'ignore_tags' => implode(self::SEPARATOR, $this->translation->getIgnoreTags()), 'split_sentences' => $this->translation->getSplitSentences(), 'preserve_formatting' => $this->translation->getPreserveFormatting(), 'glossary_id' => $this->translation->getGlossaryId(), diff --git a/tests/DeeplClientFactoryTest.php b/tests/DeeplClientFactoryTest.php index f8d8480..e9ee0de 100644 --- a/tests/DeeplClientFactoryTest.php +++ b/tests/DeeplClientFactoryTest.php @@ -18,26 +18,20 @@ public function testCreateReturnsClientWithCustomLibraries(): void $authKey = 'some-auth-key'; - $this->assertInstanceOf( - DeeplClientInterface::class, - DeeplClientFactory::create( - $authKey, - $client, - $requestFactory, - $streamFactory - ) - ); + self::assertInstanceOf(DeeplClientInterface::class, DeeplClientFactory::create( + $authKey, + $client, + $requestFactory, + $streamFactory + )); } public function testCreateReturnsClientWithAutoDisovery(): void { $authKey = 'some-auth-key'; - $this->assertInstanceOf( - DeeplClientInterface::class, - DeeplClientFactory::create( - $authKey - ) - ); + self::assertInstanceOf(DeeplClientInterface::class, DeeplClientFactory::create( + $authKey + )); } } diff --git a/tests/DeeplClientTest.php b/tests/DeeplClientTest.php index ef4709a..60875d3 100644 --- a/tests/DeeplClientTest.php +++ b/tests/DeeplClientTest.php @@ -120,7 +120,7 @@ public function testGetUsageCanReturnUsageModel(): void ->with($request) ->willReturn($response); - $this->assertInstanceOf(UsageInterface::class, $this->subject->getUsage()); + self::assertInstanceOf(UsageInterface::class, $this->subject->getUsage()); } public function testGetTranslationCanThrowException(): void @@ -193,7 +193,7 @@ public function testGetTranslationCanReturnTranslationModel(): void ->with($request) ->willReturn($response); - $this->assertInstanceOf(TranslationInterface::class, $this->subject->getTranslation($translation)); + self::assertInstanceOf(TranslationInterface::class, $this->subject->getTranslation($translation)); } public function testTranslateCanReturnJsonEncodedObject(): void @@ -234,7 +234,7 @@ public function testTranslateCanReturnJsonEncodedObject(): void ->with($request) ->willReturn($response); - $this->assertInstanceOf(TranslationInterface::class, $this->subject->translate('some text', 'some language')); + self::assertInstanceOf(TranslationInterface::class, $this->subject->translate('some text', 'some language')); } public function testTranslateBatchPerformsBatchTranslations(): void @@ -274,10 +274,7 @@ public function testTranslateBatchPerformsBatchTranslations(): void ->with($request) ->willReturn($response); - $this->assertInstanceOf( - BatchTranslationInterface::class, - $this->subject->translateBatch(['some text'], 'some language') - ); + self::assertInstanceOf(BatchTranslationInterface::class, $this->subject->translateBatch(['some text'], 'some language')); } public function testTranslateFileCanReturnInstanceOfResponseModel(): void @@ -320,7 +317,7 @@ public function testTranslateFileCanReturnInstanceOfResponseModel(): void ->with($request) ->willReturn($response); - $this->assertInstanceOf(FileSubmissionInterface::class, $this->subject->translateFile($fileTranslation)); + self::assertInstanceOf(FileSubmissionInterface::class, $this->subject->translateFile($fileTranslation)); } public function testGetFileTranslationStatusCanReturnInstanceOfResponseModel(): void @@ -363,7 +360,7 @@ public function testGetFileTranslationStatusCanReturnInstanceOfResponseModel(): ->with($request) ->willReturn($response); - $this->assertInstanceOf(FileTranslationStatusInterface::class, $this->subject->getFileTranslationStatus($fileSubmission)); + self::assertInstanceOf(FileTranslationStatusInterface::class, $this->subject->getFileTranslationStatus($fileSubmission)); } public function testGetFileTranslationCanReturnInstanceOfResponseModel(): void @@ -402,7 +399,7 @@ public function testGetFileTranslationCanReturnInstanceOfResponseModel(): void ->with($request) ->willReturn($response); - $this->assertInstanceOf(FileTranslationInterface::class, $this->subject->getFileTranslation($fileSubmission)); + self::assertInstanceOf(FileTranslationInterface::class, $this->subject->getFileTranslation($fileSubmission)); } public static function errorStatusCodeProvider(): array @@ -487,7 +484,7 @@ public function testGetSupportedLanguagesReturnsSupportedLanguagesModel(): void ->with($request) ->willReturn($response); - $this->assertInstanceOf(SupportedLanguages::class, $this->subject->getSupportedLanguages()); + self::assertInstanceOf(SupportedLanguages::class, $this->subject->getSupportedLanguages()); } public function testGetGlossariesSupportedLanguagesPairsGetCorrectModel(): void @@ -528,7 +525,7 @@ public function testGetGlossariesSupportedLanguagesPairsGetCorrectModel(): void ->with($request) ->willReturn($response); - $this->assertInstanceOf(GlossariesSupportedLanguagesPairs::class, $this->subject->getGlossariesSupportedLanguagesPairs()); + self::assertInstanceOf(GlossariesSupportedLanguagesPairs::class, $this->subject->getGlossariesSupportedLanguagesPairs()); } public function testGetGlossariesListGetCorrectModel(): void @@ -569,7 +566,7 @@ public function testGetGlossariesListGetCorrectModel(): void ->with($request) ->willReturn($response); - $this->assertInstanceOf(Glossaries::class, $this->subject->getGlossariesList()); + self::assertInstanceOf(Glossaries::class, $this->subject->getGlossariesList()); } public function testCreateGlossaryGetCorrectModel(): void @@ -612,7 +609,7 @@ public function testCreateGlossaryGetCorrectModel(): void $submission = $this->createMock(GlossarySubmission::class); - $this->assertInstanceOf(Glossary::class, $this->subject->createGlossary($submission)); + self::assertInstanceOf(Glossary::class, $this->subject->createGlossary($submission)); } public function testRetrieveGlossaryGetCorrectModel(): void @@ -654,7 +651,7 @@ public function testRetrieveGlossaryGetCorrectModel(): void ->willReturn($response); $submission = $this->createMock(GlossaryIdSubmission::class); - $this->assertInstanceOf(Glossary::class, $this->subject->retrieveGlossary($submission)); + self::assertInstanceOf(Glossary::class, $this->subject->retrieveGlossary($submission)); } public function testDeleteGlossaryGetCorrectBoolean(): void @@ -696,7 +693,7 @@ public function testDeleteGlossaryGetCorrectBoolean(): void ->willReturn($response); $submission = $this->createMock(GlossaryIdSubmission::class); - $this->assertTrue($this->subject->deleteGlossary($submission)); + self::assertTrue($this->subject->deleteGlossary($submission)); } public function testRetrieveGlossaryEntriesGetCorrectModel(): void @@ -738,7 +735,7 @@ public function testRetrieveGlossaryEntriesGetCorrectModel(): void ->willReturn($response); $submission = $this->createMock(GlossaryIdSubmission::class); - $this->assertInstanceOf(GlossaryEntries::class, $this->subject->retrieveGlossaryEntries($submission)); + self::assertInstanceOf(GlossaryEntries::class, $this->subject->retrieveGlossaryEntries($submission)); } private function createRequestExpectations( diff --git a/tests/Handler/DeeplFileRequestHandlerTest.php b/tests/Handler/DeeplFileRequestHandlerTest.php index 94930fb..e9f4514 100644 --- a/tests/Handler/DeeplFileRequestHandlerTest.php +++ b/tests/Handler/DeeplFileRequestHandlerTest.php @@ -42,7 +42,7 @@ public function testGetPathCanReturnPath(): void $this->fileSubmission->expects($this->once()) ->method('getDocumentId') ->willReturn('documentId'); - $this->assertSame(sprintf(DeeplFileRequestHandler::API_ENDPOINT, 'documentId'), $this->subject->getPath()); + self::assertSame(sprintf(DeeplFileRequestHandler::API_ENDPOINT, 'documentId'), $this->subject->getPath()); } public function testGetBodyCanReturnFilteredArray(): void @@ -65,22 +65,16 @@ public function testGetBodyCanReturnFilteredArray(): void ) ->willReturn($stream); - $this->assertSame( - $stream, - $this->subject->getBody() - ); + self::assertSame($stream, $this->subject->getBody()); } public function testGetMethodCanReturnMethod(): void { - $this->assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod()); + self::assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod()); } public function testGetContentTypeReturnsValue(): void { - $this->assertSame( - 'application/x-www-form-urlencoded', - $this->subject->getContentType() - ); + self::assertSame('application/x-www-form-urlencoded', $this->subject->getContentType()); } } diff --git a/tests/Handler/DeeplFileSubmissionRequestHandlerTest.php b/tests/Handler/DeeplFileSubmissionRequestHandlerTest.php index deb7575..8004bfa 100644 --- a/tests/Handler/DeeplFileSubmissionRequestHandlerTest.php +++ b/tests/Handler/DeeplFileSubmissionRequestHandlerTest.php @@ -39,7 +39,7 @@ public function setUp(): void public function testGetPathCanReturnPath(): void { - $this->assertSame(DeeplFileSubmissionRequestHandler::API_ENDPOINT, $this->subject->getPath()); + self::assertSame(DeeplFileSubmissionRequestHandler::API_ENDPOINT, $this->subject->getPath()); } public function testGetBodyCanReturnFilteredArray(): void @@ -79,10 +79,7 @@ public function testGetBodyCanReturnFilteredArray(): void ->method('build') ->willReturn($stream); - $this->assertSame( - $stream, - $this->subject->getBody() - ); + self::assertSame($stream, $this->subject->getBody()); } public function testGetBodyIgnoresSourceLangIfEmpty(): void @@ -121,22 +118,16 @@ public function testGetBodyIgnoresSourceLangIfEmpty(): void ->method('build') ->willReturn($stream); - $this->assertSame( - $stream, - $this->subject->getBody() - ); + self::assertSame($stream, $this->subject->getBody()); } public function testGetMethodCanReturnMethod(): void { - $this->assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod()); + self::assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod()); } public function testGetContentTypeReturnsValue(): void { - $this->assertSame( - 'multipart/form-data;boundary="boundary"', - $this->subject->getContentType() - ); + self::assertSame('multipart/form-data;boundary="boundary"', $this->subject->getContentType()); } } diff --git a/tests/Handler/DeeplFileTranslationStatusRequestHandlerTest.php b/tests/Handler/DeeplFileTranslationStatusRequestHandlerTest.php index 9e6fb9b..0f0002b 100644 --- a/tests/Handler/DeeplFileTranslationStatusRequestHandlerTest.php +++ b/tests/Handler/DeeplFileTranslationStatusRequestHandlerTest.php @@ -42,7 +42,7 @@ public function testGetPathCanReturnPath(): void $this->fileSubmission->expects($this->once()) ->method('getDocumentId') ->willReturn('documentId'); - $this->assertSame(sprintf(DeeplFileTranslationStatusRequestHandler::API_ENDPOINT, 'documentId'), $this->subject->getPath()); + self::assertSame(sprintf(DeeplFileTranslationStatusRequestHandler::API_ENDPOINT, 'documentId'), $this->subject->getPath()); } public function testGetBodyCanReturnFilteredArray(): void @@ -65,22 +65,16 @@ public function testGetBodyCanReturnFilteredArray(): void ) ->willReturn($stream); - $this->assertSame( - $stream, - $this->subject->getBody() - ); + self::assertSame($stream, $this->subject->getBody()); } public function testGetMethodCanReturnMethod(): void { - $this->assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod()); + self::assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod()); } public function testGetContentTypeReturnsValue(): void { - $this->assertSame( - 'application/x-www-form-urlencoded', - $this->subject->getContentType() - ); + self::assertSame('application/x-www-form-urlencoded', $this->subject->getContentType()); } } diff --git a/tests/Handler/DeeplRequestFactoryTest.php b/tests/Handler/DeeplRequestFactoryTest.php index 993c8f4..95d56f4 100644 --- a/tests/Handler/DeeplRequestFactoryTest.php +++ b/tests/Handler/DeeplRequestFactoryTest.php @@ -33,131 +33,92 @@ protected function setUp(): void public function testCreateDeeplUsageRequestHandlerCanReturnInstanceOfUsageRequestHandler(): void { - $this->assertInstanceOf( - DeeplUsageRequestHandler::class, - $this->subject->createDeeplUsageRequestHandler() - ); + self::assertInstanceOf(DeeplUsageRequestHandler::class, $this->subject->createDeeplUsageRequestHandler()); } public function testCreateDeeplTranslationRequestHandler(): void { $translation = $this->createMock(TranslationConfigInterface::class); - $this->assertInstanceOf( - DeeplTranslationRequestHandler::class, - $this->subject->createDeeplTranslationRequestHandler($translation) - ); + self::assertInstanceOf(DeeplTranslationRequestHandler::class, $this->subject->createDeeplTranslationRequestHandler($translation)); } public function testCreateDeeplBatchTranslationRequestHandler(): void { $translation = $this->createMock(BatchTranslationConfigInterface::class); - $this->assertInstanceOf( - DeeplBatchTranslationRequestHandler::class, - $this->subject->createDeeplBatchTranslationRequestHandler($translation) - ); + self::assertInstanceOf(DeeplBatchTranslationRequestHandler::class, $this->subject->createDeeplBatchTranslationRequestHandler($translation)); } public function testCreateDeeplFileSubmissionRequestHandler(): void { $fileTranslation = $this->createMock(FileTranslationConfigInterface::class); - $this->assertInstanceOf( - DeeplFileSubmissionRequestHandler::class, - $this->subject->createDeeplFileSubmissionRequestHandler($fileTranslation) - ); + self::assertInstanceOf(DeeplFileSubmissionRequestHandler::class, $this->subject->createDeeplFileSubmissionRequestHandler($fileTranslation)); } public function testCreateDeeplFileTranslationStatusRequestHandler(): void { $fileSubmission = $this->createMock(FileSubmissionInterface::class); - $this->assertInstanceOf( - DeeplFileTranslationStatusRequestHandler::class, - $this->subject->createDeeplFileTranslationStatusRequestHandler($fileSubmission) - ); + self::assertInstanceOf(DeeplFileTranslationStatusRequestHandler::class, $this->subject->createDeeplFileTranslationStatusRequestHandler($fileSubmission)); } public function testCreateDeeplFileTranslationRequestHandler(): void { $fileSubmission = $this->createMock(FileSubmissionInterface::class); - $this->assertInstanceOf( - DeeplFileRequestHandler::class, - $this->subject->createDeeplFileTranslationRequestHandler($fileSubmission) - ); + self::assertInstanceOf(DeeplFileRequestHandler::class, $this->subject->createDeeplFileTranslationRequestHandler($fileSubmission)); } public function testCreateDeeplSupportedLanguageRetrievalRequestHandler(): void { - $this->assertInstanceOf( - DeeplSupportedLanguageRetrievalRequestHandler::class, - $this->subject->createDeeplSupportedLanguageRetrievalRequestHandler() - ); + self::assertInstanceOf(DeeplSupportedLanguageRetrievalRequestHandler::class, $this->subject->createDeeplSupportedLanguageRetrievalRequestHandler()); } public function testGetDeeplBaseUriCanReturnPaidBaseUri(): void { - $this->assertSame(DeeplRequestFactory::DEEPL_PAID_BASE_URI, $this->subject->getDeeplBaseUri()); + self::assertSame(DeeplRequestFactory::DEEPL_PAID_BASE_URI, $this->subject->getDeeplBaseUri()); } public function testGetDeeplFreeUriCanReturnFreeBaseUri(): void { $this->subject = new DeeplRequestFactory('something:fx', $this->streamFactory); - $this->assertSame(DeeplRequestFactory::DEEPL_FREE_BASE_URI, $this->subject->getDeeplBaseUri()); + self::assertSame(DeeplRequestFactory::DEEPL_FREE_BASE_URI, $this->subject->getDeeplBaseUri()); } public function testCreateDeeplGlossariesSupportedLanguagesPairsRetrievalRequestHandler(): void { - $this->assertInstanceOf( - DeeplGlossariesSupportedLanguagesPairsRetrievalRequestHandler::class, - $this->subject->createDeeplGlossariesSupportedLanguagesPairsRetrievalRequestHandler() - ); + self::assertInstanceOf(DeeplGlossariesSupportedLanguagesPairsRetrievalRequestHandler::class, $this->subject->createDeeplGlossariesSupportedLanguagesPairsRetrievalRequestHandler()); } public function testCreateDeeplGlossariesListRetrievalRequestHandler(): void { - $this->assertInstanceOf( - DeeplGlossariesListRetrievalRequestHandler::class, - $this->subject->createDeeplGlossariesListRetrievalRequestHandler() - ); + self::assertInstanceOf(DeeplGlossariesListRetrievalRequestHandler::class, $this->subject->createDeeplGlossariesListRetrievalRequestHandler()); } public function testCreateDeeplGlossaryCreateRequestHandler(): void { $submission = $this->createMock(GlossarySubmission::class); - $this->assertInstanceOf( - DeeplGlossaryCreateRequestHandler::class, - $this->subject->createDeeplGlossaryCreateRequestHandler($submission) - ); + self::assertInstanceOf(DeeplGlossaryCreateRequestHandler::class, $this->subject->createDeeplGlossaryCreateRequestHandler($submission)); } public function testCreateDeeplGlossaryRetrieveRequestHandler(): void { $submission = $this->createMock(GlossaryIdSubmission::class); - $this->assertInstanceOf( - DeeplGlossaryRetrieveRequestHandler::class, - $this->subject->createDeeplGlossaryRetrieveRequestHandler($submission) - ); + self::assertInstanceOf(DeeplGlossaryRetrieveRequestHandler::class, $this->subject->createDeeplGlossaryRetrieveRequestHandler($submission)); } public function testCreateDeeplGlossaryDeleteRequestHandler(): void { $submission = $this->createMock(GlossaryIdSubmission::class); - $this->assertInstanceOf( - DeeplGlossaryDeleteRequestHandler::class, - $this->subject->createDeeplGlossaryDeleteRequestHandler($submission) - ); + self::assertInstanceOf(DeeplGlossaryDeleteRequestHandler::class, $this->subject->createDeeplGlossaryDeleteRequestHandler($submission)); } public function testCreateDeeplGlossaryEntriesRetrieveRequestHandler(): void { $submission = $this->createMock(GlossaryIdSubmission::class); - $this->assertInstanceOf( - DeeplGlossaryEntriesRetrieveRequestHandler::class, - $this->subject->createDeeplGlossaryEntriesRetrieveRequestHandler($submission) - ); + self::assertInstanceOf(DeeplGlossaryEntriesRetrieveRequestHandler::class, $this->subject->createDeeplGlossaryEntriesRetrieveRequestHandler($submission)); } //TODO tests } diff --git a/tests/Handler/DeeplTranslationRequestHandlerTest.php b/tests/Handler/DeeplTranslationRequestHandlerTest.php index 162ddc6..5d4a8e2 100644 --- a/tests/Handler/DeeplTranslationRequestHandlerTest.php +++ b/tests/Handler/DeeplTranslationRequestHandlerTest.php @@ -40,7 +40,7 @@ public function setUp(): void public function testGetPathCanReturnPath(): void { - $this->assertSame(DeeplTranslationRequestHandler::API_ENDPOINT, $this->subject->getPath()); + self::assertSame(DeeplTranslationRequestHandler::API_ENDPOINT, $this->subject->getPath()); } public function testGetBodyCanReturnFilteredArray(): void @@ -68,10 +68,7 @@ public function testGetBodyCanReturnFilteredArray(): void ) ->willReturn($stream); - $this->assertSame( - $stream, - $this->subject->getBody() - ); + self::assertSame($stream, $this->subject->getBody()); } public function testGetBodyCanReturnArrayWithOptionalTags(): void @@ -129,22 +126,16 @@ public function testGetBodyCanReturnArrayWithOptionalTags(): void ) ->willReturn($stream); - $this->assertSame( - $stream, - $this->subject->getBody() - ); + self::assertSame($stream, $this->subject->getBody()); } public function testGetMethodCanReturnMethod(): void { - $this->assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod()); + self::assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod()); } public function testGetContentTypeReturnsValue(): void { - $this->assertSame( - 'application/x-www-form-urlencoded', - $this->subject->getContentType() - ); + self::assertSame('application/x-www-form-urlencoded', $this->subject->getContentType()); } } diff --git a/tests/Handler/DeeplUsageRequestHandlerTest.php b/tests/Handler/DeeplUsageRequestHandlerTest.php index 8726498..4332bee 100644 --- a/tests/Handler/DeeplUsageRequestHandlerTest.php +++ b/tests/Handler/DeeplUsageRequestHandlerTest.php @@ -31,12 +31,12 @@ public function setUp(): void public function testGetPathCanReturnApiPath(): void { - $this->assertSame(DeeplUsageRequestHandler::API_ENDPOINT, $this->subject->getPath()); + self::assertSame(DeeplUsageRequestHandler::API_ENDPOINT, $this->subject->getPath()); } public function testGetMethodCanReturnMethod(): void { - $this->assertSame(DeeplRequestHandlerInterface::METHOD_GET, $this->subject->getMethod()); + self::assertSame(DeeplRequestHandlerInterface::METHOD_GET, $this->subject->getMethod()); } public function testGetBodyCanReturnArray(): void @@ -50,17 +50,11 @@ public function testGetBodyCanReturnArray(): void ) ->willReturn($stream); - $this->assertSame( - $stream, - $this->subject->getBody() - ); + self::assertSame($stream, $this->subject->getBody()); } public function testGetContentTypeReturnsValue(): void { - $this->assertSame( - 'application/x-www-form-urlencoded', - $this->subject->getContentType() - ); + self::assertSame('application/x-www-form-urlencoded', $this->subject->getContentType()); } } diff --git a/tests/Model/BatchTranslationConfigTest.php b/tests/Model/BatchTranslationConfigTest.php index 8f3fe37..fd04e5a 100644 --- a/tests/Model/BatchTranslationConfigTest.php +++ b/tests/Model/BatchTranslationConfigTest.php @@ -78,6 +78,6 @@ public function testGetSplitSentencesCanReturnInteger(): void public function testGetGlossaryIdCanReturnInteger(): void { $this->subject->setGlossaryId('id'); - $this->assertSame('id', $this->subject->getGlossaryId()); + self::assertSame('id', $this->subject->getGlossaryId()); } } diff --git a/tests/Model/BatchTranslationTest.php b/tests/Model/BatchTranslationTest.php index 8a2be86..bfb8923 100644 --- a/tests/Model/BatchTranslationTest.php +++ b/tests/Model/BatchTranslationTest.php @@ -41,9 +41,6 @@ public function testHydrateCanHydrateUsageStdClass(): void public function testSetTranslationsCanSettArrayOfTextAndCanReturnSelf(): void { - $this->assertInstanceOf( - BatchTranslationInterface::class, - $this->subject->setTranslations(['some', 'thing']) - ); + self::assertInstanceOf(BatchTranslationInterface::class, $this->subject->setTranslations(['some', 'thing'])); } } diff --git a/tests/Model/FileSubmissionTest.php b/tests/Model/FileSubmissionTest.php index f0e6406..8aefd92 100644 --- a/tests/Model/FileSubmissionTest.php +++ b/tests/Model/FileSubmissionTest.php @@ -21,18 +21,12 @@ public function setUp(): void public function testGetDocumentIdCanReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setDocumentId($value)->getDocumentId() - ); + self::assertSame($value, $this->subject->setDocumentId($value)->getDocumentId()); } public function testGetDocumentKeyCanReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setDocumentKey($value)->getDocumentKey() - ); + self::assertSame($value, $this->subject->setDocumentKey($value)->getDocumentKey()); } } diff --git a/tests/Model/FileTranslationConfigTest.php b/tests/Model/FileTranslationConfigTest.php index 8cffafe..66f8503 100644 --- a/tests/Model/FileTranslationConfigTest.php +++ b/tests/Model/FileTranslationConfigTest.php @@ -26,33 +26,21 @@ public function setUp(): void public function testGetFileContentCanReturnString(): void { - $this->assertSame( - 'abc', - $this->subject->getFileContent() - ); + self::assertSame('abc', $this->subject->getFileContent()); } public function testGetFileNameCanReturnString(): void { - $this->assertSame( - 'abc.txt', - $this->subject->getFileName() - ); + self::assertSame('abc.txt', $this->subject->getFileName()); } public function testGetTargetLangCanReturnString(): void { - $this->assertSame( - LanguageEnum::LANGUAGE_EN, - $this->subject->getTargetLang() - ); + self::assertSame(LanguageEnum::LANGUAGE_EN, $this->subject->getTargetLang()); } public function testGetSourceLangCanReturnString(): void { - $this->assertSame( - LanguageEnum::LANGUAGE_DE, - $this->subject->getSourceLang() - ); + self::assertSame(LanguageEnum::LANGUAGE_DE, $this->subject->getSourceLang()); } } diff --git a/tests/Model/FileTranslationStatusTest.php b/tests/Model/FileTranslationStatusTest.php index e68d3a4..947235a 100644 --- a/tests/Model/FileTranslationStatusTest.php +++ b/tests/Model/FileTranslationStatusTest.php @@ -18,39 +18,27 @@ public function setUp(): void $this->subject = new FileTranslationStatus(); } - public function testGetDocumentIdCanReturnString() + public function testGetDocumentIdCanReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setDocumentId($value)->getDocumentId() - ); + self::assertSame($value, $this->subject->setDocumentId($value)->getDocumentId()); } public function testGetStatusCanReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setStatus($value)->getStatus() - ); + self::assertSame($value, $this->subject->setStatus($value)->getStatus()); } public function testGetSecondsRemainingCanReturnInteger(): void { $value = 1234; - $this->assertSame( - $value, - $this->subject->setSecondsRemaining($value)->getSecondsRemaining() - ); + self::assertSame($value, $this->subject->setSecondsRemaining($value)->getSecondsRemaining()); } public function testGetBilledCharactersCanReturnInteger(): void { $value = 1234; - $this->assertSame( - $value, - $this->subject->setBilledCharacters($value)->getBilledCharacters() - ); + self::assertSame($value, $this->subject->setBilledCharacters($value)->getBilledCharacters()); } } diff --git a/tests/Model/FileTranslationTest.php b/tests/Model/FileTranslationTest.php index 6d09ef5..65e27a5 100644 --- a/tests/Model/FileTranslationTest.php +++ b/tests/Model/FileTranslationTest.php @@ -21,9 +21,6 @@ public function setUp(): void public function testGetContentCanReturnString(): void { $this->subject->setContent('some content'); - $this->assertSame( - 'some content', - $this->subject->getContent() - ); + self::assertSame('some content', $this->subject->getContent()); } } diff --git a/tests/Model/GlossaryIdSubmissionTest.php b/tests/Model/GlossaryIdSubmissionTest.php index 75d1f6e..f46aed4 100644 --- a/tests/Model/GlossaryIdSubmissionTest.php +++ b/tests/Model/GlossaryIdSubmissionTest.php @@ -21,9 +21,6 @@ public function setUp(): void public function testGetIdReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setId($value)->getId() - ); + self::assertSame($value, $this->subject->setId($value)->getId()); } } diff --git a/tests/Model/GlossarySubmissionTest.php b/tests/Model/GlossarySubmissionTest.php index 942e2a1..b120e8a 100644 --- a/tests/Model/GlossarySubmissionTest.php +++ b/tests/Model/GlossarySubmissionTest.php @@ -21,41 +21,26 @@ public function setUp(): void public function testGetNameReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setName($value)->getName() - ); + self::assertSame($value, $this->subject->setName($value)->getName()); } public function testGetSourceLangReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setSourceLang($value)->getSourceLang() - ); + self::assertSame($value, $this->subject->setSourceLang($value)->getSourceLang()); } public function testGetTargetLangReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setTargetLang($value)->getTargetLang() - ); + self::assertSame($value, $this->subject->setTargetLang($value)->getTargetLang()); } public function testGetEntriesReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setEntries($value)->getEntries() - ); + self::assertSame($value, $this->subject->setEntries($value)->getEntries()); } public function testGetEntriesFormatReturnString(): void { $value = 'some value'; - $this->assertSame( - $value, - $this->subject->setEntriesFormat($value)->getEntriesFormat() - ); + self::assertSame($value, $this->subject->setEntriesFormat($value)->getEntriesFormat()); } } diff --git a/tests/Model/TranslationConfigTest.php b/tests/Model/TranslationConfigTest.php index a7caa33..508996f 100644 --- a/tests/Model/TranslationConfigTest.php +++ b/tests/Model/TranslationConfigTest.php @@ -25,59 +25,59 @@ public function setUp(): void public function testGetNonSplittingTagsCanReturnString(): void { $this->subject->setNonSplittingTags(['some', 'splitting', 'tags']); - $this->assertContains('some', $this->subject->getNonSplittingTags()); - $this->assertContains('splitting', $this->subject->getNonSplittingTags()); - $this->assertContains('tags', $this->subject->getNonSplittingTags()); + self::assertContains('some', $this->subject->getNonSplittingTags()); + self::assertContains('splitting', $this->subject->getNonSplittingTags()); + self::assertContains('tags', $this->subject->getNonSplittingTags()); } public function testGetIgnoreTagsCanReturnString(): void { $this->subject->setIgnoreTags(['some', 'ignore', 'tags']); - $this->assertContains('some', $this->subject->getIgnoreTags()); - $this->assertContains('ignore', $this->subject->getIgnoreTags()); - $this->assertContains('tags', $this->subject->getIgnoreTags()); + self::assertContains('some', $this->subject->getIgnoreTags()); + self::assertContains('ignore', $this->subject->getIgnoreTags()); + self::assertContains('tags', $this->subject->getIgnoreTags()); } public function testGetPreserveFormattingCanReturnInteger(): void { $this->subject->setPreserveFormatting(TextHandlingEnum::PRESERVEFORMATTING_ON); - $this->assertSame('1', $this->subject->getPreserveFormatting()); + self::assertSame('1', $this->subject->getPreserveFormatting()); } public function testGetTargetLangCanReturnString(): void { $this->subject->setTargetLang('some target lang'); - $this->assertSame('some target lang', $this->subject->getTargetLang()); + self::assertSame('some target lang', $this->subject->getTargetLang()); } public function testGetTagHandlingCanReturnString(): void { $this->subject->setTagHandling(['some', 'tags']); - $this->assertContains('some', $this->subject->getTagHandling()); - $this->assertContains('tags', $this->subject->getTagHandling()); + self::assertContains('some', $this->subject->getTagHandling()); + self::assertContains('tags', $this->subject->getTagHandling()); } public function testGetTextCanReturnString(): void { $this->subject->setText('some text to translate'); - $this->assertSame('some text to translate', $this->subject->getText()); + self::assertSame('some text to translate', $this->subject->getText()); } public function testGetSourceLangCanReturnString(): void { $this->subject->setSourceLang('some source lang'); - $this->assertSame('some source lang', $this->subject->getSourceLang()); + self::assertSame('some source lang', $this->subject->getSourceLang()); } public function testGetSplitSentencesCanReturnInteger(): void { $this->subject->setSplitSentences(TextHandlingEnum::SPLITSENTENCES_NONEWLINES); - $this->assertSame(TextHandlingEnum::SPLITSENTENCES_NONEWLINES, $this->subject->getSplitSentences()); + self::assertSame(TextHandlingEnum::SPLITSENTENCES_NONEWLINES, $this->subject->getSplitSentences()); } public function testGetGlossaryIdCanReturnInteger(): void { $this->subject->setGlossaryId('id'); - $this->assertSame('id', $this->subject->getGlossaryId()); + self::assertSame('id', $this->subject->getGlossaryId()); } } diff --git a/tests/Model/TranslationTest.php b/tests/Model/TranslationTest.php index 3ab23e1..9019864 100644 --- a/tests/Model/TranslationTest.php +++ b/tests/Model/TranslationTest.php @@ -21,13 +21,13 @@ public function setUp(): void public function testGetDetectedSourceLanguageCanReturnString(): void { $this->subject->setDetectedSourceLanguage('DE'); - $this->assertSame('DE', $this->subject->getDetectedSourceLanguage()); + self::assertSame('DE', $this->subject->getDetectedSourceLanguage()); } public function testGetTextCanReturnString(): void { $this->subject->setText('some text'); - $this->assertSame('some text', $this->subject->getText()); + self::assertSame('some text', $this->subject->getText()); } public function testHydrateCanHydrateUsageStdClass(): void @@ -35,7 +35,7 @@ public function testHydrateCanHydrateUsageStdClass(): void $demo_response = json_decode('{ "translations": [ { "detected_source_language": "DE", "text": "Hello World!" } ] }'); $this->subject->hydrate($demo_response); - $this->assertEquals('DE', $this->subject->getDetectedSourceLanguage()); - $this->assertEquals('Hello World!', $this->subject->getText()); + self::assertEquals('DE', $this->subject->getDetectedSourceLanguage()); + self::assertEquals('Hello World!', $this->subject->getText()); } } diff --git a/tests/Model/UsageTest.php b/tests/Model/UsageTest.php index 4b643d7..c848378 100644 --- a/tests/Model/UsageTest.php +++ b/tests/Model/UsageTest.php @@ -21,13 +21,13 @@ public function setUp(): void public function testGetCharacterCountCanReturnInt(): void { $this->subject->setCharacterCount(10); - $this->assertSame(10, $this->subject->getCharacterCount()); + self::assertSame(10, $this->subject->getCharacterCount()); } public function testGetCharacterLimitCanReturnInt(): void { - $this->subject->setCharacterLimit(123456789); - $this->assertSame(123456789, $this->subject->getCharacterLimit()); + $this->subject->setCharacterLimit(123_456_789); + self::assertSame(123_456_789, $this->subject->getCharacterLimit()); } public function testHydrateCanHydrateUsageStdClass(): void @@ -35,7 +35,7 @@ public function testHydrateCanHydrateUsageStdClass(): void $demo_response = json_decode('{ "character_count": 180118, "character_limit": 1250000, "some_other": 123 }'); $this->subject->hydrate($demo_response); - $this->assertEquals(180118, $this->subject->getCharacterCount()); - $this->assertEquals(1250000, $this->subject->getCharacterLimit()); + self::assertEquals(180118, $this->subject->getCharacterCount()); + self::assertEquals(1_250_000, $this->subject->getCharacterLimit()); } }