Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

enadabuzaid's avatar

Class "Mockery" not found when deploying via forge

I have this error many times when deploying via forge and the forage gives me the following hint

Please make sure that the following SSH key is placed in both the /home/forge/.ssh/authorized_keys file and the /root/.ssh/authorized_keys file on your server.

and I am sure the ssh is correct

Nothing to install, update or remove
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In SupportFileUploads.php line 17:
                             
  Class "Mockery" not found  
                             

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

what is this problem and how solve it

0 likes
1 reply
LaryAI's avatar
Level 58

The error you're encountering, "Class 'Mockery' not found," typically indicates that the Mockery library is not installed or not autoloaded correctly in your project. This can happen for several reasons, especially during deployment.

Here are the steps to resolve this issue:

  1. Ensure Mockery is Installed: First, make sure that Mockery is listed as a dependency in your composer.json file. It should be under the require-dev section since Mockery is usually used for testing.

    {
        "require-dev": {
            "mockery/mockery": "^1.0"
        }
    }
    
  2. Run Composer Install: After confirming that Mockery is listed in composer.json, run the following command to install the dependencies:

    composer install --no-dev
    

    If you are deploying to a production environment, you might be using the --no-dev flag, which skips the installation of development dependencies. Ensure that you are not running this flag if you need Mockery for some reason in your deployment process.

  3. Check Autoloading: Ensure that the autoload files are generated correctly. You can force a regeneration of the autoload files by running:

    composer dump-autoload
    
  4. Verify SSH Keys: The hint provided by Forge suggests ensuring that the SSH keys are correctly placed. This is crucial for accessing private repositories or running certain commands that require SSH authentication. Verify that the SSH keys are correctly placed in both /home/forge/.ssh/authorized_keys and /root/.ssh/authorized_keys.

  5. Check for Environment-Specific Issues: Sometimes, the issue might be environment-specific. Ensure that the environment where you are deploying has all the necessary permissions and configurations.

  6. Check for Missing Dependencies: If the problem persists, it might be due to other missing dependencies or misconfigurations. Ensure that all required PHP extensions and other dependencies are installed on the server.

Here is a summary of the commands you might need to run:

# Ensure Mockery is in composer.json
composer require --dev mockery/mockery

# Install dependencies
composer install

# Regenerate autoload files
composer dump-autoload

By following these steps, you should be able to resolve the "Class 'Mockery' not found" error during your deployment process. If the issue persists, consider checking the deployment logs for more detailed error messages or any other missing dependencies.

Please or to participate in this conversation.