diff --git a/src/Shared/Logger/Configurator/MonologLevelConfiguratorTrait.php b/src/Shared/Logger/Configurator/MonologLevelConfiguratorTrait.php index edd7c5c..dd4f9e7 100644 --- a/src/Shared/Logger/Configurator/MonologLevelConfiguratorTrait.php +++ b/src/Shared/Logger/Configurator/MonologLevelConfiguratorTrait.php @@ -10,7 +10,8 @@ trait MonologLevelConfiguratorTrait /** * The minimum logging level at which this handler will be triggered */ - protected Level $logLevel; + protected Level $logLevel = Level::Debug; + public function getLogLevel(): Level { @@ -41,4 +42,14 @@ public function hasLogLevel(): bool { return isset($this->logLevel); } + + public function getFilePermission(): int + { + return 644; + } + + public function useLocking(): bool + { + return false; + } } diff --git a/tests/stub/Plugin/Stream/FactoryStub.php b/tests/stub/Plugin/Stream/FactoryStub.php index 4e2686c..2fc55be 100644 --- a/tests/stub/Plugin/Stream/FactoryStub.php +++ b/tests/stub/Plugin/Stream/FactoryStub.php @@ -12,6 +12,6 @@ class FactoryStub implements PluginFactoryInterface { public function create(PluginConfiguratorInterface $configurator): LoggerPluginInterface { - return new StreamLoggerPluginStub($configurator); + return new HandlerExceptionLoggerPluginStub($configurator); } } diff --git a/tests/stub/Plugin/Stream/StreamLoggerPluginConfiguratorStub.php b/tests/stub/Plugin/Stream/StreamLoggerPluginConfiguratorStub.php index 7952500..85ff81a 100644 --- a/tests/stub/Plugin/Stream/StreamLoggerPluginConfiguratorStub.php +++ b/tests/stub/Plugin/Stream/StreamLoggerPluginConfiguratorStub.php @@ -3,10 +3,8 @@ namespace EveronLoggerTests\Stub\Plugin\Stream; use Everon\Logger\Contract\Configurator\PluginConfiguratorInterface; +use Everon\Logger\Exception\ConfiguratorValidationException; use Everon\Shared\Logger\Configurator\MonologLevelConfiguratorTrait; -use UnexpectedValueException; -use function array_key_exists; -use function is_array; /** * Code generated by POPO generator, do not edit. @@ -16,606 +14,74 @@ class StreamLoggerPluginConfiguratorStub implements PluginConfiguratorInterface { use MonologLevelConfiguratorTrait; - public const PLUGIN_CLASS = 'pluginClass'; - public const PLUGIN_FACTORY_CLASS = 'pluginFactoryClass'; - public const SHOULD_BUBBLE = 'shouldBubble'; - public const STREAM_LOCATION = 'streamLocation'; - public const FILE_PERMISSION = 'filePermission'; - public const USE_LOCKING = 'useLocking'; - - protected const METADATA = [ - 'pluginClass' => [ - 'type' => 'string', - 'default' => \Everon\Logger\Plugin\Stream\StreamLoggerPlugin::class, - 'mappingPolicy' => [], - 'mappingPolicyValue' => 'pluginClass', - ], - 'pluginFactoryClass' => [ - 'type' => 'string', - 'default' => null, - 'mappingPolicy' => [], - 'mappingPolicyValue' => 'pluginFactoryClass', - ], - 'shouldBubble' => [ - 'type' => 'bool', - 'default' => true, - 'mappingPolicy' => [], - 'mappingPolicyValue' => 'shouldBubble', - ], - 'streamLocation' => [ - 'type' => 'string', - 'default' => null, - 'mappingPolicy' => [], - 'mappingPolicyValue' => 'streamLocation', - ], - 'filePermission' => [ - 'type' => 'int', - 'default' => 644, - 'mappingPolicy' => [], - 'mappingPolicyValue' => 'filePermission', - ], - 'useLocking' => ['type' => 'bool', 'default' => false, 'mappingPolicy' => [], 'mappingPolicyValue' => 'useLocking'], - ]; - - protected array $updateMap = []; - protected ?string $pluginClass = \Everon\Logger\Plugin\Stream\StreamLoggerPlugin::class; - - /** Defines custom plugin factory to be used to create a plugin */ - protected ?string $pluginFactoryClass = null; - - /** Whether the messages that are handled can bubble up the stack or not */ - protected bool $shouldBubble = true; - - /** If a missing path can't be created, an UnexpectedValueException will be thrown on first write. */ - protected ?string $streamLocation = null; - - /** Optional file permissions (default (0644) are only for owner read/write). */ - protected ?int $filePermission = 644; - - /** Try to lock log file before doing any writes. */ - protected bool $useLocking = false; - - protected function setupDateTimeProperty($propertyName): void - { - if (self::METADATA[$propertyName]['type'] === 'datetime' && $this->$propertyName === null) { - $value = self::METADATA[$propertyName]['default'] ?: 'now'; - $datetime = new DateTime($value); - $timezone = self::METADATA[$propertyName]['timezone'] ?? null; - if ($timezone !== null) { - $timezone = new DateTimeZone($timezone); - $datetime = new DateTime($value, $timezone); - } - $this->$propertyName = $datetime; - } - } - - public function isNew(): bool - { - return empty($this->updateMap) === true; - } - - public function listModifiedProperties(): array - { - $sorted = array_keys($this->updateMap); - sort($sorted, SORT_STRING); - return $sorted; - } - - public function modifiedToArray(): array - { - $data = $this->toArray(); - $modifiedProperties = $this->listModifiedProperties(); - - return array_filter($data, function ($key) use ($modifiedProperties) { - return in_array($key, $modifiedProperties); - }, ARRAY_FILTER_USE_KEY); - } - - protected function setupPopoProperty($propertyName): void - { - if (self::METADATA[$propertyName]['type'] === 'popo' && $this->$propertyName === null) { - $popo = self::METADATA[$propertyName]['default']; - $this->$propertyName = new $popo; - } - } - - public function requireAll(): self - { - $errors = []; - - try { - $this->requirePluginClass(); - } - catch (Throwable $throwable) { - $errors['pluginClass'] = $throwable->getMessage(); - } - try { - $this->requirePluginFactoryClass(); - } - catch (Throwable $throwable) { - $errors['pluginFactoryClass'] = $throwable->getMessage(); - } - try { - $this->requireShouldBubble(); - } - catch (Throwable $throwable) { - $errors['shouldBubble'] = $throwable->getMessage(); - } - try { - $this->requireStreamLocation(); - } - catch (Throwable $throwable) { - $errors['streamLocation'] = $throwable->getMessage(); - } - try { - $this->requireFilePermission(); - } - catch (Throwable $throwable) { - $errors['filePermission'] = $throwable->getMessage(); - } - try { - $this->requireUseLocking(); - } - catch (Throwable $throwable) { - $errors['useLocking'] = $throwable->getMessage(); - } - - if (empty($errors) === false) { - throw new UnexpectedValueException( - implode("\n", $errors), - ); - } - - return $this; - } - - public function fromArray(array $data): self - { - $metadata = [ - 'pluginClass' => 'pluginClass', - 'pluginFactoryClass' => 'pluginFactoryClass', - 'shouldBubble' => 'shouldBubble', - 'streamLocation' => 'streamLocation', - 'filePermission' => 'filePermission', - 'useLocking' => 'useLocking', - ]; - - - foreach ($metadata as $name => $mappedName) { - $meta = self::METADATA[$name]; - $value = $data[$mappedName] ?? $this->$name ?? null; - $popoValue = $meta['default']; - - if ($popoValue !== null && $meta['type'] === 'popo') { - $popo = new $popoValue; - - if (is_array($value)) { - $popo->fromArray($value); - } - - $value = $popo; - } - - if ($meta['type'] === 'datetime') { - if (($value instanceof DateTime) === false) { - $datetime = new DateTime($data[$name] ?? $meta['default'] ?: 'now'); - $timezone = $meta['timezone'] ?? null; - if ($timezone !== null) { - $timezone = new DateTimeZone($timezone); - $datetime = new DateTime($data[$name] ?? self::METADATA[$name]['default'] ?: 'now', $timezone); - } - $value = $datetime; - } - } - - if ($meta['type'] === 'array' && isset($meta['itemIsPopo']) && $meta['itemIsPopo']) { - $className = $meta['itemType']; - - $valueCollection = []; - foreach ($value as $popoKey => $popoValue) { - $popo = new $className; - $popo->fromArray($popoValue); - - $valueCollection[] = $popo; - } - - $value = $valueCollection; - } - - $this->$name = $value; - if (array_key_exists($mappedName, $data)) { - $this->updateMap[$name] = true; - } - } - - return $this; - } - - public function fromMappedArray(array $data, ...$mappings): self - { - $result = []; - foreach (self::METADATA as $name => $propertyMetadata) { - $mappingPolicyValue = $propertyMetadata['mappingPolicyValue']; - $inputKey = $this->mapKeyName($mappings, $mappingPolicyValue); - $value = $data[$inputKey] ?? null; - - if (self::METADATA[$name]['type'] === 'popo') { - $popo = self::METADATA[$name]['default']; - $value = $this->$name !== null - ? $this->$name->fromMappedArray($value ?? [], ...$mappings) - : (new $popo)->fromMappedArray($value ?? [], ...$mappings); - $value = $value->toArray(); - } - - $result[$mappingPolicyValue] = $value; - } - - $this->fromArray($result); - - return $this; - } + private ?string $streamLocation = null; + private string $pluginClass = StreamLoggerPluginStub::class; + private ?string $pluginFactoryClass = null; public function toArray(): array { - $metadata = [ - 'pluginClass' => 'pluginClass', - 'pluginFactoryClass' => 'pluginFactoryClass', - 'shouldBubble' => 'shouldBubble', - 'streamLocation' => 'streamLocation', - 'filePermission' => 'filePermission', - 'useLocking' => 'useLocking', - ]; - - $data = []; - - foreach ($metadata as $name => $mappedName) { - $value = $this->$name; - - if (self::METADATA[$name]['type'] === 'popo') { - $popo = self::METADATA[$name]['default']; - $value = $this->$name !== null ? $this->$name->toArray() : (new $popo)->toArray(); - } - - if (self::METADATA[$name]['type'] === 'datetime') { - if (($value instanceof DateTime) === false) { - $datetime = new DateTime(self::METADATA[$name]['default'] ?: 'now'); - $timezone = self::METADATA[$name]['timezone'] ?? null; - if ($timezone !== null) { - $timezone = new DateTimeZone($timezone); - $datetime = new DateTime($this->$name ?? self::METADATA[$name]['default'] ?: 'now', $timezone); - } - $value = $datetime; - } - - $value = $value->format(self::METADATA[$name]['format']); - } - - if (self::METADATA[$name]['type'] === 'array' && isset(self::METADATA[$name]['itemIsPopo']) && self::METADATA[$name]['itemIsPopo']) { - $valueCollection = []; - foreach ($value as $popo) { - $valueCollection[] = $popo->toArray(); - } - - $value = $valueCollection; - } - - $data[$mappedName] = $value; - } - - - return $data; - } - - public function toMappedArray(...$mappings): array - { - return $this->map($this->toArray(), $mappings); - } - - protected function map(array $data, array $mappings): array - { - $result = []; - foreach (self::METADATA as $name => $propertyMetadata) { - $value = $data[$propertyMetadata['mappingPolicyValue']]; - - if (self::METADATA[$name]['type'] === 'popo') { - $popo = self::METADATA[$name]['default']; - $value = $this->$name !== null ? $this->$name->toMappedArray(...$mappings) : (new $popo)->toMappedArray( - ...$mappings, - ); - } - - $key = $this->mapKeyName($mappings, $propertyMetadata['mappingPolicyValue']); - $result[$key] = $value; - } - - return $result; - } - - protected function mapKeyName(array $mappings, string $key): string - { - static $mappingPolicy = []; - - if (empty($mappingPolicy)) { - - $mappingPolicy['none'] = - static function (string $key): string { - return $key; - }; - - $mappingPolicy['lower'] = - static function (string $key): string { - return mb_strtolower($key); - }; - - $mappingPolicy['upper'] = - static function (string $key): string { - return mb_strtoupper($key); - }; - - $mappingPolicy['snake-to-camel'] = - static function (string $key): string { - $stringTokens = explode('_', mb_strtolower($key)); - $camelizedString = array_shift($stringTokens); - foreach ($stringTokens as $token) { - $camelizedString .= ucfirst($token); - } - - return $camelizedString; - }; - - $mappingPolicy['camel-to-snake'] = - static function (string $key): string { - $camelizedStringTokens = preg_split('/(?<=[^A-Z])(?=[A-Z])/', $key); - if ($camelizedStringTokens !== false && count($camelizedStringTokens) > 0) { - $key = mb_strtolower(implode('_', $camelizedStringTokens)); - } - - return $key; - }; - - } - - foreach ($mappings as $mappingIndex => $mappingType) { - if (!array_key_exists($mappingType, $mappingPolicy)) { - continue; - } - - $key = $mappingPolicy[$mappingType]($key); - } - - return $key; - } - - public function toArrayLower(): array - { - return $this->toMappedArray('lower'); - } - - public function toArrayUpper(): array - { - return $this->toMappedArray('upper'); - } - - public function toArraySnakeToCamel(): array - { - return $this->toMappedArray('snake-to-camel'); + return []; } - public function toArrayCamelToSnake(): array + public function fromArray(array $data): PluginConfiguratorInterface { - return $this->toMappedArray('camel-to-snake'); - } - - public function getPluginClass(): ?string - { - return $this->pluginClass; - } - - public function hasPluginClass(): bool - { - return $this->pluginClass !== null; + return $this; } public function requirePluginClass(): string { - $this->setupPopoProperty('pluginClass'); - $this->setupDateTimeProperty('pluginClass'); - - if ($this->pluginClass === null) { - throw new UnexpectedValueException('Required value of "pluginClass" has not been set'); - } return $this->pluginClass; } - public function setPluginClass(?string $pluginClass): self + public function setPluginClass(string $class): self { - $this->pluginClass = $pluginClass; - $this->updateMap['pluginClass'] = true; + $this->pluginClass = $class; + return $this; } - /** - * Defines custom plugin factory to be used to create a plugin - */ public function getPluginFactoryClass(): ?string { return $this->pluginFactoryClass; } - public function hasPluginFactoryClass(): bool - { - return $this->pluginFactoryClass !== null; - } - - /** - * Defines custom plugin factory to be used to create a plugin - */ - public function requirePluginFactoryClass(): string - { - $this->setupPopoProperty('pluginFactoryClass'); - $this->setupDateTimeProperty('pluginFactoryClass'); - - if ($this->pluginFactoryClass === null) { - throw new UnexpectedValueException('Required value of "pluginFactoryClass" has not been set'); - } - return $this->pluginFactoryClass; - } - - /** - * Defines custom plugin factory to be used to create a plugin - */ public function setPluginFactoryClass(?string $pluginFactoryClass): self { $this->pluginFactoryClass = $pluginFactoryClass; - $this->updateMap['pluginFactoryClass'] = true; + return $this; } - /** - * Whether the messages that are handled can bubble up the stack or not - */ public function shouldBubble(): ?bool { - return $this->shouldBubble; - } - - public function hasShouldBubble(): bool - { - return $this->shouldBubble !== null; + return true; } - /** - * Whether the messages that are handled can bubble up the stack or not - */ - public function requireShouldBubble(): bool + public function setStreamLocation(string $logFilename): self { - $this->setupPopoProperty('shouldBubble'); - $this->setupDateTimeProperty('shouldBubble'); + $this->streamLocation = $logFilename; - if ($this->shouldBubble === null) { - throw new UnexpectedValueException('Required value of "shouldBubble" has not been set'); - } - return $this->shouldBubble; - } - - /** - * Whether the messages that are handled can bubble up the stack or not - */ - public function setShouldBubble(bool $shouldBubble): self - { - $this->shouldBubble = $shouldBubble; - $this->updateMap['shouldBubble'] = true; return $this; } - /** - * If a missing path can't be created, an UnexpectedValueException will be thrown on first write. - */ - public function getStreamLocation(): ?string - { - return $this->streamLocation; - } - - public function hasStreamLocation(): bool - { - return $this->streamLocation !== null; - } - - /** - * If a missing path can't be created, an UnexpectedValueException will be thrown on first write. - */ public function requireStreamLocation(): string { - $this->setupPopoProperty('streamLocation'); - $this->setupDateTimeProperty('streamLocation'); - - if ($this->streamLocation === null) { - throw new UnexpectedValueException('Required value of "streamLocation" has not been set'); - } - return $this->streamLocation; - } - - /** - * If a missing path can't be created, an UnexpectedValueException will be thrown on first write. - */ - public function setStreamLocation(?string $streamLocation): self - { - $this->streamLocation = $streamLocation; - $this->updateMap['streamLocation'] = true; - return $this; - } - - /** - * Optional file permissions (default (0644) are only for owner read/write). - */ - public function getFilePermission(): ?int - { - return $this->filePermission; - } - - public function hasFilePermission(): bool - { - return $this->filePermission !== null; - } - - /** - * Optional file permissions (default (0644) are only for owner read/write). - */ - public function requireFilePermission(): int - { - $this->setupPopoProperty('filePermission'); - $this->setupDateTimeProperty('filePermission'); - - if ($this->filePermission === null) { - throw new UnexpectedValueException('Required value of "filePermission" has not been set'); + if (!isset($this->streamLocation)) { + throw new ConfiguratorValidationException( + 'Required value of "streamLocation" has not been set', + ); } - return $this->filePermission; - } - - /** - * Optional file permissions (default (0644) are only for owner read/write). - */ - public function setFilePermission(?int $filePermission): self - { - $this->filePermission = $filePermission; - $this->updateMap['filePermission'] = true; - return $this; - } - /** - * Try to lock log file before doing any writes. - */ - public function useLocking(): ?bool - { - return $this->useLocking; - } - - public function hasUseLocking(): bool - { - return $this->useLocking !== null; + return $this->streamLocation; } - /** - * Try to lock log file before doing any writes. - */ - public function requireUseLocking(): bool + public function getStreamLocation(): string { - $this->setupPopoProperty('useLocking'); - $this->setupDateTimeProperty('useLocking'); - - if ($this->useLocking === null) { - throw new UnexpectedValueException('Required value of "useLocking" has not been set'); - } - return $this->useLocking; + return $this->streamLocation; } - /** - * Try to lock log file before doing any writes. - */ - public function setUseLocking(bool $useLocking): self + public function hasStreamLocation(): bool { - $this->useLocking = $useLocking; - $this->updateMap['useLocking'] = true; - return $this; + return $this->streamLocation !== null; } } diff --git a/tests/suite/Configurator/TestLoggerConfigurator.php b/tests/suite/Configurator/TestLoggerConfigurator.php index a99d211..c035944 100644 --- a/tests/suite/Configurator/TestLoggerConfigurator.php +++ b/tests/suite/Configurator/TestLoggerConfigurator.php @@ -2,451 +2,56 @@ namespace EveronLoggerTests\Suite\Configurator; -use Everon\Shared\Logger\Configurator\MonologLevelConfiguratorTrait; -use InvalidArgumentException; -use UnexpectedValueException; -use function array_key_exists; -use function ctype_upper; -use function is_array; -use function is_object; -use function method_exists; -use function sprintf; -use function strtolower; -use function trim; - -/** - * Code generated by POPO generator, do not edit. - * https://packagist.org/packages/popo/generator - */ class TestLoggerConfigurator { - use MonologLevelConfiguratorTrait; - - protected array $data = [ - 'message' => null, - 'context' => - [ - ], - 'extra' => - [ - ], - 'delimiter' => '] everon-logger.', - ]; - - protected array $default = [ - 'message' => null, - 'context' => - [ - ], - 'extra' => - [ - ], - 'delimiter' => '] everon-logger.', - ]; - - protected array $propertyMapping = [ - 'message' => 'string', - 'context' => 'array', - 'extra' => 'array', - 'delimiter' => 'string', - ]; - - protected array $collectionItems = [ - ]; - - protected array $updateMap = []; - - /** - * @param string $property - * - * @return mixed|null - */ - protected function popoGetValue(string $property) - { - if (!isset($this->data[$property])) { - if ($this->typeIsObject($this->propertyMapping[$property])) { - $popo = new $this->propertyMapping[$property]; - $this->data[$property] = $popo; - } - else { - return null; - } - } - - return $this->data[$property]; - } - - /** - * @param string $property - * @param mixed $value - * - * @return void - */ - protected function popoSetValue(string $property, $value): void - { - $this->data[$property] = $value; - - $this->updateMap[$property] = true; - } - - /** - * @param string $property - * - * @return void - * @throws UnexpectedValueException - */ - protected function assertPropertyValue(string $property): void - { - if (!isset($this->data[$property])) { - throw new UnexpectedValueException( - sprintf( - 'Required value of "%s" has not been set', - $property, - ), - ); - } - } - - /** - * @param string $propertyName - * @param mixed $value - * - * @return void - * @throws \InvalidArgumentException - */ - protected function addCollectionItem(string $propertyName, $value): void - { - $type = trim(strtolower($this->propertyMapping[$propertyName])); - $collection = $this->popoGetValue($propertyName) ?? []; - - if (!is_array($collection) || $type !== 'array') { - throw new InvalidArgumentException('Cannot add item to non array type: ' . $propertyName); - } - - $collection[] = $value; - - $this->popoSetValue($propertyName, $collection); - } - - public function toArray(): array - { - $data = []; - - foreach ($this->propertyMapping as $key => $type) { - if (!array_key_exists($key, $data)) { - $data[$key] = $this->default[$key] ?? null; - } - $value = $this->data[$key]; - - if ($this->isCollectionItem($key) && is_array($value)) { - foreach ($value as $popo) { - if (is_object($popo) && method_exists($popo, 'toArray')) { - $data[$key][] = $popo->toArray(); - } - } - - continue; - } - - if (is_object($value) && method_exists($value, 'toArray')) { - $data[$key] = $value->toArray(); - continue; - } - - $data[$key] = $value; - } - - return $data; - } - - public function fromArray(array $data): TestLoggerConfigurator - { - foreach ($this->propertyMapping as $key => $type) { - $result[$key] = $this->default[$key] ?? null; - - if ($this->typeIsObject($type)) { - $popo = new $this->propertyMapping[$key]; - if (method_exists($popo, 'fromArray')) { - $popoData = $data[$key] ?? $this->default[$key] ?? []; - $popo->fromArray($popoData); - } - $result[$key] = $popo; - - continue; - } + use \Everon\Shared\Logger\Configurator\MonologLevelConfiguratorTrait; - if (array_key_exists($key, $data)) { - if ($this->isCollectionItem($key)) { - foreach ($data[$key] as $popoData) { - $popo = new $this->collectionItems[$key](); - if (method_exists($popo, 'fromArray')) { - $popo->fromArray($popoData); - } - $result[$key][] = $popo; - } - } - else { - $result[$key] = $data[$key]; - } - } - } + protected ?string $message; - $this->data = $result; + protected array $extra = []; - foreach ($data as $key => $value) { - if (!array_key_exists($key, $result)) { - continue; - } + protected array $context = []; - $type = $this->propertyMapping[$key] ?? null; - if ($type !== null) { - $value = $this->typecastValue($type, $result[$key]); - $this->popoSetValue($key, $value); - } - } + protected string $delimiter = '] everon-logger.'; - return $this; - } - - /** - * @param string $type - * @param mixed $value - * - * @return mixed - */ - protected function typecastValue(string $type, $value) - { - if ($value === null) { - return $value; - } - - switch ($type) { - case 'int': - $value = (int)$value; - break; - case 'string': - $value = (string)$value; - break; - case 'bool': - $value = (bool)$value; - break; - case 'array': - $value = (array)$value; - break; - } - - return $value; - } - - protected function isCollectionItem(string $key): bool - { - return array_key_exists($key, $this->collectionItems); - } - - protected function typeIsObject(string $value): bool - { - return $value[0] === '\\' && ctype_upper($value[1]); - } - - /** - * @return string|null - */ public function getMessage(): ?string { - return $this->popoGetValue('message'); + return $this->message; } - /** - * @param string|null $message - * - * @return TestLoggerConfigurator - */ - public function setMessage(?string $message): TestLoggerConfigurator + public function setMessage(?string $message): static { - $this->popoSetValue('message', $message); + $this->message = $message; return $this; } - /** - * Throws exception if value is null. - * - * @return string - * @throws \UnexpectedValueException - * - */ - public function requireMessage(): string - { - $this->assertPropertyValue('message'); - - return (string)$this->popoGetValue('message'); - } - - /** - * Returns true if value was set to any value, ignores defaults. - * - * @return bool - */ - public function hasMessage(): bool + public function getExtra(): array { - return $this->updateMap['message'] ?? false; + return $this->extra; } - /** - * @return array|null - */ - public function getContext(): ?array + public function setExtra(array $extra): static { - return $this->popoGetValue('context'); - } - - /** - * @param array|null $context - * - * @return TestLoggerConfigurator - */ - public function setContext(?array $context): TestLoggerConfigurator - { - $this->popoSetValue('context', $context); + $this->extra = $extra; return $this; } - /** - * Throws exception if value is null. - * - * @return array - * @throws \UnexpectedValueException - * - */ - public function requireContext(): array - { - $this->assertPropertyValue('context'); - - return (array)$this->popoGetValue('context'); - } - - /** - * Returns true if value was set to any value, ignores defaults. - * - * @return bool - */ - public function hasContext(): bool - { - return $this->updateMap['context'] ?? false; - } - - /** - * @return array|null - */ - public function getExtra(): ?array + public function getContext(): array { - return $this->popoGetValue('extra'); + return $this->context; } - /** - * @param array|null $extra - * - * @return TestLoggerConfigurator - */ - public function setExtra(?array $extra): TestLoggerConfigurator + public function setContext(array $context): static { - $this->popoSetValue('extra', $extra); + $this->context = $context; return $this; } - /** - * Throws exception if value is null. - * - * @return array - * @throws \UnexpectedValueException - * - */ - public function requireExtra(): array - { - $this->assertPropertyValue('extra'); - - return (array)$this->popoGetValue('extra'); - } - - /** - * Returns true if value was set to any value, ignores defaults. - * - * @return bool - */ - public function hasExtra(): bool - { - return $this->updateMap['extra'] ?? false; - } - - /** - * @return string|null - */ - public function getDelimiter(): ?string + public function getDelimiter(): string { - return $this->popoGetValue('delimiter'); + return $this->delimiter; } - - /** - * @param string|null $delimiter - * - * @return TestLoggerConfigurator - */ - public function setDelimiter(?string $delimiter): TestLoggerConfigurator - { - $this->popoSetValue('delimiter', $delimiter); - - return $this; - } - - /** - * Throws exception if value is null. - * - * @return string - * @throws \UnexpectedValueException - * - */ - public function requireDelimiter(): string - { - $this->assertPropertyValue('delimiter'); - - return (string)$this->popoGetValue('delimiter'); - } - - /** - * Returns true if value was set to any value, ignores defaults. - * - * @return bool - */ - public function hasDelimiter(): bool - { - return $this->updateMap['delimiter'] ?? false; - } - - - /** - * @param $item - * - * @return TestLoggerConfigurator - */ - public function addContextItem($item): TestLoggerConfigurator - { - $this->addCollectionItem('context', $item); - - return $this; - } - - /** - * @param $item - * - * @return TestLoggerConfigurator - */ - public function addExtraItem($item): TestLoggerConfigurator - { - $this->addCollectionItem('extra', $item); - - return $this; - } - } diff --git a/tests/suite/Functional/Builder/BuildLoggerFromConfiguratorTest.php b/tests/suite/Functional/Builder/BuildLoggerFromConfiguratorTest.php index 43b8308..4fd0c92 100644 --- a/tests/suite/Functional/Builder/BuildLoggerFromConfiguratorTest.php +++ b/tests/suite/Functional/Builder/BuildLoggerFromConfiguratorTest.php @@ -9,7 +9,7 @@ use Everon\Logger\Exception\PluginBuildException; use Everon\Logger\Exception\ProcessorBuildException; use Everon\Shared\Testify\Logger\LoggerHelperTrait; -use EveronLoggerTests\Stub\Plugin\Stream\HandlerExceptionLoggerPluginStub; +use EveronLoggerTests\Stub\Plugin\Stream\FactoryStub; use EveronLoggerTests\Stub\Plugin\Stream\PluginExceptionLoggerPluginStub; use EveronLoggerTests\Stub\Plugin\Stream\ProcessorExceptionStub; use EveronLoggerTests\Stub\Plugin\Stream\StreamLoggerPluginConfiguratorStub; @@ -150,7 +150,7 @@ public function test_build_should_throw_exception_when_validation_fails(): void ); $streamPluginConfigurator = (new StreamLoggerPluginConfiguratorStub()) - ->setPluginClass(HandlerExceptionLoggerPluginStub::class) + ->setPluginFactoryClass(FactoryStub::class) ->setLogLevel(Level::Info) ->setStreamLocation($this->logFilename);