Skip to content

Conversation

@XbNz
Copy link
Contributor

@XbNz XbNz commented Nov 22, 2024

  • ChildProcess::class now implements Contracts\ChildProcess::class interface
  • Facades\ChildProcess::fake() swaps implementations with a test double concrete
  • Implement new binding in NativeServiceProvider::class
  • Implement Contracts/ChildProcess::class methods, mimicking that of the implementation
  • Implement ChildProcessFake::class with assertion helpers
  • Test that ChildProcessFake::class assertions work

Working example of test flow:

#[\PHPUnit\Framework\Attributes\Test]
public function submitting_form_results_in_icmp_ping_action_being_hit_with_requested_ip_address(): void
{
    // Arrange
    ChildProcess::fake();

    // Act
    $response = Livewire::test(Ping::class)
        ->set('target', '1.1.1.1')
        ->set('interval', 1000)
        ->call('ping');

    // Assert
    $this->assertDatabaseHas(IpAddress::class, [
        'ip' => '1.1.1.1',
    ]);

    ChildProcess::assertGet('ping-worker');
    ChildProcess::assertMessage(fn (string $message, string|null $alias) => $message === 'target-add:1.1.1.1::1000' && $alias === null);
}

- ChildProcess::class now implements Contracts\ChildProcess::class interface
- Facades\ChildProcess::fake() swaps implementations with a test double concrete
- Implement new binding in NativeServiceProvider::class
- Implement Contracts/ChildProcess::class methods, mimicing that of the implementation
- Implement ChildProcessFake::class with assertion helpers
- Test that ChildProcessFake::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.

Incredible stuff! Thank you

@simonhamp simonhamp merged commit ff9283e into NativePHP:main Nov 22, 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