Skip to content

Feature: Add Tests for Extract Action#178

Merged
128na merged 8 commits into
masterfrom
feature/test-extract
Jun 2, 2026
Merged

Feature: Add Tests for Extract Action#178
128na merged 8 commits into
masterfrom
feature/test-extract

Conversation

@128na
Copy link
Copy Markdown
Owner

@128na 128na commented Jun 2, 2026

ExtractActionおよび関連する各サイト(Japan, Portal, Twitrans)のExtractContents、ExtractLastModified処理に対するテストを追加しました。

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive feature tests for the extraction actions across different sites (Japan, Portal, and Twitrans), verifying content extraction, last modified date parsing, and handler invocation. The review feedback suggests refactoring ExtractActionTest.php to use Mockery instead of manual anonymous classes and state objects, which would make the tests more concise and idiomatic.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +17 to +63
public function test_invokes_handlers_for_all_sites_when_null_provided(): void
{
$state = (object) ['japan' => false, 'portal' => false, 'twitrans' => false];

$this->app->bind(Handler::class, function () use ($state) {
return new class($state) implements HandlerInterface
{
public function __construct(private object $state) {}

public function __invoke(LoggerInterface $logger): void
{
$this->state->japan = true;
}
};
});

$this->app->bind(\App\Actions\Extract\Portal\Handler::class, function () use ($state) {
return new class($state) implements HandlerInterface
{
public function __construct(private object $state) {}

public function __invoke(LoggerInterface $logger): void
{
$this->state->portal = true;
}
};
});

$this->app->bind(\App\Actions\Extract\Twitrans\Handler::class, function () use ($state) {
return new class($state) implements HandlerInterface
{
public function __construct(private object $state) {}

public function __invoke(LoggerInterface $logger): void
{
$this->state->twitrans = true;
}
};
});

$action = app(ExtractAction::class);
$action(null, new NullLogger);

$this->assertTrue($state->japan);
$this->assertTrue($state->portal);
$this->assertTrue($state->twitrans);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

ハンドラーが呼び出されたことを検証するために、冗長な匿名クラスや手動の $state オブジェクトを使用する代わりに、Mockery を使用してハンドラークラスをモック化し、期待値(once())を設定することをお勧めします。これにより、テストがより簡潔で読みやすく、かつ慣用的(idiomatic)になります。

    public function test_invokes_handlers_for_all_sites_when_null_provided(): void
    {
        $japanHandler = \Mockery::mock(Handler::class);
        $japanHandler->shouldReceive('__invoke')->once();
        $this->app->instance(Handler::class, $japanHandler);

        $portalHandler = \Mockery::mock(\App\Actions\Extract\Portal\Handler::class);
        $portalHandler->shouldReceive('__invoke')->once();
        $this->app->instance(\App\Actions\Extract\Portal\Handler::class, $portalHandler);

        $twitransHandler = \Mockery::mock(\App\Actions\Extract\Twitrans\Handler::class);
        $twitransHandler->shouldReceive('__invoke')->once();
        $this->app->instance(\App\Actions\Extract\Twitrans\Handler::class, $twitransHandler);

        $action = app(ExtractAction::class);
        $action(null, new NullLogger);
    }

Comment on lines +65 to +111
public function test_invokes_specific_handler_when_site_provided(): void
{
$state = (object) ['japan' => false, 'portal' => false, 'twitrans' => false];

$this->app->bind(Handler::class, function () use ($state) {
return new class($state) implements HandlerInterface
{
public function __construct(private object $state) {}

public function __invoke(LoggerInterface $logger): void
{
$this->state->japan = true;
}
};
});

$this->app->bind(\App\Actions\Extract\Portal\Handler::class, function () use ($state) {
return new class($state) implements HandlerInterface
{
public function __construct(private object $state) {}

public function __invoke(LoggerInterface $logger): void
{
$this->state->portal = true;
}
};
});

$this->app->bind(\App\Actions\Extract\Twitrans\Handler::class, function () use ($state) {
return new class($state) implements HandlerInterface
{
public function __construct(private object $state) {}

public function __invoke(LoggerInterface $logger): void
{
$this->state->twitrans = true;
}
};
});

$action = app(ExtractAction::class);
$action(SiteName::Japan, new NullLogger);

$this->assertTrue($state->japan);
$this->assertFalse($state->portal);
$this->assertFalse($state->twitrans);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

同様に、Mockery を使用して特定のハンドラーのみが呼び出され(once())、他のハンドラーは呼び出されないこと(never())を検証できます。これにより、テストコードが大幅にシンプルになります。

    public function test_invokes_specific_handler_when_site_provided(): void
    {
        $japanHandler = \Mockery::mock(Handler::class);
        $japanHandler->shouldReceive('__invoke')->once();
        $this->app->instance(Handler::class, $japanHandler);

        $portalHandler = \Mockery::mock(\App\Actions\Extract\Portal\Handler::class);
        $portalHandler->shouldReceive('__invoke')->never();
        $this->app->instance(\App\Actions\Extract\Portal\Handler::class, $portalHandler);

        $twitransHandler = \Mockery::mock(\App\Actions\Extract\Twitrans\Handler::class);
        $twitransHandler->shouldReceive('__invoke')->never();
        $this->app->instance(\App\Actions\Extract\Twitrans\Handler::class, $twitransHandler);

        $action = app(ExtractAction::class);
        $action(SiteName::Japan, new NullLogger);
    }

@128na
Copy link
Copy Markdown
Owner Author

128na commented Jun 2, 2026

ご指摘ありがとうございます!ご提案の通り、ExtractActionTest.php を Mockery を利用してリファクタリングし、匿名クラスと状態オブジェクトを削除してシンプルにしました。修正をPushしました。

@128na 128na merged commit ce4536e into master Jun 2, 2026
5 checks passed
@128na 128na deleted the feature/test-extract branch June 2, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants