Skip to content

Nyholm/NSA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c264c17 · Jul 15, 2021

History

47 Commits
Jul 15, 2021
Jul 15, 2021
Jul 15, 2021
Aug 6, 2016
Sep 19, 2020
Sep 19, 2020
Sep 19, 2020
Aug 6, 2016
Jul 15, 2021
Aug 6, 2016
Nov 29, 2017
Jul 15, 2021
Sep 19, 2020
Sep 19, 2020
Aug 6, 2016
Sep 19, 2020

Repository files navigation

NSA; See and do whatever you want. Great for writing tests

Latest Version Software License Build Status Code Coverage Quality Score Total Downloads

This small class helps you to test your private and protected properties and methods. One could argue that you never should test private methods but sometimes it just makes the test code a lot cleaner and easier to write and understand. This library is all about DX.

Usage

$object = new Dog();

NSA::setProperty($object, 'name', 'Foobar');
$name = NSA::getProperty($object, 'name');
$result = NSA::invokeMethod($object, 'doAction', 'jump', '1 meter');

echo $name; // "Foobar"
echo $result; // "Dog just did 'jump' for 1 meter"

// Access static properties and methods
$age = NSA::getProperty('\Dog', 'age');
echo $age; // 12
class Dog
{
    private $name = 'unnamed';
    private static $age = 12;

    private function doAction($action, $parameter)
    {
        return sprintf("Dog just did '%s' for %s", $action, $parameter);
    }
}

Install

$ composer require nyholm/nsa

License

The MIT License (MIT). Please see License File for more information.