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

[BUG] Annotation with data providers #7

Closed
MGatner opened this issue Mar 31, 2021 · 4 comments
Closed

[BUG] Annotation with data providers #7

MGatner opened this issue Mar 31, 2021 · 4 comments
Labels
sort/bug Something isn't working

Comments

@MGatner
Copy link

MGatner commented Mar 31, 2021

Environment:

  • PHP version: 7.4
  • Tachycardia version: v1.1.1

Description:
When using the @timeLimit annotation on a test with a data provider the new limit is not respected.

Steps to Reproduce:
Here's my actual test case (using ControllerTester):

	/**
	 * @dataProvider indexDataProvider
	 * @timeLimit 0.75
	 */
	public function testIndexHasCorrectJobs(string $method, array $expected)
	{
		$result = $this->execute($method);
		$result->assertOK();
		$result->assertStatus(200);

		// Check that each expected Job is present and others are not
		foreach (['staff', 'client', 'completed', 'deleted'] as $type)
		{
			if (in_array($type, $expected))
			{
				// Check for the Job name linked by its ID
				$result->see(anchor('jobs/show/' . $this->$type->id, $this->$type->name));
			}
			else
			{
				$result->dontSee($this->$type->name);
			}
		}
	}

	public function indexDataProvider(): array
	{
		return [
			['staff', ['staff']],
			['active', ['staff', 'client']],
			['archive', ['completed']],
			['all', ['staff', 'client', 'completed']],
			['trash', ['deleted']],
		];
	}

No matter what I set for @timeLimit I always get a warning:

Nexus\PHPUnit\Extension\Tachycardia identified this sole slow test:
+--------------------------------------------------------------+---------------+-------------+
| Test Case                                                    | Time Consumed | Time Limit  |
+--------------------------------------------------------------+---------------+-------------+
| JobsControllerTest::testIndexHasCorrectJobs with data set #2 | 00:00:00.68   | 00:00:00.50 |
+--------------------------------------------------------------+---------------+-------------+

Notice that "Time Limit" is 0.5.

Expected Output:
Each iteration of a data-provided test should use the limit override.

@MGatner MGatner added the sort/bug Something isn't working label Mar 31, 2021
@paulbalandan
Copy link
Contributor

I have a hunch on this. I think the problem is in the getAnnotations method. I'm on mobile so probably will get back to PC by tomorrow.

Can you try this debug script?

use PHPUnit\Unit\Test as TestUtil;

$annotations = TestUtil::parseTestMethodAnnotations(JobsControllerTest::class, 'testIndexHasCorrectJobs with data set #2');

var_dump($annotations);
// this should have the timeLimit subkey for the method key

I'm suspecting TestUtil needs to parse only the test method name without the dataname.

@MGatner
Copy link
Author

MGatner commented Mar 31, 2021

┌────────────────────────────────────────────────────────────────────────────────────────┐
│ $annotations
└────────────────────────────────────────────────────────────────────────────────────────┘
array (2) [
    'method' => null
    'class' => array (1) [
        'mixin' => array (1) [
            0 => string (14) "CIUnitTestCase"
        ]
    ]
]

@paulbalandan
Copy link
Contributor

Fixed in f9750f6.

@MGatner
Copy link
Author

MGatner commented Apr 1, 2021

Confirmed, override time limit now shows:

Nexus\PHPUnit\Extension\Tachycardia identified this sole slow test:
+--------------------------------------------------------------+---------------+-------------+
| Test Case                                                    | Time Consumed | Time Limit  |
+--------------------------------------------------------------+---------------+-------------+
| JobsControllerTest::testIndexHasCorrectJobs with data set #2 | 00:00:01.06   | 00:00:00.75 |
+--------------------------------------------------------------+---------------+-------------+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sort/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants