diff --git a/src/Application/Actions/ActionError.php b/src/Application/Actions/ActionError.php index 3a81cc5..deeec93 100644 --- a/src/Application/Actions/ActionError.php +++ b/src/Application/Actions/ActionError.php @@ -6,6 +6,9 @@ use JsonSerializable; +/** + * @codeCoverageIgnore + */ class ActionError implements JsonSerializable { public const BAD_REQUEST = 'BAD_REQUEST'; diff --git a/src/Application/Actions/ActionPayload.php b/src/Application/Actions/ActionPayload.php index cbf5110..bde0feb 100644 --- a/src/Application/Actions/ActionPayload.php +++ b/src/Application/Actions/ActionPayload.php @@ -6,6 +6,9 @@ use JsonSerializable; +/** + * @codeCoverageIgnore + */ class ActionPayload implements JsonSerializable { private int $statusCode; diff --git a/src/Application/Actions/Dgo/CreateDgoAction.php b/src/Application/Actions/Dgo/CreateDgoAction.php index 84ffde1..9d711e8 100644 --- a/src/Application/Actions/Dgo/CreateDgoAction.php +++ b/src/Application/Actions/Dgo/CreateDgoAction.php @@ -76,15 +76,8 @@ protected function action(): Response return $this->response; } - private function kana2alphabet(string $target): string + private function kana2alphabet(string $checkWord): string { - $checkWord = null; - if (strlen($target) === 1) { - $checkWord = '$target '; - } else { - $checkWord = $target; - } - $checkWordDouble = mb_substr($checkWord, 0, 2); if (in_array($checkWordDouble, ['ジャ', 'ジュ', 'ジョ'], true)) { return 'J'; @@ -183,7 +176,7 @@ private function kana2alphabet(string $target): string case 'ワ': return 'W'; default: - return mb_substr($checkWord, 0, 1); + return ''; } } } diff --git a/src/Application/Handlers/HttpErrorHandler.php b/src/Application/Handlers/HttpErrorHandler.php index 64e02b1..d4d476c 100644 --- a/src/Application/Handlers/HttpErrorHandler.php +++ b/src/Application/Handlers/HttpErrorHandler.php @@ -17,6 +17,9 @@ use Slim\Handlers\ErrorHandler as SlimErrorHandler; use Throwable; +/** + * @codeCoverageIgnore + */ class HttpErrorHandler extends SlimErrorHandler { /** diff --git a/src/Application/Handlers/ShutdownHandler.php b/src/Application/Handlers/ShutdownHandler.php index dc54b27..52e13bb 100644 --- a/src/Application/Handlers/ShutdownHandler.php +++ b/src/Application/Handlers/ShutdownHandler.php @@ -8,6 +8,9 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Exception\HttpInternalServerErrorException; +/** + * @codeCoverageIgnore + */ class ShutdownHandler { private Request $request; diff --git a/src/Application/ResponseEmitter/ResponseEmitter.php b/src/Application/ResponseEmitter/ResponseEmitter.php index 8a27ae1..3e27f85 100644 --- a/src/Application/ResponseEmitter/ResponseEmitter.php +++ b/src/Application/ResponseEmitter/ResponseEmitter.php @@ -7,6 +7,9 @@ use Psr\Http\Message\ResponseInterface; use Slim\ResponseEmitter as SlimResponseEmitter; +/** + * @codeCoverageIgnore + */ class ResponseEmitter extends SlimResponseEmitter { /** diff --git a/tests/Application/Actions/Dgo/CreateDgoActionTest.php b/tests/Application/Actions/Dgo/CreateDgoActionTest.php index 4f0e762..bc61a85 100644 --- a/tests/Application/Actions/Dgo/CreateDgoActionTest.php +++ b/tests/Application/Actions/Dgo/CreateDgoActionTest.php @@ -22,6 +22,105 @@ public function testOkFromMecabOnly() $this->assertEquals(json_encode(['text' => 'DD']), $payload); $this->assertEquals(200, $response->getStatusCode()); + + $request = $this->createRequest('GET', '/get-dai-go') + ->withHeader('Authorization', 'Bearer test_test_test') + ->withHeader('Content-Type', 'application/json') + ->withQueryParams(['target' => '絵文字が多い']); + $response = $app->handle($request); + + $payload = (string) $response->getBody(); + + $this->assertEquals(json_encode(['text' => 'EO']), $payload); + $this->assertEquals(200, $response->getStatusCode()); + + $request = $this->createRequest('GET', '/get-dai-go') + ->withHeader('Authorization', 'Bearer test_test_test') + ->withHeader('Content-Type', 'application/json') + ->withQueryParams(['target' => '地下だと十分に涼しい']); + $response = $app->handle($request); + + $payload = (string) $response->getBody(); + + $this->assertEquals(json_encode(['text' => 'CJS']), $payload); + $this->assertEquals(200, $response->getStatusCode()); + + $request = $this->createRequest('GET', '/get-dai-go') + ->withHeader('Authorization', 'Bearer test_test_test') + ->withHeader('Content-Type', 'application/json') + ->withQueryParams(['target' => '学校の校庭で座禅']); + $response = $app->handle($request); + + $payload = (string) $response->getBody(); + + $this->assertEquals(json_encode(['text' => 'GKZ']), $payload); + $this->assertEquals(200, $response->getStatusCode()); + + $request = $this->createRequest('GET', '/get-dai-go') + ->withHeader('Authorization', 'Bearer test_test_test') + ->withHeader('Content-Type', 'application/json') + ->withQueryParams(['target' => '何か変な帽子']); + $response = $app->handle($request); + + $payload = (string) $response->getBody(); + + $this->assertEquals(json_encode(['text' => 'NHB']), $payload); + $this->assertEquals(200, $response->getStatusCode()); + + $request = $this->createRequest('GET', '/get-dai-go') + ->withHeader('Authorization', 'Bearer test_test_test') + ->withHeader('Content-Type', 'application/json') + ->withQueryParams(['target' => '事前にパジャマを着て待つ']); + $response = $app->handle($request); + + $payload = (string) $response->getBody(); + + $this->assertEquals(json_encode(['text' => 'JPKM']), $payload); + $this->assertEquals(200, $response->getStatusCode()); + + $request = $this->createRequest('GET', '/get-dai-go') + ->withHeader('Authorization', 'Bearer test_test_test') + ->withHeader('Content-Type', 'application/json') + ->withQueryParams(['target' => 'レース会場にようこそ']); + $response = $app->handle($request); + + $payload = (string) $response->getBody(); + + $this->assertEquals(json_encode(['text' => 'RKY']), $payload); + $this->assertEquals(200, $response->getStatusCode()); + + $request = $this->createRequest('GET', '/get-dai-go') + ->withHeader('Authorization', 'Bearer test_test_test') + ->withHeader('Content-Type', 'application/json') + ->withQueryParams(['target' => '綿毛であるようだ']); + $response = $app->handle($request); + + $payload = (string) $response->getBody(); + + $this->assertEquals(json_encode(['text' => 'W']), $payload); + $this->assertEquals(200, $response->getStatusCode()); + + $request = $this->createRequest('GET', '/get-dai-go') + ->withHeader('Authorization', 'Bearer test_test_test') + ->withHeader('Content-Type', 'application/json') + ->withQueryParams(['target' => 'っぽい']); + $response = $app->handle($request); + + $payload = (string) $response->getBody(); + + $this->assertEquals(json_encode(['text' => '']), $payload); + $this->assertEquals(200, $response->getStatusCode()); + + $request = $this->createRequest('GET', '/get-dai-go') + ->withHeader('Authorization', 'Bearer test_test_test') + ->withHeader('Content-Type', 'application/json') + ->withQueryParams(['target' => '新しい上着の色']); + $response = $app->handle($request); + + $payload = (string) $response->getBody(); + + $this->assertEquals(json_encode(['text' => 'AUI']), $payload); + $this->assertEquals(200, $response->getStatusCode()); } public function testOkFromMecabWithNotExistsFile()