Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jclaveau/php-visibility-violator

Library to violate the defined visibility of methods and properties for testing purpose
https://github.com/jclaveau/php-visibility-violator

Last synced: 2 days ago
JSON representation

Library to violate the defined visibility of methods and properties for testing purpose

Awesome Lists containing this project

README

        

PHP Visibility Violator
=============================

This class provides simple helpers uppon basic features of the [Reflection API](https://secure.php.net/manual/en/book.reflection.php) to violate the [visibility](http://php.net/manual/en/language.oop5.visibility.php) of properties and methods:

+ Modify or access privates properties of classes and instances
+ Call privates or protected methods

## Quality
[![Build Status](https://travis-ci.org/jclaveau/php-logical-filter.png?branch=master)](https://travis-ci.org/jclaveau/php-visibility-violator)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jclaveau/php-visibility-violator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jclaveau/php-visibility-violator/?branch=master)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/jclaveau/php-visibility-violator/issues)
[![Viewed](http://hits.dwyl.com/jclaveau/php-visibility-violator.svg)](http://hits.dwyl.com/jclaveau/php-visibility-violator)

## Installation
The Visibility Violator is available via composer

```
composer require jclaveau/php-visibility-violator
```

## Usage

```php
use JClaveau\VisibilityViolator\VisibilityViolator;

$value = VisibilityViolator::getHiddenProperty($instance, 'property');
$value = VisibilityViolator::getHiddenProperty(MyClass::class, 'static_property');

VisibilityViolator::setHiddenProperty($instance, 'property', 'new value');
VisibilityViolator::setHiddenProperty(MyClass::class, 'static_property', 'new value');

$return = VisibilityViolator::callHiddenMethod($instance, 'method', $arguments);
$return = VisibilityViolator::callHiddenMethod(MyClass::class, 'staticMethod', ['argument 1', 'argument 2']);
```

## Documentation
+ [API Reference](docs)
+ [PHP Visibility Documentation](http://php.net/manual/en/language.oop5.visibility.php)
+ [PHP Reflection Documentation](https://secure.php.net/manual/en/book.reflection.php)
+ [Tests](tests/unit/VisibilityViolatorTest.php)