Search code examples
laravelhoneypot

Unable to disable Msurguy Honeypot in Unit test in Laravel


I am developing a Laravel application. I am doing unit testing on my application as well. I am also implementing Honeypot on the forms as well using this package, https://github.com/msurguy/Honeypot. It is working when I submit the form from the browser. But the thing is I need to disable it in the unit test. I am trying to do it following what is mentioned in the docs like this.

Honeypot::disable();

But when I run my test, I got this error.

ErrorException: Non-static method Msurguy\Honeypot\Honeypot::disable() should not be called statically

What is wrong? Is the documentation wrong or how can I possibly do that? That is what exactly mentioned in the docs.


Solution

  • You want to call the facade statically, not the service class directly.

    Instead of this:

    use Msurguy\Honeypot\Honeypot;
    
    // ...
    
    Honeypot::disable();
    

    Do:

    use Msurguy\Honeypot\HoneypotFacade as Honeypot;
    
    // ...
    
    Honeypot::disable();
    

    Or:

    // ...
    
    \Honeypot::disable();