Updated: Comment #N
Problem/Motivation
Drupal\system\Tests\Routing\* contain some great unit tests for the routing system, but we're missing a unit test for RouteBuilder. To do so, we need to remove the module_list() dependency, so postponing this on #1331486: Move module_invoke_*() and friends to an Extensions class.
Some of the tests needed to mock the router dumper. The current code typehints the matcher dumper interfaces, though calls "addRoutes" which is not
defined yet as an interface.
Proposed resolution
Let's add a specific dumper interface which contains the addRoutes method()
Remaining tasks
User interface changes
API changes
Original report by @username
The current code
In order to write proper tests we intro
Comments
Comment #1
effulgentsia commented#1855204-5: RouteBuilder needs to respect route options set in yaml file contains some starter unit tests for this we might want to bring over when we're ready to do this.
Comment #2
jibran#1331486-239: Move module_invoke_*() and friends to an Extensions class is committed.
Comment #3
katbailey commentedThe "replace module_list()" bit was done as part of #1331486: Move module_invoke_*() and friends to an Extensions class, so we just need to write the tests.
Comment #4
dawehner.
Comment #5
dawehnerWhile writing the tests I actually realized that the it is actually not true that the routes are not in memory all the time.
The test file was just some random test writing until I realized that they actually should not pass. Note: At the end all routes
are in the dumper.
Note: RouteCollection->addCollection does not remove old entries.
Comment #6
mile23RouteBuilder says things like this:
$yaml_discovery = new YamlDiscovery('routing', $this->moduleHandler->getModuleDirectories());I say things like this: #2095037: Add vfsStream as a dependency in composer.json.
Comment #7
dawehnerThere we go, this fixes the actual bug as well as tests the rest of the class.
Comment #9
dawehnerSome fixes later.
Comment #11
dawehnerThere we go.
Comment #12
dawehnerLet's be honest.
Comment #13
dawehnerFixed a missing whitespace.
Comment #14
Crell commentedDiscussed with dawehner in IRC. We don't need to mess with the interface for MatcherDumper; there was a bug in the tests he was using. :-)
Comment #15
dawehnerWe have been talking about removing the matcher dumper to be a service, thought this is not part of the patch as it would be kind of out of scope.
Comment #18
dawehnerFixed the errors.
Comment #19
damiankloip commentedOverall, that is some good unit testing.
Should we use YAML?
Won't this always return NULL anyway? regardless of whether the lock fails.
Nice!
Comment #20
dawehnerThanks for the review!
Someone had the idea that phpunit strict mode would be a good idea.
Comment #21
damiankloip commented:) Maybe we should make rebuild() return something?
Comment #22
dawehnerWell, we could just return TRUE/FALSE but it is kind of pointless to be honest.
Comment #23
dawehnerHere is a patch for that.
Comment #24
Crell commentedWhy are we still doing this? It's not needed.
Comment #25
dawehnerI potentially agree that it is scope-creep though addRoutes is not part of the symfony interface, so as the router
system should be possible to be used on whatever other database system we should introduce an interface. Do you want to add a new issue for that or is it okay in this issue?
Comment #26
dawehner#23: route_rebuild-1859684-23.patch queued for re-testing.
Comment #27
klausiwhy the "|" OR here? the first is a child of the second, so just use the second.
should be "FALSE otherwise".
Can't say much about the rest, looks like we are merely expanding test coverage here? No actual bug is fixed here?
Comment #28
dawehnerAh this was not on purpose.
The only actual bug was the missing interface.
Comment #29
Crell commentedWe should drop addRoutes(). The dumper not being a true-service is a separate matter (and my fault for not catching originally). Adding another method that duplicates existing functionality is not necessary.
Comment #30
dawehnerSo you suggest to just leave the method but just skip to use an interface?
Comment #31
Crell commentedNever mind, I was misreading the patch. :-) Ignore my objections.
Comment #32
catchWhere is this setRoutes() method that's supposed to be added?
Comment #33
dawehner@catch
I was wrong on that. All we need is the already existing addRoutes method.
Comment #34
dawehnerComment #35
catchIn that case, we should update the comment so it's not talking about a method that doesn't exist, and I'm wondering why we're extending the interface at all if it has exactly the same single identical method to the Symfony one. If there's a reason it could use a comment as to why.
Comment #36
dawehnerComment #37
dawehnerAdded some comment about the need for an interface: https://drupal.org/node/1859684
Comment #38
Crell commentedBackground: The Symfony dumper interface doesn't define how routes get queued up to be dumped, just how they're dumped. Our dumper defines a method for doing so, but when I wrote it I didn't bother to make an interface for it. (The Symfony default one uses a constructor parameter for a single RouteCollection, which wouldn't scale for us.) This issue fixes that oversight on my part.
I was confused by this too, earlier in the thread. We're good now.
Comment #39
catchSorry I still don't get it.
The comment says
However the interface does not extend the interface with a setRoutes method, it just defines an addRoutes() method.
If I'm missing something please let me know, but I don't see how the patch is possibly correct at the moment.
Comment #40
Crell commentedI think that's just the comment being a bit out of date. It should now read addRoutes(). Does that make more sense?
Comment #41
catchYes that's all I really wanted in #32 (assuming that was the problem).
Comment #42
dawehnerOh sometimes I am just blind.
Comment #43
Crell commentedSeems to happen to a lot of people in this thread. :-)
Comment #44
catchCommitted/pushed to 8.x, thanks!
Comment #45
dawehnerLet's also mark the issue as fixed.