Statistics
28
1
0
1.3y
Badges
Dependencies

DependencyMocker

Loads dependencies to mocked classes by Mockery for Nette Framework.

Usage

Set up

Banned Classes

Data entities, classes with different implementations of mockery magic (e.g. __getStatic()) etc.

Spamer\DependencyMocker\Mocker::setBannedClasses([
	App\Entity\BaseEntity::class,
	App\GetStatic::class,
]);

Mock Class

$basePresenter = Spamer\DependencyMocker\Mocker::mockClassDependencies(App\BasePresenter::class);

Magic

Methods in BasePresenter:

$basePresenter->shouldReceive('add')->andReturn(1);

Accessing dependencies of BasePresenter and setting up Mockery logic.

Private property

Spamer\DependencyMocker\Mocker::getProperty(
	App\BasePresenter::class, 
	'articleModel', 
	$basePresenter
)
	->shouldReceive('save')->once();

Public property

$basePresenter->articleModel->shouldReceive('save')->once();
  • v1.1 v1.1

    • New function allowing to call private method on object.

    Example:

    class TestClass
    {
        private function saltPassword($string)
        {
            return $string . 'salt';
        }
    }
    

    Test result:

    $testClass = new TestClass();
    
    $result = \Spamer\DependencyMocker\Mocker::callPrivateFunction($testClass, 'saltPassword', ['string']);
    
    \Tester\Assert::same('stringsalt', $result);
    
  • v1.0.1 v1.0.1

    • Fixed exception when mocking class without __construct method.
  • v1.0

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com