ignaszak/testing-tools

v2.0.0 2017-04-17 14:02 UTC

This package is not auto-updated.

Last update: 2024-11-09 21:02:57 UTC


README

This package provides tools for testing class via reflection.

Requirements

  • PHP >= 7.0.0
  • PHPUnit >= 6.0.0

Installation

composer require ignaszak/testing-tools

Usage

Get property value

<?php

use Ignaszak\TestingTools\Test;

Test::get('propertyName', $object);

Set property value

<?php

use Ignaszak\TestingTools\Test;

// Set value
Test::inject('propertyName', 'new value', $object);
// Get value
Test::get('propertyName', $object);

Call method

<?php

use Ignaszak\TestingTools\Test;

// Call method with args
Test::call('method', ['arg1', 'arg2'], $object);
// Call method wthout args
Test::call('method', null, $object);

Define tested class

You can set instance of tested class in Test::$object.

<?php

use Ignaszak\TestingTools\Test;

Test::$object = new Example();

// All these methods refers to `Example`
Test::inject('propertyName', 'new value');
Test::inject('propertyName'); // Set null
Test::get('propertyName');
Test::call('method');
Test::call('method', ['arg1', 'arg2']);