dingo-d / wp-pest

A package that will add WordPress integration test suite with Pest
MIT License
119 stars 5 forks source link

Call to undefined function mock() #19

Closed paulcgdev closed 1 year ago

paulcgdev commented 1 year ago

Describe your bug

Simply using mock() function (like this) throws an error Call to undefined function mock(). Using the class works though as in $mock = \Mockery::mock( Bootstrap::class );.

Steps to Reproduce

Just use mock() function

Expected behavior

Should not throw error.

Screenshots, screen recording, code snippet

2022-09-02_13-23-24

Environment info

Windows 11 Pro on WSL2 PHP 7.4.x and/or 8.0.x Composer version 2.0.14 2021-05-21 17:03:37 PHPStorm 2022.2.1 - although doesn't matter because even in just the WSL terminal, it's the same

Please confirm that you have searched existing issues in this repo.

Yes

dingo-d commented 1 year ago

Hmmm, could be because the underlying test case (if integration tests are in question) doesn't have this method exposed. I'll need to check, and add it as a helper if not used 👍🏼

dingo-d commented 1 year ago

Oh, I just noticed that you need to install the pest-plugin-mock, and I haven't tested this package with the mock package.

I think that you can add this:

<?php

use Mockery;
use Mockery\MockInterface;

function mock(string $classname): MockInterface
{
    return Mockery::mock($classname);
}

inside the Helpers.php file, and you should be able to use the mock() to use mockery.

You are able to do so because the PHPUnit-Polyfills package depends on the BrainMonkey package, which in turn depends on Mockery 😄

paulcgdev commented 1 year ago

Found it... seems just calling Mockery::globalHelpers(); works. Added it to _manually_load_plugin() function like so:

function _manually_load_plugin() {

    Mockery::globalHelpers();// <- added
    require dirname( __FILE__, 2 ) . '/main-plugin.php';
}