Skip to content

Global shortcut test double #436

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

Merged
merged 1 commit into from
Dec 1, 2024
Merged

Conversation

XbNz
Copy link
Contributor

@XbNz XbNz commented Nov 29, 2024

  • GlobalShortcut::class now implements Contracts\GlobalShortcut::class interface
  • Facades\GlobalShortcut::fake() swaps implementations with a test double concrete
  • Implement new binding in NativeServiceProvider::class
  • Implement GlobalShortcutFake::class with assertion helpers
  • Test that GlobalShortcutFake::class assertions work

This one is dead simple:

final class OnWindowFocusedTest extends TestCase
{
    #[\PHPUnit\Framework\Attributes\Test]
    public function it_registers_a_hotkey_for_the_preferences_page(): void
    {
        // Arrange
        GlobalShortcut::fake();

        // Act
        $this->app->make(Dispatcher::class)->dispatch(new WindowFocused('doesnt-matter'));

        // Assert
        GlobalShortcut::assertKey('CmdOrCtrl+,');
        GlobalShortcut::assertRegisteredCount(1);
        GlobalShortcut::assertEvent(OpenPreferencesEvent::class);
    }
}

- GlobalShortcut::class now implements Contracts\GlobalShortcut::class interface
- Facades\GlobalShortcut::fake() swaps implementations with a test double concrete
- Implement new binding in NativeServiceProvider::clas
- Implement GlobalShortcutFake::class with assertion helpers
- Test that GlobalShortcutFake::class assertions work
Copy link
Member

@simonhamp simonhamp left a comment

Choose a reason for hiding this comment

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

Wonderful

@simonhamp simonhamp merged commit 7f4994d into NativePHP:main Dec 1, 2024
21 checks passed
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