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(); Monkey::patch('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\rand', 'Kahlan\\Spec\\Suite\\Plugin\\myrand'); expect($mon->rand(0, 100))->toBe(101); }); it("patches a class", function () { $mon = new Mon(); Monkey::patch('Kahlan\\Util\\Text', 'Kahlan\\Spec\\Mock\\Plugin\\Monkey\\MyString'); expect($mon->dump((object) 'hello'))->toBe('myhashvalue'); }); it("can unpatch a monkey patch", function () { $mon = new Mon(); Monkey::patch('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\rand', 'Kahlan\\Spec\\Suite\\Plugin\\myrand'); expect($mon->rand(0, 100))->toBe(101); Monkey::reset('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\rand'); expect($mon->rand(0, 100))->toBe(50); }); it("throws an exception with trying to patch an unsupported functions or core langage statements", function () { $closure = function () { Monkey::patch('func_get_args', function () { return []; }); }; expect($closure)->toThrow(new Exception('Monkey patching `func_get_args()` is not supported by Kahlan.'));