<?php namespace jtreminio\TestExtensions; /** * Some useful methods to make testing with PHPUnit faster and more fun * * @author Juan Treminio <jtreminio@gmail.com> */ abstract class TestExtensions extends \PHPUnit_Framework_TestCase { /** * Set protected/private attribute of object * * @param object &$object Object containing attribute * @param string $attributeName Attribute name to change * @param string $value Value to set attribute to * * @return null */ public function setAttribute(&$object, $attributeName, $value) { $class = is_object($object) ? get_class($object) : $object; $reflection = new \ReflectionProperty($class, $attributeName); $reflection->setAccessible(true); $reflection->setValue($object, $value); } /** * Get protected/private attribute of object * * @param object &$object Object containing attribute * @param string $attributeName Attribute name to fetch * @return mixed */ public function getAttribute(&$object, $attributeName) { $class = is_object($object) ? get_class($object) : $object; $reflection = new \ReflectionProperty($class, $attributeName); $reflection->setAccessible(true); return $reflection->getValue($object); } /** * Call protected/private method of a class. * * @param object &$object Instantiated object that we will run method on. * @param string $methodName Method name to call * @param array $parameters Array of parameters to pass into method. * * @return mixed Method return. */ public function invokeMethod(&$object, $methodName, array $parameters = array()) { $reflection = new \ReflectionClass(get_class($object)); $method = $reflection->getMethod($methodName); $method->setAccessible(true); return $method->invokeArgs($object, $parameters); } } |
Source – Github jtreminio
continuously i used to read smaller content which as well clear
their motive, and that is also happening with this piece of
writing which I am reading at this time.
thx
I am really happy to read this webpage posts which carries
tons of helpful data, thanks for providing these kinds of data.
I see your site needs some unique content. Writing
manually is time consuming, but there is solution for this.
Just search for – Masquro’s strategies
Everything is very open with a really clear description of
the issues. It was really informative. Your site is extremely helpful.
Thank you for sharing!
Hello mates, good piece of writing and fastidious arguments commented at
this place, I am genuinely enjoying by these.
It’s hard to come by well-informed people for this
topic, however, you sound like you know what you’re talking about!
Thanks
Hello, I desire to subscribe for this webpage to take most up-to-date
updates, therefore where can i do it please help.