Kahlan\Plugin\Double::instance PHP Method

instance() public static method

Creates a polyvalent instance.
public static instance ( array $options = [] ) : object
$options array Array of options. Options are: - `'class'` _string_: the fully-namespaced class name. - `'extends'` _string_: the fully-namespaced parent class name. - `'args'` _array_: arguments to pass to the constructor. - `'methods'` _string_: override the method defined.
return object The created instance.
    public static function instance($options = [])
    {
        $class = static::classname($options);
        if (isset($options['args'])) {
            $refl = new ReflectionClass($class);
            $instance = $refl->newInstanceArgs($options['args']);
        } else {
            $instance = new $class();
        }
        return $instance;
    }

Usage Example

Example #1
0
         $expectation = new Expectation();
         expect($expectation->not())->toBe(false);
         expect($expectation->not)->toBe($expectation);
         expect($expectation->not())->toBe(true);
     });
     it("throws an exception with unsupported attributes", function () {
         $closure = function () {
             $expectation = new Expectation();
             $expectation->abc;
         };
         expect($closure)->toThrow(new Exception('Unsupported attribute `abc`.'));
     });
 });
 describe("->clear()", function () {
     it("clears an expectation", function () {
         $actual = Double::instance();
         $expectation = expectation($actual, 10);
         $matcher = $expectation->not->toReceive('helloWorld');
         expect($expectation->actual())->toBe($actual);
         expect($expectation->deferred())->toBe(['matcherName' => 'toReceive', 'matcher' => 'Kahlan\\Matcher\\ToReceive', 'data' => ['actual' => $actual, 'expected' => 'helloWorld'], 'instance' => $matcher, 'not' => true]);
         expect($expectation->timeout())->toBe(10);
         expect($expectation->not())->toBe(true);
         expect($expectation->passed())->toBe(true);
         expect($expectation->logs())->toHaveLength(1);
         $expectation->clear();
         expect($expectation->actual())->toBe(null);
         expect($expectation->deferred())->toBe(null);
         expect($expectation->timeout())->toBe(-1);
         expect($expectation->not())->toBe(false);
         expect($expectation->passed())->toBe(true);
         expect($expectation->logs())->toHaveLength(0);
All Usage Examples Of Kahlan\Plugin\Double::instance