diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4175fe..3cc234a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,26 @@ on: jobs: test: - uses: zenstruck/.github/.github/workflows/php-test-symfony.yml@main + name: PHP ${{ matrix.php }}, SF ${{ matrix.symfony }} - ${{ matrix.deps }} + runs-on: ubuntu-latest + strategy: + matrix: + php: [8.1, 8.2, 8.3] + deps: [highest] + symfony: [6.4.*, 7.0.*] + include: + - php: 8.1 + deps: lowest + symfony: '*' + exclude: + - php: 8.1 + symfony: 7.0.* + steps: + - uses: zenstruck/.github/actions/php-test-symfony@main + with: + php: ${{ matrix.php }} + symfony: ${{ matrix.symfony }} + deps: ${{ matrix.deps }} code-coverage: uses: zenstruck/.github/.github/workflows/php-coverage-codecov.yml@main diff --git a/.gitignore b/.gitignore index aa58d4a..e942df1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ /build/ /var/ /drivers/ +/attachment.zip /.php-cs-fixer.cache /.phpunit.result.cache diff --git a/README.md b/README.md index 9bc9a0d..cdd1b7a 100644 --- a/README.md +++ b/README.md @@ -354,7 +354,6 @@ previous request didn't perform any security-related operations. Possible soluti for all requests removing the need to ever call `->withProfiling()` but can slow down your tests. - #### HTTP Requests The _KernelBrowser_ can be used for testing API endpoints. The following http methods are available: @@ -411,7 +410,7 @@ $browser Make assertions about json responses using [JMESPath expressions](https://jmespath.org/) See the [JMESPath Tutorials](https://jmespath.org/tutorial.html) to learn more. -> **Note** +> [!NOTE] > `mtdowling/jmespath.php` is required: `composer require --dev mtdowling/jmespath.php`. ```php @@ -457,7 +456,7 @@ $json = $browser ; ``` -> **Note** +> [!NOTE] > See the [full `zenstruck/assert` expectation API documentation](https://github.com/zenstruck/assert#expectation-api) > to see all the methods available on `Zenstruck\Browser\Json`. @@ -543,6 +542,126 @@ class MyTest extends PantherTestCase } ``` +### Advanced DOM Selectors + +Any browser method that accepts a `$selector` argument can be one of the following types: + +1. `string` - [_auto selector_](#auto-string-selector) +2. `Zenstruck\Dom\Selector` - [_selector object_](#selector-object) +3. `callable` - [_callable selector_](#callable-selector) + +> [!NOTE] +> Most [`PantherBrowser`](#pantherbrowser) specific methods that accept a `$selector` +> argument only accept a string that's specific to the Panther client. + +#### Auto (`string`) Selector + +A `string` is considered an auto selector and tries to find the DOM node using the following +strategies in order (first strategy to find a node wins): + +1. **CSS**: Try to find _any node_ using `$selector` as CSS selector string. +2. **Button**: Try to find ` + + diff --git a/tests/KernelBrowserTests.php b/tests/KernelBrowserTests.php index 7a6bd4f..1a1bbef 100644 --- a/tests/KernelBrowserTests.php +++ b/tests/KernelBrowserTests.php @@ -19,6 +19,7 @@ use Zenstruck\Browser\Json; use Zenstruck\Browser\KernelBrowser; use Zenstruck\Browser\Tests\Fixture\CustomHttpOptions; +use Zenstruck\Dom; /** * @author Kevin Bond @@ -27,6 +28,26 @@ trait KernelBrowserTests { use BrowserTests; + /** + * @test + */ + public function click_with_complex_callback_filter(): void + { + $this->browser() + ->visit('/page1') + ->click(function(Dom $dom) { + return $dom + ->find('input7') + ?->ensure(Dom\Node\Form\Field::class) + ->form() + ?->siblings('#link') + ->first('a link') + ; + }) + ->assertOn('/page2') + ; + } + /** * @test */ @@ -322,10 +343,10 @@ public function can_set_default_http_options(): void $this->browser() ->setDefaultHttpOptions(['headers' => ['x-foo' => 'bar']]) ->post('/http-method') - ->assertContains('"x-foo":["Bar"]') + ->assertContains('"x-foo":["bar"]') ->post('/http-method', ['headers' => ['x-bar' => 'foo']]) - ->assertContains('"x-bar":["Foo"]') - ->assertContains('"x-foo":["Bar"]') + ->assertContains('"x-bar":["foo"]') + ->assertContains('"x-foo":["bar"]') ; }