Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non test method testimonial gets executed as test #4471

Closed
sebastiansulinski opened this issue Sep 27, 2020 · 4 comments
Closed

Non test method testimonial gets executed as test #4471

sebastiansulinski opened this issue Sep 27, 2020 · 4 comments
Assignees
Labels
feature/test-runner CLI test runner type/bug Something is broken

Comments

@sebastiansulinski
Copy link

I've just came across a problem with non test methods starting with test... - in my particular case it was a trait that generates either a single or multiple records for the Testimonial model. Here's the trait:

trait TestimonialTrait
{
    /**
     * Get Testimonial instance.
     *
     * @param  array  $props
     * @param  mixed  ...$states
     * @return \App\Models\Testimonial
     */
    protected function testimonial(array $props = [], ...$states): Testimonial
    {
        //...
    }

    /**
     * Get Testimonial collection.
     *
     * @param  int  $count
     * @param  array  $props
     * @param  mixed  ...$states
     * @return \Illuminate\Support\Collection
     */
    protected function testimonials(int $count, array $props = [], ...$states): Collection
    {
        //...
    }
}

When used with the test class I get two warnings at the end:

Test method "testimonial" in test class "Tests\Feature\Admin\Testimonial\TestimonialTest" is not public.

Test method "testimonials" in test class "Tests\Feature\Admin\Testimonial\TestimonialTest" is not public.

When changed visibility of both of the methods to public, I get:

This test did not perform any assertions

/Users/sebastian/code/valet/chichester-park-hotel/tests/Traits/TestimonialTrait.php:19

ArgumentCountError : Too few arguments to function Tests\Feature\Admin\Testimonial\TestimonialTest::testimonials(), 0 passed in /Users/sebastian/code/valet/chichester-park-hotel/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1533 and at least 1 expected
 /Users/sebastian/code/valet/chichester-park-hotel/tests/Traits/TestimonialTrait.php:32

I can obviously try to change method name, but I wonder if this has been reported before and can be fixed by detecting either camel / snake case method naming for the test prefix. If it's an overkill then not too worry, but I just thought I'll mention in case you could do a quick fix for it.

@sebastiansulinski sebastiansulinski added the type/bug Something is broken label Sep 27, 2020
@sebastianbergmann
Copy link
Owner

The documentation is clear:

The tests are public methods that are named test*
I think changing this to "name must begin with test followed by either an uppercase character or _" may be confusing and/or introduce unintended side effects.

@sebastiansulinski
Copy link
Author

You say it's clear, but it's not really because if you have a protected method starting with test* then you have the first warning I've shown in the original example so no, I don't think it's completely clear.

Screenshot 2020-09-27 at 14 25 03

@sebastianbergmann
Copy link
Owner

I don't think it's completely clear

I agree, this could be clearer.

@epdenouden
Copy link
Contributor

@sebastianbergmann the TestDox Refactoring Team does appreciate it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

3 participants