D
D
Denis2021-01-14 17:23:19
PHP
Denis, 2021-01-14 17:23:19

Why doesn't expectException work in functional tests?

Why doesn't expectException work in functional tests? That is, elementarily, this statement never works under any circumstances in functional tests. The unit seems to be fine. And you have to use an alternative:

$response = $this->post(route('items.use', ['id' => -1, 'count' => 0]));

$this->assertTrue($response->exception->getCode() == 0);

In the controller:

$item = Item::findOrFail($id);

And here are the statements:

$this->expectException(InvalidArgumentException::class);


Never work.

And the "exception" property has nothing to do with the statement expectException, expectExceptionCode, expectExceptionMessage, and so on. They all don't work. Yes, in principle, you can work with the exception property, but
it does not have a method that returns the exception type. It is not convenient to identify exceptions by code or error. Well, in principle, I want to figure out when and what to use and what is the difference.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-01-14
@Gromfer

In findorfail http tests, the maximum assertNotFound is checked. This is logical. Http request does not know anything about php code / Laravel and should not know. If you need to test code, then you need to write unit tests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question