2017 © Pedro Peláez
 

library php-method-injection

PHP Trait to inject methods

image

horat1us/php-method-injection

PHP Trait to inject methods

  • Monday, May 8, 2017
  • by Horat1us
  • Repository
  • 1 Watchers
  • 0 Stars
  • 175 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 51 % Grown

The README.md

PHP Method Injection Trait

Scrutinizer Code Quality Code Coverage Build Status Latest Stable Version Total Downloads License, (*1)

This trait allows you to extend your object with custom method dynamically., (*2)

Usage

You can use DynamicObject or implement interface InjectMethodsInterface with trait InjectMethods on your custom object., (*3)

Simple example will output:, (*4)

Hello, Alexander
Hello, Letnikow
Array
(
    [arguments] => Array
        (
            [0] => Man
        )

    [methodName] => welcome
    [object] => Horat1us\MethodInjection\DynamicObject
    [message] => Injected method welcome not found in Horat1us\MethodInjection\DynamicObject
)

About

This package is created for using in tests. For example, you have interface, (*5)

<?php
interface ServiceInterface
{
    public function run($args);
}

and you need to test arguments which will be passed to this service. You can define fake service:, (*6)

<?php
use Horat1us\MethodInjection\InjectMethodsInterface;
use Horat1us\MethodInjection\InjectMethods;

/**
 * @method Test($args) 
 */
class FakeService implements InjectMethodsInterface, ServiceInterface
{
    use InjectMethods;

    public function run($args) {
        $this->Test($args);
    }
}

and use it in your test service, (*7)

<?php
$service = new FakeService(['Test' => function() {
    // Your tests here
}]);
ServiceRunner::run($service);

Install

composer require horat1us/php-method-injection

Tests

phpunit

License

This project is open-sourced software licensed under the MIT license, (*8)

The Versions

08/05 2017

dev-master

9999999-dev

PHP Trait to inject methods

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Alexander Letnikow

08/05 2017

1.0.0

1.0.0.0

PHP Trait to inject methods

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Alexander Letnikow