Problem/Motivation

The annotation component has 0 explicit testing.

Proposed resolution

Add tests.

Remaining tasks

Review and commit patch.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because it provides additional testing
Issue priority Normal missing tests
Unfrozen changes Unfrozen because it only changes tests
Disruption 0 Disruption
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markdorison’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Needs review » Needs work

Patch no longer applies cleanly.

neclimdul’s picture

Status: Needs work » Needs review
FileSize
3.76 KB
9.85 KB

Thanks! Re-roll and a couple cleanups since some coding standards have changed since this was rolled last year.

Couple notes:
1) I think there is actually some coverage now but its in kernel tests. This is IMHO better.
2) There is a new feature since original roll to provide additional annotation namespaces and that test coverage is missing from this coverage.
3) Cache handling is not tested in this testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

+++ b/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php
@@ -0,0 +1,46 @@
+    $discovery = new AnnotatedClassDiscovery(['com/example' => [__DIR__ . '/Fixtures']]);
...
+        'class' => 'com/example\com\example\DiscoveryTest1',

That classname looks so weird, how is "com/example" a valid namespace?

neclimdul’s picture

This so old there are 8.0 beta eval's in the summary still... I assume I did that for a reason but i'm going to have to do some digging to answer your question at this point.

dawehner’s picture

Status: Needs review » Needs work

Let's set it to needs work until then :)

neclimdul’s picture

Status: Needs work » Needs review

So PHP allows it as documented here. http://php.net/manual/en/language.namespaces.faq.php#language.namespaces...

I think I was asserting that we didn't break it because we where working with namespaces as strings.

+++ b/core/tests/Drupal/Tests/Component/Annotation/Fixtures/com/example/DiscoveryTest1.php
@@ -0,0 +1,10 @@
+namespace com\example;

Its actually working here.

dawehner’s picture

Do you mind leaving a comment about that? It still confused me.

neclimdul’s picture

um.. that would be because it doesn't make sense. I guess it just shows that annotations doesn't actually care about the namespace it just parses files? That's probably not something that needs to be tested...

So cleaned that up and added some tests for custom plugin annotations which seem to have been missing. Only thing not tested now I think it the FileCache stuff.

Status: Needs review » Needs work

The last submitted patch, 10: tests_for_annotation-2435607-10.patch, failed testing.

neclimdul’s picture

Status: Needs work » Needs review

I don't even know. that failure doesn't even show up in the test run logs.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Kinda goes without saying... Needs a reroll. :-)

Also we need tests so we can proceed with #2631202: Doctrine no longer supports SimpleAnnotationReader, incorporate a solution into core

markdorison’s picture

Status: Needs work » Needs review
FileSize
10 KB

Re-rolled.

Mile23’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll
+++ b/core/tests/Drupal/Tests/Component/Annotation/AnnotatedClassDiscoveryTest.php
@@ -0,0 +1,89 @@
+    $result = $reflection->invoke(
+      $discovery);
+    $this->assertEquals([
+      'com/example' => [__DIR__]
+    ], $result);

Some weird formatting. If we can fit a function on a line we should.

Generally looks like it does a good job of exercising all the classes.

markdorison’s picture

Status: Needs work » Needs review
FileSize
11.06 KB
4.48 KB

Fixed issue detailed in #16 and updated the rest of the patch to conform to Drupal coding standards.

Mile23’s picture

Status: Needs review » Reviewed & tested by the community

Cool, thanks. RTBC now assuming the tests will pass....

larowlan’s picture

  1. +++ b/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php
    @@ -34,7 +34,9 @@ public function testGetDefinitions() {
    -
    
    @@ -45,12 +47,16 @@ public function get() {
    +/**
    

    nit: I think we need these blank lines

  2. +++ b/core/tests/Drupal/Tests/Component/Annotation/PluginIdTest.php
    @@ -0,0 +1,55 @@
    +    // Assert plugin starts empty regardless on constructor.
    

    nit: on => of?

These can be fixed on commit

markdorison’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
11.06 KB
1.22 KB

Fixed issues detailed in #19.

Mile23’s picture

Status: Needs review » Reviewed & tested by the community

#20 fixes #19.

larowlan’s picture

From #10
Only thing not tested now I think it the FileCache stuff.
I can't see any interdiffs since then that add that?

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Mile23’s picture

Status: Needs review » Needs work

This component has a dependency on drupal/core-file-cache, which is incorrect in its composer.json despite #2876725: Fix trivial core component composer bugs before 8.4.0 and #2867960: Merge Component composer.json files to account for them during build

We should exercise and test the behavior of the file cache as you can see in http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Component/Annotat...

So: The test should create an AnnotatedClassDiscovery, use it to discover, check the cache for the same information we got back, change the cache, perform the same query, get back the different cached result.

Agreed? :-)

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

So: The test should create an AnnotatedClassDiscovery, use it to discover, check the cache for the same information we got back, change the cache, perform the same query, get back the different cached result.

That sounds like a good solution for testing the filecache.

Mile23’s picture

Status: Needs work » Needs review
FileSize
13.86 KB
7.1 KB

So I see a bunch of fails locally that look like this:

1) Drupal\Tests\Component\Annotation\AnnotatedClassDiscoveryTest::testGetPluginNamespaces
Component tests should not extend a core test base class.

That's the test listener doing it's job so yay test listener.

Fixed. I had to move some FileCacheFactory management to AnnotatedClassDiscoveryTest.

Added file cache test. It's a separate test class because it has a different setUp() than AnnotatedClassDiscoveryTest, in that we want to use caching. :-)

neclimdul’s picture

Why is "\Drupal\Tests\UnitTestCase" considered Core? I know I've had this discussion before when writing a lot of component tests early on and it is clearly not or it would be in "\Drupal\Tests\Core\"

Mile23’s picture

UnitTestCase uses \Drupal and other core-related stuff. Component tests should be runnable independent of core. See: https://github.com/paul-m/drupal_component_tester

It's true that UnitTestCase might be better placed under the Core namespace.

Check it out: BrowserTestBase is under \Drupal\Tests\, too, and it doesn't even inherit from UnitTestCase. Happy to review a re-shuffling issue if you file it.

neclimdul’s picture

Thanks. I've opened #2913630: Move UnitTestCase to Core namespace, deprecate old to start that.

I'd RTBC but the cache test is failing locally and I'm trying to sort out why... Filecache is frustrating.

Mile23’s picture

I'm not seeing any fails locally...

neclimdul’s picture

Process isolation bug in in UnitTestCase. Not directly tied to this patch but exposed by you actually testing the FileCache system.

Breakdown: If run in isolation like testbot everything works. AnnotatedClassDiscoveryCachedTest::setUpdoes not touch filecache global config and cache works as expected. But if run as a full test suite using the phpunit runner (and no process isolation) any core test that uses UnitTestCase before the cached annotation test causes the filecache to be disabled globally and never re-enabled. That causes the AnnotatedClassDiscoveryCachedTest test to break when it gets a Null cache implementation. Unfortunately phpunit's global change detection isn't catching this because its hidden in a static class.

I updated the UnitTestCase to clean up after itself. We could possibly also force the configuration we want as part of the cached annotation test but we should definitely fix UnitTestCase to avoid it breaking subtly in the future.

If you agree with the changes I made, I think the patch is RTBC.

Mile23’s picture

Oh yeah, of course.

We could set @runTestsInSeparateProcess for those classes.

neclimdul’s picture

we could but tearDown should reset any state changes so the UnitTest change is correct imho.

Mile23’s picture

Nevermind... @runTestsInSeparateProcesses not really a good idea, actually. :-)

UnitTestCase::setUp() always sets the file cache configuration and prefix, so it's in a known state before the tests run. Other than that, the only way to make sure state doesn't bleed is to run all tests that change the file cache settings in isolated processes, and not use setUp() to manage it, which is a lot more effort and takes longer. (setUp() is run before the separate process is created, so it will still change the static and possibly leak to other tests.)

I don't like the idea of the test being responsible for resetting static state at tearDown(), because the 'old' settings could just be the leaked state we don't want.

So being consistent with UnitTestCase, we set the config of the file cache explicitly in setUp() in both classes.

I couldn't find any similar issues in the file cache component.

Also: FileCacheFactory::setConfiguration() docs: Completely not useful. :-)

Also II: Statics are evil and will bring forth the ire of the Ancient Ones who will devour your soul before you can invoke the names of the Gang of Four.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

I don't agree but that's fine because in reality its totally unrelated to this issue so lets discuss in a follow up. :)
#2914242: Reset Filecache State in UnitTestCase

Mile23’s picture

:-)

larowlan’s picture

Adding review credit for @dawehner

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed as 2d25dc4 and pushed to 8.5.x.

  • larowlan committed 2d25dc4 on 8.5.x
    Issue #2435607 by neclimdul, markdorison, Mile23, dawehner: Tests for...
Mile23’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.