diff --git a/Resources/doc/symfony7_integration.md b/Resources/doc/symfony7_integration.md index 76e77ce..51eac8e 100644 --- a/Resources/doc/symfony7_integration.md +++ b/Resources/doc/symfony7_integration.md @@ -159,4 +159,4 @@ final class ErrbitExceptionSubscriber implements EventSubscriberInterface - **Autoconfigure**: With `autoconfigure: true`, Symfony automatically detects `#[AsEventListener]` attributes and registers them - **Priority**: Use priority `0` or lower to let Symfony's error handler run first if you want the normal error page to display - **Async mode**: The `async => true` option uses UDP for non-blocking error reporting -- **Symfony 7.4+**: Supports union types in event listener method signatures +- **Type declarations**: When running on PHP 8+, you can use union types in event listener method signatures diff --git a/src/Errbit/Errbit.php b/src/Errbit/Errbit.php index f346af5..954078c 100644 --- a/src/Errbit/Errbit.php +++ b/src/Errbit/Errbit.php @@ -54,7 +54,7 @@ public static function instance() * This is made public for flexibility, though it is not expected you * should use it. * - * @param array $config the configuration for the API + * @param array $config the configuration for the API */ public function __construct(private array $config = []) { @@ -102,7 +102,7 @@ public function onNotify($callback): static * - params_filters * - backtrace_filters * - * @param array $config + * @param array $config * * @return static the current instance of the client * @throws \Errbit\Exception\ConfigurationException @@ -116,7 +116,7 @@ public function configure(array $config = []): static } /** - * @param array $handlers + * @param array $handlers * * @return $this * @throws \Errbit\Exception\Exception @@ -133,7 +133,7 @@ public function start(array $handlers = ['exception', 'error', 'fatal']): static * Notify an individual exception manually. * * @param \Throwable $exception - * @param array $options + * @param array $options * * @return static [Errbit] the current instance * @throws \Errbit\Exception\ConfigurationException @@ -142,8 +142,9 @@ public function notify(\Throwable $exception, array $options = []): static { $this->checkConfig(); $config = array_merge($this->config, $options); - - if ($this->shouldNotify($exception, $config['skipped_exceptions'])) { + /** @var array> $skippedExceptions */ + $skippedExceptions = $config['skipped_exceptions']; + if ($this->shouldNotify($exception, $skippedExceptions)) { $this->getWriter()->write($exception, $config); $this->notifyObservers($exception, $config); } @@ -153,7 +154,7 @@ public function notify(\Throwable $exception, array $options = []): static /** * @param \Throwable $exception - * @param array $skippedExceptions + * @param array> $skippedExceptions * * @return bool */ @@ -165,7 +166,9 @@ protected function shouldNotify(\Throwable $exception, array $skippedExceptions) } } $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? ''; - foreach ($this->config['ignore_user_agent'] as $ua) { + /** @var array $ignoreUserAgents */ + $ignoreUserAgents = $this->config['ignore_user_agent']; + foreach ($ignoreUserAgents as $ua) { if ($userAgent !== '' && str_contains($userAgent, $ua)) { return false; } @@ -176,7 +179,7 @@ protected function shouldNotify(\Throwable $exception, array $skippedExceptions) /** * @param \Throwable $exception - * @param array $config + * @param array $config * * @return void */ diff --git a/src/Errbit/Exception/Notice.php b/src/Errbit/Exception/Notice.php index 1333c3e..5869cc8 100644 --- a/src/Errbit/Exception/Notice.php +++ b/src/Errbit/Exception/Notice.php @@ -22,11 +22,11 @@ class Notice /** * Create a new notice for the given Exception with the given $options. * - * @param mixed $exception - the exception that occurred - * @param array $options - full configuration + options + * @param \Throwable $exception - the exception that occurred + * @param array $options - full configuration + options */ public function __construct( - private mixed $exception, + private \Throwable $exception, array $options = [] ) { $this->options = array_merge( @@ -56,7 +56,7 @@ private function buildRequestUrl(): ?string $this->guessProtocol(), $this->guessHost(), $this->guessPort(), - $_SERVER['REQUEST_URI'] + (string) $_SERVER['REQUEST_URI'] ); } @@ -71,7 +71,7 @@ private function buildRequestUrl(): ?string private function guessProtocol(): string { if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) { - return $_SERVER['HTTP_X_FORWARDED_PROTO']; + return (string) $_SERVER['HTTP_X_FORWARDED_PROTO']; } elseif (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) { return 'https'; } else { @@ -87,9 +87,9 @@ private function guessProtocol(): string private function guessHost(): string { if (!empty($_SERVER['HTTP_HOST'])) { - return $_SERVER['HTTP_HOST']; + return (string) $_SERVER['HTTP_HOST']; } elseif (!empty($_SERVER['SERVER_NAME'])) { - return $_SERVER['SERVER_NAME']; + return (string) $_SERVER['SERVER_NAME']; } else { return '127.0.0.1'; } @@ -106,10 +106,10 @@ private function guessPort(): string $_SERVER['SERVER_PORT'], [80, 443] )) { - return sprintf(':%d', $_SERVER['SERVER_PORT']); + return sprintf(':%d', (int) $_SERVER['SERVER_PORT']); } - - return '80'; + + return ''; } /** @@ -142,9 +142,12 @@ private function filterParams(string $name): void } if (is_array($this->options['params_filters'])) { - foreach ($this->options['params_filters'] as $pattern) { - foreach ($this->options[$name] as $key => $value) { - + /** @var array $paramsFilters */ + $paramsFilters = $this->options['params_filters']; + foreach ($paramsFilters as $pattern) { + /** @var array $params */ + $params = $this->options[$name]; + foreach ($params as $key => $value) { if (preg_match($pattern, (string)$key)) { $this->options[$name][$key] = '[FILTERED]'; } @@ -158,13 +161,13 @@ private function filterParams(string $name): void /** * Convenience method to instantiate a new notice. * - * @param mixed $exception - Exception - * @param array $options - array of options + * @param \Throwable $exception - Exception + * @param array $options - array of options * * @return Notice */ public static function forException( - mixed $exception, + \Throwable $exception, array $options = [] ): Notice { return new self($exception, $options); @@ -187,7 +190,7 @@ public function asXml(): string '', ['version' => Errbit::API_VERSION], function (XmlBuilder $notice) use ($exception, $options, $self) { - $notice->tag('api-key', $options['api_key']); + $notice->tag('api-key', (string) ($options['api_key'] ?? '')); $notice->tag( 'notifier', '', @@ -198,7 +201,7 @@ function (XmlBuilder $notifier) { $notifier->tag('url', Errbit::PROJECT_URL); } ); - + $notice->tag( 'error', '', @@ -225,7 +228,7 @@ function (XmlBuilder $backtrace) use ( $self ) { $trace = $exception->getTrace(); - + $file1 = $exception->getFile(); $backtrace->tag( 'line', @@ -238,7 +241,7 @@ function (XmlBuilder $backtrace) use ( 'method' => "", ] ); - + // if there is no trace we should add an empty element if (empty($trace)) { $backtrace->tag( @@ -251,7 +254,9 @@ function (XmlBuilder $backtrace) use ( ] ); } else { + /** @var array> $trace */ foreach ($trace as $frame) { + /** @var array $frame */ $backtrace->tag( 'line', '', @@ -259,7 +264,7 @@ function (XmlBuilder $backtrace) use ( 'number' => $frame['line'] ?? 0, 'file' => isset($frame['file']) ? $self->filterTrace( - $frame['file'] + (string) $frame['file'] ) : '', 'method' => $self->filterTrace( $self->formatMethod($frame) @@ -272,7 +277,7 @@ function (XmlBuilder $backtrace) use ( ); } ); - + if (!empty($options['url']) || !empty($options['controller']) || !empty($options['action']) @@ -287,56 +292,62 @@ function (XmlBuilder $backtrace) use ( function (XmlBuilder $request) use ($options) { $request->tag( 'url', - !empty($options['url']) ? $options['url'] : '' + !empty($options['url']) ? (string) $options['url'] : '' ); $request->tag( 'component', - !empty($options['controller']) ? $options['controller'] : '' + !empty($options['controller']) ? (string) $options['controller'] : '' ); $request->tag( 'action', - !empty($options['action']) ? $options['action'] : '' + !empty($options['action']) ? (string) $options['action'] : '' ); - if (!empty($options['parameters'])) { + if (!empty($options['parameters']) && is_array($options['parameters'])) { $request->tag( 'params', '', [], function (XmlBuilder $params) use ($options ) { + /** @var array $parameters */ + $parameters = $options['parameters']; Notice::xmlVarsFor( $params, - $options['parameters'] + $parameters ); } ); } - - if (!empty($options['session_data'])) { + + if (!empty($options['session_data']) && is_array($options['session_data'])) { $request->tag( 'session', '', [], function (XmlBuilder $session) use ($options ) { + /** @var array $sessionData */ + $sessionData = $options['session_data']; Notice::xmlVarsFor( $session, - $options['session_data'] + $sessionData ); } ); } - - if (!empty($options['cgi_data'])) { + + if (!empty($options['cgi_data']) && is_array($options['cgi_data'])) { $request->tag( 'cgi-data', '', [], function (XmlBuilder $cgiData) use ($options ) { + /** @var array $cgiDataArr */ + $cgiDataArr = $options['cgi_data']; Notice::xmlVarsFor( $cgiData, - $options['cgi_data'] + $cgiDataArr ); } ); @@ -344,27 +355,29 @@ function (XmlBuilder $cgiData) use ($options } ); } - - if (!empty($options['user'])) { + + if (!empty($options['user']) && is_array($options['user'])) { $notice->tag( 'user-attributes', '', [], function (XmlBuilder $user) use ($options) { - Notice::xmlVarsFor($user, $options['user']); + /** @var array $userData */ + $userData = $options['user']; + Notice::xmlVarsFor($user, $userData); } ); } - + $notice->tag( 'server-environment', '', [], function (XmlBuilder $env) use ($options) { - $env->tag('project-root', $options['project_root']); + $env->tag('project-root', (string) ($options['project_root'] ?? '')); $env->tag( 'environment-name', - $options['environment_name'] + (string) ($options['environment_name'] ?? '') ); } ); @@ -432,16 +445,19 @@ public function filterTrace(string $str): string } foreach ($this->options['backtrace_filters'] as $pattern => $replacement) { - $str = preg_replace($pattern, (string)$replacement, $str); + $result = preg_replace((string) $pattern, (string)$replacement, $str); + if ($result !== null) { + $str = $result; + } } - + return $str; } /** * Extract a human-readable method/function name from the given stack frame. * - * @param array $frame - a single entry for the backtrace + * @param array $frame - a single entry for the backtrace * * @return string - the name of the method/function */ @@ -450,14 +466,14 @@ public static function formatMethod(array $frame): string if (!empty($frame['class']) && !empty($frame['type']) && !empty($frame['function'])) { return sprintf( '%s%s%s()', - $frame['class'], - $frame['type'], - $frame['function'] + (string) $frame['class'], + (string) $frame['type'], + (string) $frame['function'] ); } else { return sprintf( '%s()', - !empty($frame['function']) ? $frame['function'] : '' + !empty($frame['function']) ? (string) $frame['function'] : '' ); } } @@ -467,23 +483,20 @@ public static function formatMethod(array $frame): string * * @param \Errbit\Utils\XmlBuilder $builder the builder instance to set the * data into - * @param array $array the stack frame entry + * @param array $array the stack frame entry * * @return void */ public static function xmlVarsFor(XmlBuilder $builder, array $array): void { - foreach ($array as $key => $value) { if (is_object($value)) { - $hash = spl_object_hash($value); - $value = (array)$value; } else { $hash = null; } - + if (is_array($value)) { if (null === $hash || !in_array($hash, self::$hashArray)) { self::$hashArray[] = $hash; @@ -491,7 +504,7 @@ public static function xmlVarsFor(XmlBuilder $builder, array $array): void 'var', '', ['key' => $key], - function ($var) use ($value) { + function (XmlBuilder $var) use ($value) { Notice::xmlVarsFor($var, $value); }, true @@ -503,9 +516,8 @@ function ($var) use ($value) { ['key' => $key] ); } - } else { - $builder->tag('var', $value, ['key' => $key]); + $builder->tag('var', (string) $value, ['key' => $key]); } } } diff --git a/src/Errbit/Handlers/ErrorHandlers.php b/src/Errbit/Handlers/ErrorHandlers.php index 0ee15df..73fdd7b 100644 --- a/src/Errbit/Handlers/ErrorHandlers.php +++ b/src/Errbit/Handlers/ErrorHandlers.php @@ -21,7 +21,7 @@ class ErrorHandlers /** * @param \Errbit\Errbit $errbit - * @param array $handlers + * @param array $handlers * * @return void */ @@ -32,9 +32,9 @@ public static function register(Errbit $errbit, array $handlers = ['exception', /** * @param \Errbit\Errbit $errbit - * @param array $handlers + * @param array $handlers */ - public function __construct(private Errbit $errbit, array $handlers=[]) + public function __construct(private Errbit $errbit, array $handlers = []) { $this->install($handlers); $this->converter = Converter::createDefault(); @@ -50,21 +50,25 @@ public function __construct(private Errbit $errbit, array $handlers=[]) * @param string $file error file * @param int $line * + * @return bool * @throws \Errbit\Exception\Exception */ - public function onError(int $code, string $message, string $file, int $line): void + public function onError(int $code, string $message, string $file, int $line): bool { $exception = $this->converter->convert($code, $message, null, $file, $line, debug_backtrace()); $this->errbit->notify($exception); + return false; } /** * On exception * - * @throws \Exception + * @param \Throwable $exception + * @return void + * @throws \Errbit\Exception\ConfigurationException */ - public function onException(\Exception $exception): void + public function onException(\Throwable $exception): void { $error = $this->converter->convert( $exception->getCode(), @@ -94,7 +98,7 @@ public function onShutdown(): void /** * Installer * - * @param array $handlers + * @param array $handlers */ private function install(array $handlers): void { diff --git a/src/Errbit/Utils/XmlBuilder.php b/src/Errbit/Utils/XmlBuilder.php index 781655f..c418ffc 100644 --- a/src/Errbit/Utils/XmlBuilder.php +++ b/src/Errbit/Utils/XmlBuilder.php @@ -41,44 +41,32 @@ public function __construct(?\SimpleXMLElement $xml = null) /** * Insert a tag into the XML. * - * @param string $name the name of the tag, required. - * @param string $value the text value of the element, optional - * @param array $attributes an array of attributes for the tag, optional - * @param Callable $callback a callback to receive an XmlBuilder for the new tag, optional + * @param string $name the name of the tag, required. + * @param mixed $value the text value of the element, optional + * @param array $attributes an array of attributes for the tag, optional + * @param callable|null $callback a callback to receive an XmlBuilder for the new tag, optional + * @param bool $getLastChild whether to get the last child element * * @return XmlBuilder a builder for the inserted tag */ - /** - * Insert a tag into the XML. - * - * @param string $name the name of the tag, required. - * @param string $value the text value of the element, optional - * @param array $attributes an array of attributes for the tag, optional - * @param Callable $callback a callback to receive an XmlBuilder for the new tag, optional - * - * @return XmlBuilder a builder for the inserted tag - */ - public function tag($name, $value = '', $attributes = [], $callback = null, bool $getLastChild = false) + public function tag(string $name, mixed $value = '', array $attributes = [], ?callable $callback = null, bool $getLastChild = false): XmlBuilder { - $idx = is_countable($this->_xml->$name) ? count($this->_xml->$name) : 0; - if (is_object($value)) { - $value = "[" . $value::class . "]"; - } else { - $value = (string) $value; - } - - $this->_xml->{$name}[$idx] = $value; + $this->_xml->{$name}[$idx] = $this->normalizeValue($value); foreach ($attributes as $attr => $v) { - $this->_xml->{$name}[$idx][$attr] = $v; + $this->_xml->{$name}[$idx][$attr] = $this->normalizeValue($v); } $node = new self($this->_xml->$name); if ($getLastChild) { $array = $this->_xml->xpath($name."[last()]"); - $xml = array_shift($array); - $node = new self($xml); + if (is_array($array)) { + $xml = array_shift($array); + if ($xml instanceof \SimpleXMLElement) { + $node = new self($xml); + } + } } if ($callback) { @@ -98,11 +86,43 @@ public function tag($name, $value = '', $attributes = [], $callback = null, bool */ public function attribute($name, $value): static { - $this->_xml[$name] = $value; + $this->_xml[$name] = $this->normalizeValue($value); return $this; } + /** + * Cast any scalar or object value into a string for XML nodes. + */ + private function normalizeValue(mixed $value): string + { + if ($value instanceof \Stringable) { + return (string) $value; + } + + if (is_object($value)) { + return sprintf('[%s]', $value::class); + } + + if (is_bool($value)) { + return $value ? 'true' : 'false'; + } + + if (null === $value) { + return ''; + } + + if (is_resource($value)) { + return sprintf('[resource:%s]', get_resource_type($value)); + } + + if (is_array($value)) { + return '[array]'; + } + + return (string) $value; + } + /** * Return this XmlBuilder as a string of XML. * @@ -110,7 +130,8 @@ public function attribute($name, $value): static */ public function asXml(): string { - return self::utf8ForXML($this->_xml->asXML()); + $xml = $this->_xml->asXML(); + return self::utf8ForXML($xml !== false ? $xml : ''); } /** diff --git a/src/Errbit/Writer/AbstractWriter.php b/src/Errbit/Writer/AbstractWriter.php index 8fceaab..01f1d6b 100644 --- a/src/Errbit/Writer/AbstractWriter.php +++ b/src/Errbit/Writer/AbstractWriter.php @@ -11,6 +11,7 @@ abstract class AbstractWriter */ public const NOTICES_PATH = '/notifier_api/v2/notices/'; /** + * @param array $config * @return string */ protected function buildConnectionScheme(array $config): string @@ -23,13 +24,13 @@ protected function buildConnectionScheme(array $config): string } else { $proto = 'tcp'; } - - return sprintf('%s://%s', $proto, $config['host']); + + return sprintf('%s://%s', $proto, (string) $config['host']); } /** * @param \Throwable $exception - * @param array $options + * @param array $options * * @return string */ diff --git a/src/Errbit/Writer/GuzzleWriter.php b/src/Errbit/Writer/GuzzleWriter.php index 9f6debb..b2094cb 100644 --- a/src/Errbit/Writer/GuzzleWriter.php +++ b/src/Errbit/Writer/GuzzleWriter.php @@ -12,7 +12,7 @@ class GuzzleWriter extends AbstractWriter implements WriterInterface { /** - * @param array $config + * @param array $config * * @return string */ @@ -23,7 +23,8 @@ protected function buildConnectionScheme(array $config): string } else { $proto = 'http'; } - return sprintf('%s://%s%s', $proto, $config['host'], (isset($config['port']) ? ':' . $config['port'] : '')); + $port = isset($config['port']) ? ':' . $config['port'] : ''; + return sprintf('%s://%s%s', $proto, (string) $config['host'], $port); } public function __construct(private readonly ClientInterface $client) @@ -32,56 +33,65 @@ public function __construct(private readonly ClientInterface $client) /** * @param \Throwable $exception - * @param array $config + * @param array $config * * @return ResponseInterface|PromiseInterface * @throws \GuzzleHttp\Exception\GuzzleException */ public function write(\Throwable $exception, array $config): mixed { - if($config['async']) { + if ($config['async']) { return $this->asyncWrite($exception, $config); } return $this->synchronousWrite($exception, $config); - } - + /** + * @param \Throwable $exception + * @param array $config * + * @return ResponseInterface * @throws \GuzzleHttp\Exception\GuzzleException */ - public function synchronousWrite(\Throwable $exception, array $config): ResponseInterface + public function synchronousWrite(\Throwable $exception, array $config): ResponseInterface { $uri = $this->buildConnectionScheme($config); $body = $this->buildNoticeFor($exception, $config); - - return $this->client->post( - uri: $uri.self::NOTICES_PATH, - options: [ - 'body' =>$body, - 'connect_timout' => $config['connect_timeout'], - 'headers'=>[ - 'Content-Type'=>'text/xml', - 'Accept'=>'text/xml, application/xml' + + return $this->client->request( + 'POST', + $uri . self::NOTICES_PATH, + [ + 'body' => $body, + 'connect_timeout' => $config['connect_timeout'], + 'headers' => [ + 'Content-Type' => 'text/xml', + 'Accept' => 'text/xml, application/xml' ] ] ); } - + + /** + * @param \Throwable $exception + * @param array $config + * + * @return PromiseInterface + */ public function asyncWrite(\Throwable $exception, array $config): PromiseInterface { $uri = $this->buildConnectionScheme($config); - $promise = $this->client->postAsync( - $uri.self::NOTICES_PATH, + return $this->client->requestAsync( + 'POST', + $uri . self::NOTICES_PATH, [ - 'body' =>$this->buildNoticeFor($exception, $config), - 'connect_timout' => $config['connect_timeout'], - 'headers'=>[ - 'Content-Type'=>'text/xml', - 'Accept'=>'text/xml, application/xml' + 'body' => $this->buildNoticeFor($exception, $config), + 'connect_timeout' => $config['connect_timeout'], + 'headers' => [ + 'Content-Type' => 'text/xml', + 'Accept' => 'text/xml, application/xml' ] ] ); - return $promise; } } diff --git a/src/Errbit/Writer/SocketWriter.php b/src/Errbit/Writer/SocketWriter.php index 5d34d60..78f0f3b 100644 --- a/src/Errbit/Writer/SocketWriter.php +++ b/src/Errbit/Writer/SocketWriter.php @@ -13,7 +13,7 @@ class SocketWriter extends AbstractWriter implements WriterInterface * {@inheritdoc} * * @param \Throwable $exception - * @param array $config + * @param array $config * * @return mixed * @throws \JsonException @@ -25,25 +25,26 @@ public function write(\Throwable $exception, array $config): mixed (int) $config['port'], $errno, $errstr, - $config['connect_timeout'] + (float) $config['connect_timeout'] ); if ($socket) { - stream_set_timeout($socket, $config['write_timeout']); + stream_set_timeout($socket, (int) $config['write_timeout']); $payLoad = $this->buildPayload($exception, $config); - if (strlen((string) $payLoad) > 7000 && $config['async']) { + if (strlen($payLoad) > 7000 && $config['async']) { $messageId = uniqid('', true); - $chunks = str_split((string) $payLoad, 7000); + $chunks = str_split($payLoad, 7000); + $lastIndex = count($chunks) - 1; foreach ($chunks as $idx => $chunk) { $packet = ['messageid' => $messageId, 'data' => $chunk]; - if ($idx == count($chunks)-1) { + if ($idx === $lastIndex) { $packet['last'] = true; } $fragment = json_encode($packet, JSON_THROW_ON_ERROR); fwrite($socket, $fragment); } } else { - fwrite($socket, (string) $payLoad); + fwrite($socket, $payLoad); /** * If errbit is behind a proxy, then we need read characters to make sure @@ -52,9 +53,9 @@ public function write(\Throwable $exception, array $config): mixed * Proxies usually do not make request to endpoints if client quits connection before * proxy even gets the chance to create connection to endpoint */ - if ($this->charactersToRead !== false) { + if ($this->charactersToRead !== false && $this->charactersToRead > 0) { while (!feof($socket)) { - $character = fread($socket, $this->charactersToRead); + fread($socket, $this->charactersToRead); break; } } @@ -68,7 +69,7 @@ public function write(\Throwable $exception, array $config): mixed /** * @param \Throwable $exception - * @param array $config + * @param array $config * * @return string */ @@ -82,7 +83,7 @@ protected function buildPayload(\Throwable $exception, array $config): string /** * @param string $body - * @param array $config + * @param array $config * * @return string */ @@ -95,7 +96,15 @@ protected function addHttpHeadersIfNeeded(string $body, array $config): string "%s\r\n\r\n%s", implode( "\r\n", - [sprintf('POST %s HTTP/1.1', self::NOTICES_PATH), sprintf('Host: %s', $config['host']), sprintf('User-Agent: %s', $config['agent']), sprintf('Content-Type: %s', 'text/xml'), sprintf('Accept: %s', 'text/xml, application/xml'), sprintf('Content-Length: %d', strlen((string) $body)), sprintf('Connection: %s', 'close')] + [ + sprintf('POST %s HTTP/1.1', self::NOTICES_PATH), + sprintf('Host: %s', (string) $config['host']), + sprintf('User-Agent: %s', (string) $config['agent']), + sprintf('Content-Type: %s', 'text/xml'), + sprintf('Accept: %s', 'text/xml, application/xml'), + sprintf('Content-Length: %d', strlen($body)), + sprintf('Connection: %s', 'close') + ] ), $body ); diff --git a/src/Errbit/Writer/WriterInterface.php b/src/Errbit/Writer/WriterInterface.php index e9f1372..0166cd2 100644 --- a/src/Errbit/Writer/WriterInterface.php +++ b/src/Errbit/Writer/WriterInterface.php @@ -7,7 +7,7 @@ interface WriterInterface { /** * @param \Throwable $exception - * @param array $config + * @param array $config * * @return mixed */ diff --git a/tests/Unit/Errbit/Tests/Writer/GuzzleWriterTest.php b/tests/Unit/Errbit/Tests/Writer/GuzzleWriterTest.php index c47b35e..7c79ccb 100644 --- a/tests/Unit/Errbit/Tests/Writer/GuzzleWriterTest.php +++ b/tests/Unit/Errbit/Tests/Writer/GuzzleWriterTest.php @@ -7,7 +7,6 @@ use Errbit\Errors\Notice; use Errbit\Writer\GuzzleWriter; use GuzzleHttp\Client; -use GuzzleHttp\Promise\Promise; use GuzzleHttp\Promise\PromiseInterface; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use PHPUnit\Framework\TestCase; @@ -47,7 +46,9 @@ public function testWrite(int $error): void ]; $errbit = new Errbit($config); $clientMock = \Mockery::mock(Client::class); - $clientMock->shouldReceive('post')->once(); + $clientMock->shouldReceive('request') + ->once() + ->andReturn(\Mockery::mock(ResponseInterface::class)); $writer = new GuzzleWriter($clientMock); $errbit->setWriter($writer); $handler = new \Errbit\Handlers\ErrorHandlers($errbit, ['exception', 'error', ['fatal', 'lol', 'doink']]); @@ -81,7 +82,8 @@ public function testAsyncWrite(): void $promiseMock = \Mockery::mock(PromiseInterface::class); $clientMock = \Mockery::mock(Client::class); - $clientMock->shouldReceive('postAsync') + $clientMock + ->shouldReceive('requestAsync') ->once() ->andReturn($promiseMock); @@ -100,7 +102,8 @@ public function testSynchronousWrite(): void $responseMock = \Mockery::mock(ResponseInterface::class); $clientMock = \Mockery::mock(Client::class); - $clientMock->shouldReceive('post') + $clientMock + ->shouldReceive('request') ->once() ->andReturn($responseMock);