Problem/Motivation
For simpletest we have to parse all available tests. This becomes more and more a problem, as our test suite increases, which is great!
Proposed resolution
Use doctrine's StaticReflectionReader (also used by the Plugin system) and parse the class comment using regular expressions.
We could also use https://github.com/sun/staticreflection which was once written, especially for this purpose. But it appears unmaintained.
Remaining tasks
Review
Commit
User interface changes
None
API changes
All tests have to have an @group
declaration - including PHPUnit tests (not currently the case). In HEAD, if a simpletest (a class that extends WebTestBase
or KernelTestBase
) is instantiable and does not have an @group
annotation an exception is produced. This is removed since we can not determine if a class is instantiable using static reflection - we use the @group annotation to determine if something is a test or not (i.e. a trait, abstract base class etc).
Comment | File | Size | Author |
---|---|---|---|
#21 | 2422019.21.patch | 19.28 KB | alexpott |
#21 | 14-21-interdiff.txt | 1.54 KB | alexpott |
Comments
Comment #1
dawehnerJust experiments so far, don't trust it. I'll try sun's library next.
Comment #2
alexpottIt is going to be problematic to make doctrine's annotation parser play nice with PHPUnit type annotations since they expect an open parenthesis.
Compare the annotation in the node entity
with a simpletest annoation
Comment #3
alexpottHad a look to see how easy it would be to make Doctrine's annotation parser parse a simpletest / phpunit annotation. It is not simple. The lexer is not built to work this way.
Comment #4
alexpottAnother idea... I've confirmed that the all the test classes are listed when you use the --list option on run-tests.sh. Because we can't determine if something is a PHPUnit test then all the groups are different - which is why I've standardised on using ucfirst().
Before
After
Comment #5
alexpottNow lets use the same logic everywhere.
Comment #6
alexpottNow with tests.
I think the regex to get the first summary line can be improved.
Comment #7
dawehnerGreat idea to use the regex!!
Note: We could simply use
$parser->getReflectionClass()
which allows you to check it, if needed. This would allow us to still show the exception, so people will still get help, while writing tests. If you pass along the reflection class, you could even get rid of the "api" change.Comment #8
alexpottre #7 I don't think that'll work unfortunately.
from StaticReflectionClass.
Comment #9
alexpottImproved the summary line parsing and added yet more tests.
A 200mb memory reduction must qualify this as a performance critical - plus the relief to testbots will be huge and it is good for new contributors because the testing page will work without huge amounts of memory for php.
Comment #10
BerdirNot sure why the ucfirst() is added here? We've been discussing that in #2301481: Mark test groups as belonging to modules in UI.
Comment #11
alexpottUcfirst() is added because this patch removed the php unit group making duplicate groups even more prominent.
Comment #12
BerdirHm, that is an interesting change, because lot of .travis scripts out there rely on phpunit tests not being in the module (they run phpunit test and then the group tests separately), and they also hardcode the group name. Including my script for http://d8ms.worldempire.ch/, I quite like that I can report phunit/simpletest status separately.
Not saying that we shouldn't do that, just to be aware of the side effects that will have.
Comment #13
alexpottWithout using something more funky for static reflection (https://github.com/sun/staticreflection whihch looks unmaintained since the original development) we can not know that it is a PHPUnit test - I tried using the use statements but things like
BlockContentLocalTasksTest
which extendsLocalTaskIntegrationTest
which extendsUnitTestCase
make that unrealistic.If people want to report PHPUnit separately run the PHPunit tests using phpunit. Yep they will get re-run on when using run-tests.sh but I think that is a small price to pay for the gain here.
Comment #14
alexpott@Berdir that said there is a way :) - the namespace all PHPUnit tests start with
Drupal/Test/
and simpletest tests cannot have that so... fixed and removed theucfirst
for the other issue.Comment #15
dawehnerGreat work!!
Comment #17
alexpottComment #18
alexpottComment #19
BerdirThanks, I'm not sure if it is better to use ucfirst() or not, but I think it is good to discuss that separately and not enforce it as part of a critical issue.
Did not review the patch closely, but +1 to RTBC from me.
Comment #20
amateescu CreditAttribution: amateescu commentedLooks good to me as well, found a few nitpicks though :/
Extra space here.
This should be MissingSummaryLineException now.
Cliffhanger :P
Comment #21
alexpottThanks @amateescu - fixed all of that.
Comment #22
catchCommitted/pushed to 8.0.x, thanks!
Comment #24
daffie CreditAttribution: daffie commentedWhy do all PHPUnit tests grouped together? For instance a PHPUnit test for blocks should be grouped in block. Not in PHPUnit. If I make a change to the block module and I want to do a quick test to see if all tests for the block-module pass the PHPUnit block tests are not run.
Comment #25
BerdirThat's how it worked before, and we agreed to not change the current behavior here.
Comment #26
dawehnerI'm sorry but this is just the behaviour of the previous HEAD. Afaik the idea was to allow people to run the phpunit tests as fast as possible, but I agree for those cases you should use phpunit directly anyway.
Feel free to open a non-critical followup.
Comment #27
daffie CreditAttribution: daffie commentedThank you @Berdir and @dawehner for pointing out to me that I should create a new issue for that. :-)
The new issue for the grouping of PHPUnit test (#2427191: Test-runner ignores @group annotations for PHPUnit-based tests in modules.).
Comment #29
webchickManuel Garcia and I lost 40+ minutes trying to figure out why #2499971: Tests are missing @coversDefaultClass annotations was happening as a result of insufficient documentation related to this issue. Cross-linking #2325985: No documentation about @group @coversDefaultClass @covers.
Comment #30
webchickComment #31
webchickOk, did find a change record for this after all: https://www.drupal.org/node/2325985. Added this issue to related issues there.
Spun off #2500031: Killing the entire Testing list page if any test anywhere is missing a summary is not nice; add robustness to make this a bit more robust.