liip / liip/LiipFunctionalTestBundle

[2.0] Allow to mock services when running command

Open
#463 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
PHP
Stars
648
Forks
179
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
I'm "mocking" some services when using the test client. It's something like that:
```
$client = $this->getClient();
$clientMock = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock();

$clientMock
->method('doThings')
->willReturn(true);

$client->getContainer()->set(Client::class, $clientMock);

```
**Describe the solution you'd like**
Instead of running the command directly, a `CommandClient` could be created (that could be like the "HttpClient", that allows to run any command and access the container before.

**Describe alternatives you've considered**
Maybe instead of having the ability to reuse the current kernel in `protected function runCommand(string $name, array $params = [], bool $reuseKernel = false)`, it could be useful to provide your own kernel (and use a kernel from `createClient` ?)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the existing runCommand method, including its reuseKernel option, and the createClient and HttpClient entry points. Compare how the test client exposes the container before execution; done means commands can run with services replaced by mocks without requiring direct kernel manipulation.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.