Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: namespace PHPUnit\Framework\MockObject\Stub; Chris@14: Chris@14: use PHPUnit\Framework\MockObject\Invocation; Chris@14: use PHPUnit\Framework\MockObject\Stub; Chris@14: use SebastianBergmann\Exporter\Exporter; Chris@14: Chris@14: /** Chris@14: * Stubs a method by raising a user-defined exception. Chris@14: */ Chris@14: class Exception implements Stub Chris@14: { Chris@14: private $exception; Chris@14: Chris@14: public function __construct(\Throwable $exception) Chris@14: { Chris@14: $this->exception = $exception; Chris@14: } Chris@14: Chris@14: public function invoke(Invocation $invocation) Chris@14: { Chris@14: throw $this->exception; Chris@14: } Chris@14: Chris@14: public function toString() Chris@14: { Chris@14: $exporter = new Exporter; Chris@14: Chris@14: return \sprintf( Chris@14: 'raise user-specified exception %s', Chris@14: $exporter->export($this->exception) Chris@14: ); Chris@14: } Chris@14: }