Skip to content

NormanAlbert91/mock-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPStan Mock Check

A PHPStan plugin to forbid mocking specific interfaces or classes.

Installation

Add the repository to your composer.json:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "[email protected]:NormanAlbert91/mock-check.git"
        }
    ]
}

Then install the package:

composer require --dev na/mock-check:dev-main

If you use phpstan/extension-installer, the plugin is automatically registered. Otherwise, add to your phpstan.neon:

includes:
    - vendor/na/mock-check/extension.neon

Configuration

Add forbidden patterns to your phpstan.neon:

parameters:
    mockCheck:
        forbiddenPatterns:
            -
                pattern: 'Psr\'
                message: 'PSR interfaces should not be mocked - use real implementations.'
            -
                pattern: 'Doctrine\ORM\EntityManagerInterface'
                message: 'Use the in-memory repository instead of mocking EntityManager.'
            -
                pattern: 'App\Domain\*'

Pattern formats

Pattern Description
Psr\ Trailing backslash: matches everything starting with Psr\
Psr\Log Without backslash: matches everything under Psr\Log\
Psr\Log\* Wildcard: regex-style matching
Psr\Log\LoggerInterface Exact match

Custom messages

The message parameter is optional. If omitted, a default message is shown:

Mocking Psr\Log\LoggerInterface is forbidden (matches pattern "Psr").

Detected mock methods

The plugin detects the following PHPUnit mock methods:

  • createMock()
  • createStub()
  • createPartialMock()
  • createConfiguredMock()
  • createTestProxy()
  • getMockBuilder()
  • getMock()
  • getMockForAbstractClass()
  • getMockForTrait()

About

PHPStan plugin for checking mocks

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages