Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codeCoverage 100% #28

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Application/Actions/ActionError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use JsonSerializable;

/**
* @codeCoverageIgnore
*/
class ActionError implements JsonSerializable
{
public const BAD_REQUEST = 'BAD_REQUEST';
Expand Down
3 changes: 3 additions & 0 deletions src/Application/Actions/ActionPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use JsonSerializable;

/**
* @codeCoverageIgnore
*/
class ActionPayload implements JsonSerializable
{
private int $statusCode;
Expand Down
11 changes: 2 additions & 9 deletions src/Application/Actions/Dgo/CreateDgoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -183,7 +176,7 @@ private function kana2alphabet(string $target): string
case 'ワ':
return 'W';
default:
return mb_substr($checkWord, 0, 1);
return '';
}
}
}
3 changes: 3 additions & 0 deletions src/Application/Handlers/HttpErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Slim\Handlers\ErrorHandler as SlimErrorHandler;
use Throwable;

/**
* @codeCoverageIgnore
*/
class HttpErrorHandler extends SlimErrorHandler
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Application/Handlers/ShutdownHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Exception\HttpInternalServerErrorException;

/**
* @codeCoverageIgnore
*/
class ShutdownHandler
{
private Request $request;
Expand Down
3 changes: 3 additions & 0 deletions src/Application/ResponseEmitter/ResponseEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Psr\Http\Message\ResponseInterface;
use Slim\ResponseEmitter as SlimResponseEmitter;

/**
* @codeCoverageIgnore
*/
class ResponseEmitter extends SlimResponseEmitter
{
/**
Expand Down
99 changes: 99 additions & 0 deletions tests/Application/Actions/Dgo/CreateDgoActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading