/** * A shortcut for building mocks. * * @param string $type * @param Closure|CallExpectation[] $definition * * @return $this */ public function mock($type, $definition) { Arguments::define(Boa::string(), Boa::either(Boa::func(), Boa::arrOf(Boa::instance(CallExpectation::class))))->check($type, $definition); if (is_array($definition)) { $this->provide(static::expectationsToMock($type, $definition)); return $this; } $this->provide(Mockery::mock($type, $definition)); return $this; }
/** * Attempt call the provided function a number of times until it no longer * throws an exception. * * @param callable $function * @param int $attempts * * @return mixed|null * @throws InvalidArgumentException */ public static function retry(callable $function, $attempts) { Arguments::define(Boa::func(), Boa::integer())->check($function, $attempts); for ($ii = 0; $ii < $attempts; $ii++) { try { $result = static::call($function, $ii); return $result; } catch (Exception $e) { continue; } } return null; }