Skip to content

Commit 4072eaf

Browse files
usoxadhocore
authored andcommitted
fix: correct io() fallback mechanism
If no Interactor has been provided in the first place, `io()` has a fallback in which it creates a new Interactor instance from scratch. Since the addition of php8 types in c94535f, this fails because of a missing default value for the io-property. This adds a default `null` value to the property to make the property check in `io()` work again.
1 parent 290fd40 commit 4072eaf

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Application.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class Application
4040

4141
protected string $default = '__default__';
4242

43-
/** @var Interactor */
44-
protected Interactor $io;
43+
/** @var null|Interactor */
44+
protected ?Interactor $io = null;
4545

4646
/** @var callable The callable to perform exit */
4747
protected $onExit;

tests/ApplicationTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ public function test_cmd_not_found()
251251
$this->assertStringContainsString('Did you mean cmd?', $o);
252252
}
253253

254+
public function test_io_returns_new_instance_if_not_provided(): void
255+
{
256+
$app = new Application('some-name', '0.0.1', fn () => false);
257+
258+
$this->assertInstanceOf(
259+
Interactor::class,
260+
$app->io()
261+
);
262+
}
263+
254264
protected function newApp(string $name, string $version = '')
255265
{
256266
$app = new Application($name, $version ?: '0.0.1', function () {

0 commit comments

Comments
 (0)