Componette

Componette

Spameri

Spameri / DependencyMocker v2.0.0

Loads dependencies to mocked class in Nette Framework environment.

download-cloud-line composer require spameri/dependency-mocker

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();
  • v2.0.0 PHP 8.1 support

    PHP 8.1 support

    Thanks @Jakub-Fajkus

    & PeckaDesign

  • v1.3.1 Return NULL as expected

    Fixed - When annotaion is empty return NULL instead of empty string.

  • v1.3 Drop Nette/DI dependency

    Dropped Nette/DI dependency for better usage in applications with different version of Nette/DI.

  • v1.2 Mockery version Bump

    • Fix when banned classes not set
    • Travis config
  • 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

Componette Componette felix@nette.org