Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "request".

There is no core 'request' service anymore. It was removed from core in #2284103: Remove the request from the container (14 July 2014).
Any usage of the the current version of the BanIP action causes a whitescreen/fatal PHP error.
The request must now be obtained through the core 'request_stack' service.

The unit test for this action is: tests/src/Unit/Integration/Action/BanIPTest.php
The test does NOT fail or detect this problem because the current test is faulty - the test mocks a core 'request' service for BanIP to use, so it does not detect that the 'request' service no longer exists.

The patch in #5 changes BanIP to use the 'request_stack' service and changes the test to mock the 'request_stack' service. After applying the patch, the Rules Action BanIP can be used successfully in the UI.

Comments

TR created an issue. See original summary.

tr’s picture

Status: Active » Needs review
StatusFileSize
new486 bytes
tr’s picture

StatusFileSize
new2.38 KB

Fails because the existing test is faulty - the test mocks a core 'request' service for BanIP to use. This is why the test doesn't fail when BanIP tries to use that non-existent service.

Here's the patch with a modified version of the test. This modified test mocks the real 'request_stack' core service instead.
I've never used Prophecy before, so this may take a few iterations to get the new test right ...

tr’s picture

StatusFileSize
new4.37 KB

Let's try this again ...

tr’s picture

StatusFileSize
new4.29 KB
tr’s picture

Title: BanIP causes PHP Exception » BanIP action causes PHP Exception
Issue summary: View changes
tr’s picture

Can someone try this and RTBC it?

1) Try using the Ban IP action. All you have to do is try to create a reaction rule with this action. It should fail with the fatal error shown in the original post.
2) Apply the patch and try it again. It should work!

jonathan1055’s picture

Status: Needs review » Reviewed & tested by the community

Good work @TR, yes, this patch fixes the error interactively, and I can create a rule with this action. When it is triggered it works as designed and the IP address is added to the banned list, as shown when visiting /admin/config/people/ban

I have also checked it with the tests I created and it works, following slight adjustment of the text to search for - see #2664280-25: Select lists in action & condition configuration forms

Here is a pull request to match the patch in #5 https://github.com/fago/rules/pull/498

The only thing which would be nice to do is somehow disable the 'Ban IP' selection option if the Ban module is not enabled. There should be a simple way to show this text but not allow the user to pick it. However, now that each option item is an object not array (like it used to be in D7) we can't just set '#disabled' = TRUE. This can be a follow-up issue, as it does not impact the fix here.

Jonathan

  • fago committed 42ae4eb on 8.x-3.x authored by TR
    Issue #2922804 by TR, jonathan1055: BanIP action causes PHP Exception
    
fago’s picture

Status: Reviewed & tested by the community » Fixed

Thx, agreed! Merged.

Yeah the problem of plugins requiring special modules is something which I'd prefer to solve generally, such that plugins can specify the modules they need and we handle it properly based upon that metadata.

Status: Fixed » Closed (fixed)

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

jonathan1055’s picture

Thanks for merging. Been away, back now, hence late response.