-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Tests Missed in Execution When Another Test Extends From It #529
Comments
This will also happen if a 'BarTest' simply references a 'FooTest'. So say that I give 'FooTest' a bunch of static methods, and then reference them as dataProvider-s in 'BarTest', same affect. |
This is only reproducible when using autoloading or requires for the phpunit test classes. It took me a while to figure that out as the idea seems kind of strange to me to autoload files that phpunit already includes. So the things that work: Using: BarTest.php <?php
class BarTest extends FooTest {
public function testBar() {
echo "bar";
$this->assertTrue(true);
}
} FooTest.php <?php
class FooTest extends PHPUnit_Framework_TestCase {
public function testFoo() {
echo "foo";
$this->assertTrue(true);
}
} produces:
Swapping the classes around gives me the expected:
And now what doesn't work BarTest.php <?php
require __DIR__ . '/FooTest.php';
class BarTest extends FooTest {
public function testBar() {
echo "bar";
$this->assertTrue(true);
}
} FooTest.php <?php
class FooTest extends PHPUnit_Framework_TestCase {
public function testFoo() {
echo "foo";
$this->assertTrue(true);
}
} produces::
Honestly I'd just say "Don't use autoloading or requires in test cases" but as I know people do it (not just you, I've seen that used a couple of times where people just build autoload maps for /tests/ or use file based inclusion also for the test folders (instead of just the test helpers)) I guess that is something we should take care of. Writing a regression test for that shouldn't be that hard but any pointers on how/where to fix it would be appreciated. Then again the time might be better spent on #10 that should just get rid of the issue :) |
Honestly, people should not reference something in one test file in another test file. They should be pulling things out into test helpers that live with the code to be tested, not the test code. I'm fine if it is deemed not to be fixed because honestly you should not implement tests this way, but I wanted to make sure there was some sort of documentation warning of this scenario so that there are fewer surprises. |
I think I just stumbled into this bug myself. It seems as though its a loading sequencing issue based on the filenames themselves, as BarExtendsFoo fails (Bar.php loaded before Foo.php), while FooExtendsBar succeeds (Bar.php loaded before Foo.php). Yes, my test class that are affected do use autoloading, one extending the other, and oddly enough they are named exactly the same... the files and class names are identical, only differentiated by folder locations and namespacing. In my example, ./StatementTest.php is an abstract parent of ./PDO/StatementTest.php. It looks as though the subfolder name "./PDO" is alphabetically chosen before ./StatementTest.php", and therefore ./PDO/StatementTest.php gets read before ./StatementTest.php gets read. Herein lies the loading sequence issue. Might it be possible to have the loader first load all files in a given directory before it descends into its subdirectories? |
This is still happening. Any plans on fixing this after year of no attention? |
Any progress on this? Because of this issue I can't really use https://github.com/brianium/paratest. For example when running tests in parallel I'm getting only 311 tests executed out of 371. |
Parallel test execution cannot work (correctly, with all features, ...) unless the work outlined in issue #10 has been done. |
@aik099–This issue isn't particularly high on our priority list as far as I know. Unless someone has time to work on a PR, it might be some time before we get around to it. |
Interesting, that this fact isn't mentioned anywhere on https://github.com/brianium/paratest.
I can try sending a PR, but I don't understand yet the root of a problem and it's possible solutions. Is it the fact, that test cases are auto-loaded preventing parent test case classes from test discovery? So adding Symfony is using http://www.gnu.org/software/parallel/ in their TravisCI configuration:
This looks interesting, since actual test file discovery now is done by P.S. |
So is there any temporary workaround for this? My test structure mimics my code structure, so there is a lot of overloading going on. |
Would accept a PR to this method: https://github.com/sebastianbergmann/php-file-iterator/blob/master/File/Iterator/Facade.php#L67 I'd change it to be breadth-first |
I looked into this a bit, and the issue comes from right here.
The problem arises with The way around this is to not do the the diff. Just For what it's worth Doctrine ORM has this same problem and solves it the same way. The problem, of course, is that it's kind of expensive resource-wise to check every class. |
Why not load all of the directory tree and only then do the get_declared_classes() check then? All those classes are going to end up in memory anyway. Also it seems that this is less of a problem on Windows, since it first would look at A.php and only then into the A/ folder. (Put files before directories of the same name) |
So if I have I think what will help is from the newly added classes really figure out which ones came from a file, that was included and which ones were auto-loaded (see http://www.php.net/manual/en/reflectionclass.getfilename.php). This way we can manually patch file-to-class array based on auto-loaded classes as well. |
@dracony I'm not really a huge fan of inheriting tests like this, but I wouldn't mind seeing this issue fixed. Feel free to send PRs so long as they don't just change the order of loading so that it's favorable for a particularly test suite. |
But from the |
K. I'll take a look at this. |
I think I have a simple fix for this: |
Alright, I found a slightly better solution. Instead of discarding loaded class names they go into the $untestedClasses array. Then that array is being used to match if the class exists for the particular suite. |
Well, the pull request is there, but nobody cares |
Added tests =) |
Seriously guys! Can my fix be merged now? It's been a week since I submitted a working fix WITH TESTS |
@dracony Please be patient. Your PR has possible BC and performance implications that I need to investigate before I can merge it. I hope to have time this weekend, but no guarantees. |
I just stumbled into this, we have the same issue in the Symfony test suite. |
You got that problem when you try to slice and dice test suite to make only specific tests to run. If run all test suite, then no problem happens. |
For me this problem appears always, as a test will never be loaded if its class was loaded before the first call to |
I'll look into this today. Thanks for your patience everyone :) |
This should be fixed in the next stable release. Thanks for your patience everyone :) |
…ebmozart) This PR was squashed before being merged into the 2.5 branch (closes #11485). Discussion ---------- [Validator] Constraint validators now use the 2.5 API | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - See the comments in #11049 for the origin of this PR. Currently, the 2.5 API needs to use `LegacyExecutionContextFactory` because the constraint validators rely on methods from the old `ExecutionContext` class (like `validate()`, `validateValue()`). Consequently it is impossible to switch to the pure 2.5 API and check whether all calls to deprecated methods were removed from application code. This is fixed now. This PR also introduces a complete test suite to test each constraint validator against all three APIs: 2.4, 2.5-BC and 2.5. Currently, some tests are not executed yet when running the complete test suite is run. I expect this to be fixed soon (ticket: sebastianbergmann/phpunit#529, pr: sebastianbergmann/phpunit#1327). Commits ------- 295e5bb [Validator] Fixed failing tests 3bd6d80 [Validator] CS fixes 870a41a [FrameworkBundle] Made ConstraintValidatorFactory aware of the legacy validators 7504448 [Validator] Added extensive test coverage for the constraint validators for the different APIs 8e461af [Validator] Constraint validators now use the 2.5 API. For incompatible validators, legacy validators were created
…ebmozart) This PR was squashed before being merged into the 2.5 branch (closes #11485). Discussion ---------- [Validator] Constraint validators now use the 2.5 API | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - See the comments in #11049 for the origin of this PR. Currently, the 2.5 API needs to use `LegacyExecutionContextFactory` because the constraint validators rely on methods from the old `ExecutionContext` class (like `validate()`, `validateValue()`). Consequently it is impossible to switch to the pure 2.5 API and check whether all calls to deprecated methods were removed from application code. This is fixed now. This PR also introduces a complete test suite to test each constraint validator against all three APIs: 2.4, 2.5-BC and 2.5. Currently, some tests are not executed yet when running the complete test suite is run. I expect this to be fixed soon (ticket: sebastianbergmann/phpunit#529, pr: sebastianbergmann/phpunit#1327). Commits ------- 295e5bb [Validator] Fixed failing tests 3bd6d80 [Validator] CS fixes 870a41a [FrameworkBundle] Made ConstraintValidatorFactory aware of the legacy validators 7504448 [Validator] Added extensive test coverage for the constraint validators for the different APIs 8e461af [Validator] Constraint validators now use the 2.5 API. For incompatible validators, legacy validators were created
…ebmozart) This PR was squashed before being merged into the 2.5 branch (closes #11485). Discussion ---------- [Validator] Constraint validators now use the 2.5 API | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - See the comments in #11049 for the origin of this PR. Currently, the 2.5 API needs to use `LegacyExecutionContextFactory` because the constraint validators rely on methods from the old `ExecutionContext` class (like `validate()`, `validateValue()`). Consequently it is impossible to switch to the pure 2.5 API and check whether all calls to deprecated methods were removed from application code. This is fixed now. This PR also introduces a complete test suite to test each constraint validator against all three APIs: 2.4, 2.5-BC and 2.5. Currently, some tests are not executed yet when running the complete test suite is run. I expect this to be fixed soon (ticket: sebastianbergmann/phpunit#529, pr: sebastianbergmann/phpunit#1327). Commits ------- 295e5bb [Validator] Fixed failing tests 3bd6d80 [Validator] CS fixes 870a41a [FrameworkBundle] Made ConstraintValidatorFactory aware of the legacy validators 7504448 [Validator] Added extensive test coverage for the constraint validators for the different APIs 8e461af [Validator] Constraint validators now use the 2.5 API. For incompatible validators, legacy validators were created
If you have a test 'FooTest' which is a concrete test class, and then you extend that concrete test class with test 'BarTest', 'FooTest' will not be executed as it's class was loaded and cached in PHP_Util_Class::$buffer before the test for that file can be added to the test suite.
The text was updated successfully, but these errors were encountered: