spameri/dependency-mocker

Loads dependencies to mocked classes by Mockery for Nette Framework.

v2.0.0 2022-02-10 08:59 UTC

This package is auto-updated.

Last update: 2024-12-10 15:28:12 UTC


README

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();