Skip to content

Commit 7a206f1

Browse files
committed
Revert "fix: preserve injected container on reset"
This reverts commit 2cdfc73.
1 parent 2cdfc73 commit 7a206f1

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

src/CLI/CLI.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class CLI
3333
*/
3434
protected Container $container;
3535

36-
protected ?Container $parentContainer = null;
37-
3836
/**
3937
* Args
4038
*
@@ -100,8 +98,7 @@ public function __construct(?Adapter $adapter = null, array $args = [], ?Contain
10098
@\cli_set_process_title($this->command);
10199

102100
$this->adapter = $adapter ?? new Generic();
103-
$this->parentContainer = $container;
104-
$this->container = new Container($container);
101+
$this->container = $container ?? new Container();
105102
}
106103

107104
/**
@@ -412,15 +409,14 @@ protected function validate(string $key, array $param, $value): void
412409

413410
public function setContainer(Container $container): self
414411
{
415-
$this->parentContainer = $container;
416-
$this->container = new Container($container);
412+
$this->container = $container;
417413

418414
return $this;
419415
}
420416

421417
public function reset(): void
422418
{
423-
$this->container = new Container($this->parentContainer);
419+
$this->container = new Container();
424420
}
425421

426422
private function camelCaseIt($key): string

tests/CLI/CLITest.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ public function testProvidedContainer()
211211

212212
$cli = new CLI(new Generic(), ['test.php', 'build'], $container);
213213

214-
$this->assertNotSame($container, $cli->getContainer());
215-
$this->assertEquals('test-value', $cli->getResource('test'));
214+
$this->assertSame($container, $cli->getContainer());
216215

217216
$cli->task('build')
218217
->inject('test')
@@ -227,25 +226,6 @@ public function testProvidedContainer()
227226
$this->assertEquals('test-value', $result);
228227
}
229228

230-
public function testResetPreservesInjectedContainer()
231-
{
232-
$container = new Container();
233-
$container->set('base', fn () => 'base-value');
234-
235-
$cli = new CLI(new Generic(), ['test.php', 'build'], $container);
236-
$cli->setResource('runtime', fn () => 'runtime-value');
237-
238-
$this->assertEquals('base-value', $cli->getResource('base'));
239-
$this->assertEquals('runtime-value', $cli->getResource('runtime'));
240-
241-
$cli->reset();
242-
243-
$this->assertEquals('base-value', $cli->getResource('base'));
244-
245-
$this->expectException(\Exception::class);
246-
$cli->getResource('runtime');
247-
}
248-
249229
public function testMatch()
250230
{
251231
$cli = new CLI(new Generic(), ['test.php', 'build2', '--email=me@example.com', '--list=item1', '--list=item2']); // Mock command request

0 commit comments

Comments
 (0)