}); }); describe("::reset()", function () { beforeEach(function () { Stub::on('kahlan\\spec\\fixture\\plugin\\pointcut\\Foo')->method('foo', function () { }); Stub::on('kahlan\\spec\\fixture\\plugin\\pointcut\\Bar')->method('bar', function () { }); }); it("clears all stubs", function () { Stub::reset(); expect(Stub::registered())->toBe([]); }); it("clears one stub", function () { Stub::reset('kahlan\\spec\\fixture\\plugin\\pointcut\\Foo'); expect(Stub::registered())->toBe(['kahlan\\spec\\fixture\\plugin\\pointcut\\Bar']); }); }); describe("::_generateAbstractMethods()", function () { it("throws an exception when called with a non-existing class", function () { expect(function () { $stub = Stub::classname(['extends' => 'kahlan\\plugin\\Stub', 'methods' => ['::generateAbstractMethods']]); Stub::on($stub)->method('::generateAbstractMethods', function ($class) { return static::_generateAbstractMethods($class); }); $stub::generateAbstractMethods('some\\unexisting\\Class'); })->toThrow(new IncompleteException('Unexisting parent class `some\\unexisting\\Class`')); }); }); describe("::create()", function () { before(function () {
}); }); describe("::reset()", function () { beforeEach(function () { Stub::on('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->method('foo', function () { }); Stub::on('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Bar')->method('bar', function () { }); }); it("clears all stubs", function () { Stub::reset(); expect(Stub::registered())->toBe([]); }); it("clears one stub", function () { Stub::reset('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo'); expect(Stub::registered())->toBe(['Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Bar']); }); }); describe("::_generateAbstractMethods()", function () { it("throws an exception when called with a non-existing class", function () { expect(function () { $stub = Stub::classname(['extends' => 'Kahlan\\Plugin\\Stub', 'methods' => ['::generateAbstractMethods']]); Stub::on($stub)->method('::generateAbstractMethods', function ($class) { return static::_generateAbstractMethods($class); }); $stub::generateAbstractMethods('some\\unexisting\\Class'); })->toThrow(new IncompleteException('Unexisting parent class `some\\unexisting\\Class`')); }); }); describe("::create()", function () { before(function () {
/** * Constructor * * @param string|object $actual A fully-namespaced class name or an object instance. * @param string $expected The expected method method name to be called. */ public function __construct($actual, $expected) { $this->_backtrace = Debugger::backtrace(); if (is_string($actual)) { $actual = ltrim($actual, '\\'); } $this->_check($actual); if (!$expected) { throw new InvalidArgumentException("Method name can't be empty."); } $names = is_array($expected) ? $expected : [$expected]; $reference = $actual; if (count($names) > 1) { if (!Stub::registered(Suite::hash($reference))) { throw new InvalidArgumentException("Kahlan can't Spy chained methods on real PHP code, you need to Stub the chain first."); } } $reference = $this->_reference($reference); foreach ($names as $index => $name) { if (preg_match('/^::.*/', $name)) { $reference = is_object($reference) ? get_class($reference) : $reference; } $this->_expected[] = $name; $this->_messages[$name] = $this->_watch(new Message(['parent' => $this, 'reference' => $reference, 'name' => $name])); $reference = null; } }