Kahlan\Spec\Fixture\Plugin\Monkey\Mon::datetime PHP Method

datetime() public method

public datetime ( $datetime = 'now' )
    public function datetime($datetime = 'now')
    {
        return new \DateTime($datetime);
    }

Usage Example

Esempio n. 1
0
     $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();
     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');