dev-master
9999999-devPHP Trait to inject methods
MIT
The Requires
- php >=7.0
The Development Requires
by Alexander Letnikow
1.0.0
1.0.0.0PHP Trait to inject methods
MIT
The Requires
- php >=7.0
The Development Requires
by Alexander Letnikow
Wallogit.com
2017 © Pedro Peláez
PHP Trait to inject methods
This trait allows you to extend your object with custom method dynamically., (*2)
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
)
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);
composer require horat1us/php-method-injection
phpunit
This project is open-sourced software licensed under the MIT license, (*8)
PHP Trait to inject methods
MIT
PHP Trait to inject methods
MIT