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

"PHPUnit_Framework_TestSuite_DataProvider" does not extend PHPUnit_Framework_TestCase #2859

Closed
eddmann opened this issue Nov 14, 2017 · 6 comments · Fixed by N0rthernL1ghts/eloquent-bootstrap#2 or Zemhart/project_UAS_PHP#20

Comments

@eddmann
Copy link

eddmann commented Nov 14, 2017

Q A
PHPUnit version 5.7.24
PHP version 7.1.11
Installation Method Composer

Have just noticed this exception being thrown when trying to run a test suite with a dataProvider included.

Fatal error: Uncaught PHPUnit_Framework_Exception: Class "PHPUnit_Framework_TestSuite_DataProvider" does not extend PHPUnit_Framework_TestCase.

Looking at the diff between this version and the previous it seems to be due to the caching of the declared classes. Setting the declaredClasses before attempting to load the file (similar to how it worked before) seems to solve the issue.

// TestSuite.php
$this->declaredClasses = get_declared_classes();
$filename   = PHPUnit_Util_Fileloader::checkAndLoad($filename);
$newClasses = array_diff(get_declared_classes(), $this->declaredClasses);
@sebastianbergmann
Copy link
Owner

CC @kubawerlos

@sebastianbergmann sebastianbergmann added the type/bug Something is broken label Nov 14, 2017
@sebastianbergmann
Copy link
Owner

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

@eddmann
Copy link
Author

eddmann commented Nov 14, 2017

Interestingly it only seems to occur when I include ./tests/*/ within the phpunit.xml.dist file

<testsuite name="Test Suite">
  <directory>./tests/</directory>
  <directory>./tests/*/</directory>
</testsuite>

To be honest, as providing the first directory recurses through child directories, removing the second directory definiton should not be a problem.

@moorscode
Copy link

When running coverage reports this issue occurs on our builds as well.

phpunit -c phpunit.xml --coverage-clover build/logs/clover.xml

<phpunit
	backupGlobals="false"
	backupStaticAttributes="false"
	bootstrap="tests/bootstrap.php"
	colors="true"
	convertErrorsToExceptions="true"
	convertNoticesToExceptions="true"
	convertWarningsToExceptions="true"
	processIsolation="false"
	stopOnError="false"
	stopOnFailure="false"
	stopOnIncomplete="false"
	stopOnSkipped="false"
	syntaxCheck="false"
	verbose="true"
	>
	<testsuites>
		<testsuite>
			<directory prefix="test-" suffix=".php">./tests/directory/</directory>
		</testsuite>
	</testsuites>

	<filter>
		<whitelist>
			<directory>./directory/classes</directory>
			<file>./directory/some-file.php</file>
			<file>./some-file.php</file>
		</whitelist>
	</filter>
</phpunit>

@johnbillion
Copy link
Sponsor Contributor

I'm seeing this fatal error too, and I've narrowed down the reproducible steps to the following.

  1. The issue only occurs with PHPUnit 5.7.24. PHPUnit 5.7.23 and earlier is not affected.
  2. The test suite needs to contains at least two test cases which both utilise a data provider. This is the minimum I could come up with to reproduce the fatal error:
class Test_One extends PHPUnit_Framework_TestCase {

	/**
	 * @dataProvider dataOne
	 */
	public function testOne( $data ) {
	}

	public function dataOne() {
		return array(
		);
	}

}
class Test_Two extends PHPUnit_Framework_TestCase {

	/**
	 * @dataProvider dataTwo
	 */
	public function testTwo( $data ) {
	}

	public function dataTwo() {
		return array(
		);
	}

}

johnbillion added a commit to johnbillion/query-monitor that referenced this issue Nov 14, 2017
@sebastianbergmann
Copy link
Owner

@kubawerlos I have reverted #2834 for PHPUnit 5.7 now. Will revert for PHPUnit 6.4 and PHPUnit 6.5 soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment