In unit tests, and sometimes in kernel tests, you need to mock the dependencies you aren't testing, but you can over-mock and only be testing the mocks and not the code you want to test.
Here's an example (thanks, ChatGPT, for the code).
## The Class to be tested (MyClass.php)
```php
<?php
class MyClass {
public function __construct(
private DependencyInterface $dependency
) {
}
public function doSomething() {
$result = $this->dependency->performAction();
return "Result: " . $result;
}
}
```
## Dependency Interface (DependencyInterface.php)
```php
<?php
interface DependencyInterface {
public function performAction();
}
```
## A test class that ends up testing mocks (MyClassTest.php)
In this example, the test creates a mock for the `DependencyInterface` and sets up an expectation that the performAction method will be called once, returning a specific value.
The test then calls the `doSomething` method on `MyClass` and asserts that the result is as expected.
The issue with this test is that it's not testing the actual behaviour of `MyClass`.
It's only testing that the mock is configured correctly.
If the real implementation of `MyClass` has a bug, this test won't catch it.