core icon indicating copy to clipboard operation
core copied to clipboard

tests: Change visibility from private to protected

Open thecaliskan opened this issue 1 year ago • 2 comments

Q A
Branch? 3.2
Tickets -
License MIT
Doc PR -

When an abstract class is used for tests or a custom assertion method is written (like assertJsonContains, assertJsonEquals, assertMatchesJsonSchema etc.), I updated the visibility from private to protected to able access the response.

thecaliskan avatar Jan 30 '24 16:01 thecaliskan

Did you have the opportunity to review @soyuka ?

thecaliskan avatar Feb 02 '24 14:02 thecaliskan

Did you have the opportunity to review @dunglas ?

thecaliskan avatar Feb 12 '24 11:02 thecaliskan

Hi @soyuka

What is your opinion about MR?

thecaliskan avatar Mar 21 '24 08:03 thecaliskan

What's the benefit of doing this? As these methods are defined in a trait, you can already change their visibility when importing them if necessary.

dunglas avatar Mar 21 '24 08:03 dunglas

For example, I will add a new test method like 'assertJsonContains'. When I want to use it this way, I cannot use it in the class I inherited. Because the visibility of the 'self::getHttpResponse()' method is private.

thecaliskan avatar Mar 21 '24 09:03 thecaliskan

I enjoy using API Platform testing methods in more than one project, but I don't like doing a hack like this for all of them.

thecaliskan avatar Mar 21 '24 09:03 thecaliskan

Please use:

class MyApiTestCase extends ApiTestCase {
    use ApiTestAssertionsTrait { getHttpResponse as protected; }
}

soyuka avatar Mar 21 '24 12:03 soyuka