*/ afterAll(function () { Interceptor::load($this->previous); }); it("patches a core function", function () { $mon = new Mon(); Monkey::patch('time', 'Kahlan\\Spec\\Suite\\Plugin\\mytime'); expect($mon->time())->toBe(245026800); }); describe("::patch()", function () { it("patches a core function with a closure", function () { $mon = new Mon(); Monkey::patch('time', function () { return 123; }); expect($mon->time())->toBe(123); }); it("patches a core class", function () { $mon = new Mon(); Monkey::patch('DateTime', 'Kahlan\\Spec\\Mock\\Plugin\\Monkey\\MyDateTime'); expect($mon->datetime()->getTimestamp())->toBe(245026800); }); it("patches a core class using substitutes", function () { $mon = new Mon(); $patch = Monkey::patch('DateTime'); $patch->toBe(new DateTime('@123'), new DateTime('@456')); expect($mon->datetime()->getTimestamp())->toBe(123); expect($mon->datetime()->getTimestamp())->toBe(456); }); it("patches a function", function () { $mon = new Mon();
expect($actual['data'])->toBe(['actual' => 'time()', 'actual called times' => 0, 'expected to be called' => 'time()']); }); it("returns the description message for not received call the specified number of times", function () { $mon = new Mon(); $matcher = new ToBeCalled('time'); $matcher->times(2); $matcher->resolve(['instance' => $matcher, 'data' => ['actual' => 'time', 'logs' => []]]); $actual = $matcher->description(); expect($actual['description'])->toBe('be called the expected times.'); expect($actual['data'])->toBe(['actual' => 'time()', 'actual called times' => 0, 'expected to be called' => 'time()', 'expected called times' => 2]); }); it("returns the description message for wrong passed arguments", function () { $mon = new Mon(); $matcher = new ToBeCalled('time'); $matcher->with('Hello World!'); $mon->time(); $matcher->resolve(['instance' => $matcher, 'data' => ['actual' => 'time', 'logs' => []]]); $actual = $matcher->description(); expect($actual['description'])->toBe('be called with expected parameters.'); expect($actual['data'])->toBe(['actual' => 'time()', 'actual called times' => 1, 'actual called parameters list' => [[]], 'expected to be called' => 'time()', 'expected parameters' => ['Hello World!']]); }); }); describe("->ordered()", function () { it("throw an exception when trying to play with core instance", function () { expect(function () { $matcher = new ToBeCalled('a'); $matcher->order; })->toThrow(new Exception("Unsupported attribute `order` only `ordered` is available.")); }); }); });