S
S
Steve2021-08-04 11:42:17
PHPUnit
Steve, 2021-08-04 11:42:17

How do unit tests work?

How do unit tests work? (particularly php) If I cause an error in the code, the tests do not show this.
Example:
Test:

public function testFindAll(): void
    {
        self::bootKernel();
        $repository = static::$kernel->getContainer()->get(PropertyInMemoryRepository::class);

        $this->assertInstanceOf(PropertyCollection::class, $repository->findAll(1, 1, 1));

        $count = $repository->findAll(1, 1, 1)->count();

        $this->assertSame(3, $count);
    }


PropertyInMemoryRepository:
public function findAll(int $groupId, int $page, int $limit, array $filters = []): PropertyCollection
    {
        $propertyCollection = new PropertyCollection();

        foreach ($this->propertyCollection as $property) {
            if ($property->getGroupIdValue() === $groupId) {
                $propertyCollection->append($property);
            }
        }

        return $propertyCollection;
    }


The line in the controller with the triggered error :
$dProperties = $this->propertyRepository->findAll($this->getUser()->getGroupId(), 'string', $limit, $filters);


At the exit I have Job succeeded

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-08-04
@CenterJoin

The error is that you are passing a string as the second argument in the controller?
If yes, then it will catch the controller test , not the findAll method, that test will not know by any magic that you will be passing invalid arguments somewhere else.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question