Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

README.md

Build Status

Mock Finals

Mock final classes and methods in your tests. Library overrides existing class loaders and removes all final occurrences in runtime using uopz_flags.

Installation

composer require --dev awesomite/mock-finals

Requirements

  • PHP ^7.1
  • uopz (pecl install uopz)

Use cases

In general, it's a bad practice to do so. However it may be helpful when you have to deal with legacy code or third party libraries. Please read the following article to understand how to properly deal with final keyword in your code.

Example

class Greeter
{
    final public function sayHello(): string
    {
        return 'hello';
    }
}

class MyTest extends \PHPUnit\Framework\TestCase
{
    public function testSayHello(): void
    {
        $mock = $this->getMockBuilder(Greeter::class)->getMock();
        $mock
            ->expects($this->once())
            ->method('sayHello')
            ->willReturn('goodbye')
        ;
        $this->assertSame('goodbye', $mock->sayHello());
    }
}

About

No description, website, or topics provided.

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.