Exemplo n.º 1
0
 /**
  * Setup a monkey patch.
  *
  * @param string $source A fully namespaced reference string.
  * @param string $dest   A fully namespaced reference string.
  */
 public static function patch($source, $dest = null)
 {
     $source = ltrim($source, '\\');
     if (is_object($source) || class_exists($source)) {
         $reference = $source;
     } else {
         $reference = null;
         if (MonkeyPatcher::blacklisted($source)) {
             throw new Exception("Monkey patching `{$source}()` is not supported by Kahlan.");
         }
     }
     $method = static::$_registered[$source] = new Method(compact('reference'));
     if (!$dest) {
         return $method;
     }
     $method->toBe($dest);
     return $method;
 }
Exemplo n.º 2
0
            $nodes = Parser::parse(file_get_contents($this->path . '/Trait.php'));
            $expected = file_get_contents($this->path . '/TraitProcessed.php');
            $actual = Parser::unparse($this->patcher->process($nodes));
            expect($actual)->toBe($expected);
        });
        it("patches plain php file", function () {
            $nodes = Parser::parse(file_get_contents($this->path . '/Plain.php'));
            $expected = file_get_contents($this->path . '/PlainProcessed.php');
            $actual = Parser::unparse($this->patcher->process($nodes));
            expect($actual)->toBe($expected);
        });
        it("patches errored php file", function () {
            $nodes = Parser::parse(file_get_contents($this->path . '/Errored.php'));
            $expected = file_get_contents($this->path . '/ErroredProcessed.php');
            $actual = Parser::unparse($this->patcher->process($nodes));
            expect($actual)->toBe($expected);
        });
    });
    describe("->patchable()", function () {
        it("return `true`", function () {
            expect($this->patcher->patchable('SomeClass'))->toBe(true);
        });
    });
    describe("::blacklisted()", function () {
        it("checks that blacklisted function returns `false`", function () {
            foreach (Monkey::blacklisted() as $name) {
                expect(Monkey::blacklisted($name))->toBe(true);
            }
        });
    });
});