Skip to content

Commit 785ca48

Browse files
committed
[minor] bump zenstruck/callback min version requirement
1 parent b3950b6 commit 785ca48

File tree

7 files changed

+55
-14
lines changed

7 files changed

+55
-14
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"symfony/browser-kit": "^4.4.9|^5.0.9",
1919
"symfony/framework-bundle": "^4.4|^5.0",
2020
"symfony/polyfill-php80": "^1.20",
21-
"zenstruck/callback": "^1.0"
21+
"zenstruck/callback": "^1.1"
2222
},
2323
"require-dev": {
2424
"dbrekelmans/bdi": "^0.3.0",

src/Browser.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Zenstruck\Browser\Component;
1515
use Zenstruck\Browser\Response;
1616
use Zenstruck\Browser\Test\Constraint\UrlMatches;
17+
use Zenstruck\Callback\Parameter;
1718

1819
/**
1920
* @author Kevin Bond <[email protected]>
@@ -132,12 +133,13 @@ final public function assertNotContains(string $expected): self
132133
*/
133134
final public function use(callable $callback): self
134135
{
135-
Callback::createFor($callback)
136-
->replaceUntypedArgument($this)
137-
->replaceTypedArgument(self::class, $this)
138-
->replaceTypedArgument(Component::class, fn(string $class) => new $class($this))
139-
->execute()
140-
;
136+
Callback::createFor($callback)->invokeAll(
137+
Parameter::union(
138+
Parameter::untyped($this),
139+
Parameter::typed(self::class, $this),
140+
Parameter::typed(Component::class, Parameter::factory(fn(string $class) => new $class($this)))
141+
)
142+
);
141143

142144
return $this;
143145
}

src/Browser/Component/Mailer.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Zenstruck\Browser\Component;
1111
use Zenstruck\Browser\Component\Mailer\TestEmail;
1212
use Zenstruck\Callback;
13+
use Zenstruck\Callback\Parameter;
1314

1415
/**
1516
* @author Kevin Bond <[email protected]>
@@ -54,11 +55,9 @@ public function assertEmailSentTo(string $expectedTo, $callback): self
5455

5556
if (\in_array($expectedTo, $toAddresses, true)) {
5657
// address matches
57-
Callback::createFor($callback)
58-
->minArguments(1)
59-
->replaceTypedArgument(TestEmail::class, fn(string $class) => new $class($message))
60-
->execute()
61-
;
58+
Callback::createFor($callback)->invoke(
59+
Parameter::typed(TestEmail::class, Parameter::factory(fn(string $class) => new $class($message)))
60+
);
6261

6362
return $this;
6463
}

tests/BrowserTests.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Zenstruck\Browser\Test\HasBrowser;
99
use Zenstruck\Browser\Tests\Fixture\TestComponent1;
1010
use Zenstruck\Browser\Tests\Fixture\TestComponent2;
11+
use Zenstruck\Callback\Exception\UnresolveableArgument;
1112

1213
/**
1314
* @author Kevin Bond <[email protected]>
@@ -146,9 +147,9 @@ public function with_can_accept_multiple_browsers_and_components(): void
146147
/**
147148
* @test
148149
*/
149-
public function invalid_with_callback_parameter_throws_type_error(): void
150+
public function invalid_use_callback_parameter_throws_type_error(): void
150151
{
151-
$this->expectException(\TypeError::class);
152+
$this->expectException(UnresolveableArgument::class);
152153

153154
$this->browser()->use(function(string $invalidType) {});
154155
}

tests/HttpBrowserTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ final class HttpBrowserTest extends PantherTestCase
1212
{
1313
use BrowserKitBrowserTests;
1414

15+
/**
16+
* @test
17+
*/
18+
public function can_use_http_browser_as_typehint(): void
19+
{
20+
$this->browser()
21+
->use(function(HttpBrowser $browser) {
22+
$browser->visit('/redirect1');
23+
})
24+
->assertOn('/page1')
25+
;
26+
}
27+
1528
protected function browser(): HttpBrowser
1629
{
1730
return $this->httpBrowser();

tests/KernelBrowserTests.php

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ trait KernelBrowserTests
1313
{
1414
use BrowserKitBrowserTests;
1515

16+
/**
17+
* @test
18+
*/
19+
public function can_use_kernel_browser_as_typehint(): void
20+
{
21+
$this->browser()
22+
->use(function(KernelBrowser $browser) {
23+
$browser->visit('/redirect1');
24+
})
25+
->assertOn('/page1')
26+
;
27+
}
28+
1629
/**
1730
* @test
1831
*/

tests/PantherBrowserTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ final class PantherBrowserTest extends PantherTestCase
1515
{
1616
use BrowserTests;
1717

18+
/**
19+
* @test
20+
*/
21+
public function can_use_panther_browser_as_typehint(): void
22+
{
23+
$this->browser()
24+
->use(function(PantherBrowser $browser) {
25+
$browser->visit('/page1');
26+
})
27+
->assertOn('/page1')
28+
;
29+
}
30+
1831
/**
1932
* @test
2033
*/

0 commit comments

Comments
 (0)