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

[TwigComponent] Provide class/trait for testing component #818

Closed
ker0x opened this issue Apr 25, 2023 · 2 comments · Fixed by #821
Closed

[TwigComponent] Provide class/trait for testing component #818

ker0x opened this issue Apr 25, 2023 · 2 comments · Fixed by #821

Comments

@ker0x
Copy link
Contributor

ker0x commented Apr 25, 2023

It would be great to provide a ComponentTestCase class or ComponentAssertionTrait trait to help testing component.

I was thinking of something similar to MailerAssertionsTrait so we can:

  • get an instance of the component from its name and parameters
  • assert that the output of the component is similar to an expected value
  • etc ...
@ker0x ker0x changed the title [Twig Component] Provide class/trait for testing component [TwigComponent] Provide class/trait for testing component Apr 25, 2023
@weaverryan
Copy link
Member

@kbond may have some ideas on this -it’s definitely missing

@kbond
Copy link
Member

kbond commented Apr 28, 2023

Yep, for twig components, this would be pretty straight forward.

I'm working on a new selector api for zenstruck/browser. Included in this PR is a proposed new package: zenstruck/dom, that extracts the selector system to be used with any html string. The following could be possible:

class MyComponentTest extends KernelTestCase
{
    use InteractsWithTwigComponents;

    public function test_render(): void
    {
        // simple
        $this->assertStringContainsString('some text', $this->renderComponent(MyComponent::class, ['some' => 'attributes']));

        // with zenstruck/dom
        $this->renderComponent(MyComponent::class, ['some' => 'attributes'])
            ->contains('some text')
            ->containsIn('h1', 'my title')
            ->fieldEquals('input', 'some value')
            ->containsIn(Selector::xpath('...'), 'something')
            // ...
        ;
    }
}

This was referenced Apr 28, 2023
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 a pull request may close this issue.

3 participants