summaryrefslogtreecommitdiffstats
path: root/test/unit/TestUtils/ClassUtils.php
blob: b25ca560d3d316263368b931e1c2903b667993ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

namespace SparkPost\Test\TestUtils;

class ClassUtils
{
    private $class;

    public function __construct($fqClassName)
    {
        $this->class = new \ReflectionClass($fqClassName);
    }

    /**
     * Allows access to private methods.
     *
     * This is needed to mock the GuzzleHttp\Client responses
     *
     * @param string $name
     *
     * @return ReflectionMethod
     */
    public function getMethod($method)
    {
        $method = $this->class->getMethod($name);
        $method->setAccessible(true);

        return $method;
    }

    /**
     * Allows access to private properties in the Transmission class.
     *
     * This is needed to mock the GuzzleHttp\Client responses
     *
     * @param string $name
     * @param {*}
     *
     * @return ReflectionMethod
     */
    public function getProperty($instance, $property)
    {
        $prop = $this->class->getProperty($property);
        $prop->setAccessible(true);

        return $prop->getValue($instance);
    }
    /**
     * Allows access to private properties in the Transmission class.
     *
     * This is needed to mock the GuzzleHttp\Client responses
     *
     * @param string $name
     * @param {*}
     *
     * @return ReflectionMethod
     */
    public function setProperty($instance, $property, $value)
    {
        $prop = $this->class->getProperty($property);
        $prop->setAccessible(true);
        $prop->setValue($instance, $value);
    }
}