From cb822151b30e9c6ad34f8350d1d46bece864a222 Mon Sep 17 00:00:00 2001 From: Michael Sievenpiper Date: Fri, 15 May 2026 15:43:40 +0100 Subject: [PATCH] - php 8.4 support including fixing notices and deprecations --- .github/workflows/phpunit.yml | 2 +- composer.json | 4 +- phpunit.xml | 24 +-- src/ConfigProviderInterface.php | 95 ++-------- src/ConfigSectionInterface.php | 42 +---- src/ConfigurableInterface.php | 9 +- src/ConfigurableTrait.php | 21 +-- src/Provider/AbstractConfigProvider.php | 126 +++---------- src/Provider/ConfigSection.php | 168 +++--------------- .../Ini/AbstractIniConfigProvider.php | 20 +-- src/Provider/Ini/CachedIniConfigProvider.php | 4 +- src/Provider/Ini/IniConfigProvider.php | 37 +--- src/Provider/Test/TestConfigProvider.php | 10 +- src/Provider/Test/TestConfigSection.php | 10 +- tests/ConfigProviderBaseTest.php | 66 ++----- tests/ConfigProviderTest.php | 2 +- tests/ConfigSectionBaseTest.php | 5 +- tests/ConfigSectionTest.php | 5 +- tests/ConfigurableTraitTest.php | 5 +- tests/IniCachedConfigProviderTest.php | 16 +- tests/IniConfigProviderTest.php | 2 +- tests/TestConfigProviderTest.php | 2 +- tests/TestConfigSectionTest.php | 5 +- 23 files changed, 138 insertions(+), 542 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 3891bba..da22eeb 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ] + php: [ '8.3', '8.4', '8.5' ] name: PHP ${{ matrix.php }} diff --git a/composer.json b/composer.json index 015b6b7..6070388 100644 --- a/composer.json +++ b/composer.json @@ -9,13 +9,13 @@ } ], "require": { - "php": ">=7.4" + "php": ">=8.0" }, "suggest": { "ext-apcu": "*" }, "require-dev": { - "phpunit/phpunit": "~9" + "phpunit/phpunit": "^12" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 564f4ce..89f26ad 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,23 +1,15 @@ - - - - src - - + tests + tests/ConfigProviderBaseTest.php + tests/ConfigSectionBaseTest.php + + + src + + diff --git a/src/ConfigProviderInterface.php b/src/ConfigProviderInterface.php index a3df917..9ee61d0 100644 --- a/src/ConfigProviderInterface.php +++ b/src/ConfigProviderInterface.php @@ -15,106 +15,39 @@ interface ConfigProviderInterface * * @return ConfigSectionInterface[] */ - public function getSections(); + public function getSections(): array; /** - * @param string $name Name/Key of the configuration section - * - * @return ConfigSectionInterface - * @throws \Exception + * @throws \Exception when the section does not exist (and $throw is true) */ - public function getSection($name); + public function getSection(string $name): ConfigSectionInterface; /** - * @param ConfigSectionInterface $section Section container to add - * - * @return $this * @throws \Exception when the section already exists */ - public function addSection(ConfigSectionInterface $section); + public function addSection(ConfigSectionInterface $section): static; /** * Same as addSection, however, will replace an existing section if one exists - * - * @param ConfigSectionInterface $section Section container to add - * - * @return $this */ - public function setSection(ConfigSectionInterface $section); + public function setSection(ConfigSectionInterface $section): static; - /** - * Check to see if a section exists within the configuration - * - * @param string $name Section name - * - * @return bool - */ - public function sectionExists($name); + public function sectionExists(string $name): bool; - /** - * Check to see if a section exists within the configuration - * - * @param string $name Section name - * - * @return bool - */ - public function has($name); + public function has(string $name): bool; /** - * @param string $section Section Name - * @param string $key Config Item Key - * @param mixed $default Default value for missing item - * - * @return mixed Configuration Value - * - * @throws \Exception when default is passed as an exception + * @throws \Exception when $default is passed as an Exception */ - public function getItem($section, $key, $default = null); + public function getItem(string $section, string $key, mixed $default = null): mixed; - /** - * @param string $section Section Name - * @param string $key Config Item Key - * - * @return bool - */ - public function hasItem($section, $key); + public function hasItem(string $section, string $key): bool; - /** - * Add an item to the configuration - * - * @param string $section Section Name - * @param string $item Config Item Key - * @param mixed $value Config Item Value - * - * @return $this - */ - public function addItem($section, $item, $value); + public function addItem(string $section, string $item, mixed $value): static; - /** - * Remove an item from the configuration - * - * @param $section - * @param $item - * - * @return $this - */ - public function removeItem($section, $item); + public function removeItem(string $section, string $item): static; - /** - * Remove a section from the configuration - * - * @param ConfigSectionInterface $section Section container to remove - * - * @return $this - */ - public function removeSection(ConfigSectionInterface $section); + public function removeSection(ConfigSectionInterface $section): static; - /** - * Remove a section from the configuration by its name - * - * @param string $sectionName Section name to remove - * - * @return $this - */ - public function removeSectionByName($sectionName); + public function removeSectionByName(string $sectionName): static; } diff --git a/src/ConfigSectionInterface.php b/src/ConfigSectionInterface.php index 3f62978..0df78fc 100644 --- a/src/ConfigSectionInterface.php +++ b/src/ConfigSectionInterface.php @@ -14,64 +14,38 @@ interface ConfigSectionInterface { /** * Get the name of the current section e.g. database - * - * @return string */ - public function getName(); + public function getName(): string; /** * Name the current section - * - * @param string $name Name of this section - * - * @return $this */ - public function setName($name); + public function setName(string $name): static; /** * Retrieve an item from the configuration * - * @param string $key Configuration item key e.g. hostname - * @param mixed $default Default value if the config item does not exist - * - * @return mixed - * - * @throws \Exception when default is passed as an exception + * @throws \Exception when $default is passed as an Exception */ - public function getItem($key, $default = null); + public function getItem(string $key, mixed $default = null): mixed; /** * Check to see if a config item exists within the configuration - * - * @param $key - * - * @return bool */ - public function has($key); + public function has(string $key): bool; /** * Retrieve all the items in the configuration section - * - * @return array */ - public function getItems(); + public function getItems(): array; /** * Add an item to the configuration section - * - * @param string $item Config Item Key - * @param mixed $value Config Item Value - * - * @return $this */ - public function addItem($item, $value); + public function addItem(string $item, mixed $value): static; /** * Remove a configuration item - * - * @param string $key Configuration item key e.g. hostname - * - * @return $this */ - public function removeItem($key); + public function removeItem(string $key): static; } diff --git a/src/ConfigurableInterface.php b/src/ConfigurableInterface.php index 0bcf4de..dc01289 100644 --- a/src/ConfigurableInterface.php +++ b/src/ConfigurableInterface.php @@ -3,12 +3,5 @@ interface ConfigurableInterface { - /** - * Configure the data connection - * - * @param ConfigSectionInterface $configuration - * - * @return static - */ - public function configure(ConfigSectionInterface $configuration); + public function configure(ConfigSectionInterface $configuration): static; } diff --git a/src/ConfigurableTrait.php b/src/ConfigurableTrait.php index 2e234e7..d9624ea 100644 --- a/src/ConfigurableTrait.php +++ b/src/ConfigurableTrait.php @@ -5,30 +5,15 @@ trait ConfigurableTrait { - /** - * @var ConfigSectionInterface - */ - protected $_configuration; + protected ?ConfigSectionInterface $_configuration = null; - /** - * Configure the data connection - * - * @param ConfigSectionInterface $configuration - * - * @return $this - */ - public function configure(ConfigSectionInterface $configuration) + public function configure(ConfigSectionInterface $configuration): static { $this->_configuration = $configuration; return $this; } - /** - * Retrieve the configuration - * - * @return ConfigSectionInterface - */ - protected function _config() + protected function _config(): ConfigSectionInterface { if($this->_configuration === null) { diff --git a/src/Provider/AbstractConfigProvider.php b/src/Provider/AbstractConfigProvider.php index 5b4b615..4f7d910 100644 --- a/src/Provider/AbstractConfigProvider.php +++ b/src/Provider/AbstractConfigProvider.php @@ -7,22 +7,11 @@ abstract class AbstractConfigProvider implements ConfigProviderInterface { - /** - * @var ConfigSection[] - */ - protected $_sections; + /** @var ConfigSection[] */ + protected array $_sections = []; - /** - * Add an item to the configuration - * - * @param string $section Section Name - * @param string $item Config Item Key - * @param mixed $value Config Item Value - * - * @return $this - * @throws \RuntimeException - */ - public function addItem($section, $item, $value) + #[\Override] + public function addItem(string $section, string $item, mixed $value): static { if(isset($this->_sections[$section])) { @@ -36,15 +25,8 @@ public function addItem($section, $item, $value) return $this; } - /** - * Remove an item from the configuration - * - * @param $section - * @param $item - * - * @return $this - */ - public function removeItem($section, $item) + #[\Override] + public function removeItem(string $section, string $item): static { if(isset($this->_sections[$section])) { @@ -53,16 +35,8 @@ public function removeItem($section, $item) return $this; } - /** - * @param string $section Section Name - * @param string $key Config Item Key - * @param mixed $default Default value for missing item - * - * @return mixed Configuration Value - * - * @throws \Exception when default is passed as an exception - */ - public function getItem($section, $key, $default = null) + #[\Override] + public function getItem(string $section, string $key, mixed $default = null): mixed { if(!$this->sectionExists($section)) { @@ -75,13 +49,8 @@ public function getItem($section, $key, $default = null) return $this->getSection($section)->getItem($key, $default); } - /** - * @param string $section Section Name - * @param string $key Config Item Key - * - * @return bool - */ - public function hasItem($section, $key) + #[\Override] + public function hasItem(string $section, string $key): bool { try { @@ -94,24 +63,18 @@ public function hasItem($section, $key) } /** - * Retrieve all configuration sections - * * @return ConfigSectionInterface[] */ - public function getSections() + #[\Override] + public function getSections(): array { return $this->_sections; } /** - * @param string $name Name/Key of the configuration section - * - * @param bool $throw - * - * @return ConfigSectionInterface - * @throws Exception + * @throws Exception when the section does not exist and $throw is true */ - public function getSection($name, $throw = true) + public function getSection(string $name, bool $throw = true): ConfigSectionInterface { if(isset($this->_sections[$name])) { @@ -124,39 +87,20 @@ public function getSection($name, $throw = true) throw new Exception("Configuration section $name could not be found"); } - /** - * Check to see if a section exists within the configuration - * - * @alias has - * - * @param string $name Section name - * - * @return bool - */ - public function sectionExists($name) + #[\Override] + public function sectionExists(string $name): bool { return isset($this->_sections[$name]); } - /** - * Check to see if a section exists within the configuration - * - * @param string $name Section name - * - * @return bool - */ - public function has($name) + #[\Override] + public function has(string $name): bool { return isset($this->_sections[$name]); } - /** - * @param ConfigSectionInterface $section Section container to add - * - * @return $this - * @throws \Exception when the section already exists - */ - public function addSection(ConfigSectionInterface $section) + #[\Override] + public function addSection(ConfigSectionInterface $section): static { if($this->sectionExists($section->getName())) { @@ -169,40 +113,22 @@ public function addSection(ConfigSectionInterface $section) return $this; } - /** - * Same as addSection, however, will replace an existing section if one exists - * - * @param ConfigSectionInterface $section Section container to add - * - * @return $this - */ - public function setSection(ConfigSectionInterface $section) + #[\Override] + public function setSection(ConfigSectionInterface $section): static { $this->_sections[$section->getName()] = $section; return $this; } - /** - * Remove a section from the configuration - * - * @param ConfigSectionInterface $section Section container to remove - * - * @return $this - */ - public function removeSection(ConfigSectionInterface $section) + #[\Override] + public function removeSection(ConfigSectionInterface $section): static { $this->removeSectionByName($section->getName()); return $this; } - /** - * Remove a section from the configuration by its name - * - * @param string $sectionName Section name to remove - * - * @return $this - */ - public function removeSectionByName($sectionName) + #[\Override] + public function removeSectionByName(string $sectionName): static { if(isset($this->_sections[$sectionName])) { diff --git a/src/Provider/ConfigSection.php b/src/Provider/ConfigSection.php index 7529f65..07572a8 100644 --- a/src/Provider/ConfigSection.php +++ b/src/Provider/ConfigSection.php @@ -5,117 +5,64 @@ use Exception; use Packaged\Config\ConfigSectionInterface; -/** - * Configuration section - */ class ConfigSection implements ConfigSectionInterface, ArrayAccess { - protected $_name; - protected $_items; + protected string $_name; + protected array $_items; - /** - * @param string $name Name of this configuration section - * @param array $items all configuration items e.g. [host => localhost] - */ - public function __construct($name = '', array $items = []) + public function __construct(string $name = '', array $items = []) { $this->_name = $name; $this->_items = $items; } - /** - * Name the current section - * - * @param string $name Name of this section - * - * @return $this - */ - public function setName($name) + #[\Override] + public function setName(string $name): static { $this->_name = $name; return $this; } - /** - * Get the name of the current section e.g. database - * - * @return string - */ - public function getName() + #[\Override] + public function getName(): string { return $this->_name; } - /** - * Check to see if a config item exists within the configuration - * - * @param $key - * - * @return bool - */ - public function has($key) + #[\Override] + public function has(string $key): bool { return isset($this->_items[$key]); } - /** - * Retrieve an item from the configuration - * - * @param string $key Configuration item key e.g. hostname - * @param mixed $default Default value if the config item does not exist - * - * @return mixed - * - * @throws \Exception when default is passed as an exception - */ - public function getItem($key, $default = null) + #[\Override] + public function getItem(string $key, mixed $default = null): mixed { if(isset($this->_items[$key])) { return $this->_items[$key]; } - else + if($default instanceof Exception) { - if($default instanceof Exception) - { - throw $default; - } - return $default; + throw $default; } + return $default; } - /** - * Retrieve all the items in the configuration section - * - * @return array - */ - public function getItems() + #[\Override] + public function getItems(): array { return $this->_items; } - /** - * Add a new configuration item - * - * @param string $key Configuration item key e.g. hostname - * @param mixed $value Configuration item value e.g. localhost - * - * @return $this - */ - public function addItem($key, $value) + #[\Override] + public function addItem(string $key, mixed $value): static { $this->_items[$key] = $value; return $this; } - /** - * Add a new configuration item - * - * @param array $keyValueItems - * - * @return $this - */ - public function addItems(array $keyValueItems) + public function addItems(array $keyValueItems): static { foreach($keyValueItems as $k => $v) { @@ -124,90 +71,33 @@ public function addItems(array $keyValueItems) return $this; } - /** - * Remove a configuration item - * - * @param string $key Configuration item key e.g. hostname - * - * @return $this - */ - public function removeItem($key) + #[\Override] + public function removeItem(string $key): static { unset($this->_items[$key]); return $this; } - /** - * (PHP 5 >= 5.0.0)
- * Whether a offset exists - * - * @link http://php.net/manual/en/arrayaccess.offsetexists.php - * - * @param mixed $offset

- * An offset to check for. - *

- * - * @return boolean true on success or false on failure. - *

- *

- * The return value will be casted to boolean if non-boolean was returned. - */ - public function offsetExists($offset): bool + #[\Override] + public function offsetExists(mixed $offset): bool { return isset($this->_items[$offset]); } - /** - * (PHP 5 >= 5.0.0)
- * Offset to retrieve - * - * @link http://php.net/manual/en/arrayaccess.offsetget.php - * - * @param mixed $offset

- * The offset to retrieve. - *

- * - * @return mixed Can return all value types. - */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) + #[\Override] + public function offsetGet(mixed $offset): mixed { return $this->getItem($offset); } - /** - * (PHP 5 >= 5.0.0)
- * Offset to set - * - * @link http://php.net/manual/en/arrayaccess.offsetset.php - * - * @param mixed $offset

- * The offset to assign the value to. - *

- * @param mixed $value

- * The value to set. - *

- * - * @return void - */ - public function offsetSet($offset, $value): void + #[\Override] + public function offsetSet(mixed $offset, mixed $value): void { $this->addItem($offset, $value); } - /** - * (PHP 5 >= 5.0.0)
- * Offset to unset - * - * @link http://php.net/manual/en/arrayaccess.offsetunset.php - * - * @param mixed $offset

- * The offset to unset. - *

- * - * @return void - */ - public function offsetUnset($offset): void + #[\Override] + public function offsetUnset(mixed $offset): void { unset($this->_items[$offset]); } diff --git a/src/Provider/Ini/AbstractIniConfigProvider.php b/src/Provider/Ini/AbstractIniConfigProvider.php index bfed470..c8a3c99 100644 --- a/src/Provider/Ini/AbstractIniConfigProvider.php +++ b/src/Provider/Ini/AbstractIniConfigProvider.php @@ -9,11 +9,8 @@ abstract class AbstractIniConfigProvider extends AbstractConfigProvider /** * Load configuration from a string containing INI data and optionally parse * environment variable placeholders - * - * @param string $iniString - * @param bool $parseEnv */ - protected function _loadString($iniString, $parseEnv) + protected function _loadString(string $iniString, bool $parseEnv): void { if($parseEnv) { @@ -31,12 +28,7 @@ protected function _loadString($iniString, $parseEnv) $this->_buildFromData($data); } - /** - * Build up the configuration from the sectioned array - * - * @param array $iniData - */ - protected function _buildFromData(array $iniData) + protected function _buildFromData(array $iniData): void { foreach($iniData as $section => $sectionData) { @@ -57,16 +49,12 @@ protected function _buildFromData(array $iniData) * variable's value. * Variables are expected to be in this format: {{ENV:VARNAME:defaultValue}} * The ":defaultValue" part is optional and defaults to an empty string - * - * @param string $iniString - * - * @return string */ - protected function _parseEnvVars($iniString) + protected function _parseEnvVars(string $iniString): string { return preg_replace_callback( '/{{ENV:([0-9A-Za-z_]*)(:([^{}]*))?}}/', - function ($matches) { + function(array $matches): string { $varName = $matches[1]; $default = $matches[3] ?? ''; $value = getenv($varName); diff --git a/src/Provider/Ini/CachedIniConfigProvider.php b/src/Provider/Ini/CachedIniConfigProvider.php index 0e3b4c4..f9f09a7 100644 --- a/src/Provider/Ini/CachedIniConfigProvider.php +++ b/src/Provider/Ini/CachedIniConfigProvider.php @@ -5,7 +5,7 @@ class CachedIniConfigProvider extends AbstractIniConfigProvider { protected static bool $_hasApcu; - public function __construct(array $directories = [], $filename = null, $parseEnv = false, $cacheTTL = 5) + public function __construct(array $directories = [], ?string $filename = null, bool $parseEnv = false, int $cacheTTL = 5) { self::$_hasApcu = self::$_hasApcu ?? function_exists('apcu_fetch'); @@ -15,7 +15,7 @@ public function __construct(array $directories = [], $filename = null, $parseEnv } } - public function loadCached($directories, $filename, $parseEnv = false, $cacheTTL = 5) + public function loadCached(array $directories, string $filename, bool $parseEnv = false, int $cacheTTL = 5): static { $dirsHash = md5(implode('|', $directories)); $lastCheckKey = 'CachedIniCP:' . $dirsHash . ':lastCheck:' . $filename; diff --git a/src/Provider/Ini/IniConfigProvider.php b/src/Provider/Ini/IniConfigProvider.php index 2e02b17..e6fd195 100644 --- a/src/Provider/Ini/IniConfigProvider.php +++ b/src/Provider/Ini/IniConfigProvider.php @@ -5,11 +5,7 @@ class IniConfigProvider extends AbstractIniConfigProvider { - /** - * @param null|string $file Full path of ini file to create configuration from - * @param bool $parseEnv If true then parse environment variables in the INI file - */ - public function __construct($file = null, $parseEnv = false) + public function __construct(?string $file = null, bool $parseEnv = false) { if($file !== null) { @@ -18,15 +14,9 @@ public function __construct($file = null, $parseEnv = false) } /** - * Add items from an ini file to the configuration - * - * @param string $fullPath full path to the ini file to load - * @param bool $parseEnv If true then parse environment variables in the INI file - * - * @return $this - * @throws \RuntimeException + * @throws RuntimeException */ - public function loadFile($fullPath, $parseEnv = false) + public function loadFile(string $fullPath, bool $parseEnv = false): static { if(!file_exists($fullPath)) { @@ -52,16 +42,7 @@ public function loadFile($fullPath, $parseEnv = false) return $this; } - /** - * Add items from multiple ini files - * - * @param array $paths - * @param bool $parseEnv - * @param bool $throw - * - * @return $this - */ - public function loadFiles(array $paths, $parseEnv = false, $throw = false) + public function loadFiles(array $paths, bool $parseEnv = false, bool $throw = false): static { foreach($paths as $path) { @@ -81,15 +62,9 @@ public function loadFiles(array $paths, $parseEnv = false, $throw = false) } /** - * Add items from an ini string to the configuration - * - * @param string $iniString valid ini string - * @param bool $parseEnv If true then parse environment variables in the INI file - * - * @return $this - * @throws \RuntimeException + * @throws RuntimeException */ - public function loadString($iniString, $parseEnv = false) + public function loadString(string $iniString, bool $parseEnv = false): static { $this->_loadString($iniString, $parseEnv); return $this; diff --git a/src/Provider/Test/TestConfigProvider.php b/src/Provider/Test/TestConfigProvider.php index ce75523..7c9aaa4 100644 --- a/src/Provider/Test/TestConfigProvider.php +++ b/src/Provider/Test/TestConfigProvider.php @@ -3,15 +3,7 @@ use Packaged\Config\Provider\ConfigProvider; -/** - * @deprecated \Packaged\Config\Provider\ConfigProvider - * - * Class TestConfigProvider - * - * Config provider for testing basics - * - * @package Packaged\Config\Provider\Test - */ +/** @deprecated Use \Packaged\Config\Provider\ConfigProvider directly */ class TestConfigProvider extends ConfigProvider { } diff --git a/src/Provider/Test/TestConfigSection.php b/src/Provider/Test/TestConfigSection.php index 6570af9..eb73e2f 100644 --- a/src/Provider/Test/TestConfigSection.php +++ b/src/Provider/Test/TestConfigSection.php @@ -3,15 +3,7 @@ use Packaged\Config\Provider\ConfigSection; -/** - * @deprecated \Packaged\Config\Provider\ConfigSection - * - * Class TestConfigSection - * - * Configuration section - * - * @package Packaged\Config\Provider\Test - */ +/** @deprecated Use \Packaged\Config\Provider\ConfigSection directly */ class TestConfigSection extends ConfigSection { } diff --git a/tests/ConfigProviderBaseTest.php b/tests/ConfigProviderBaseTest.php index 2c7f5fd..36d416c 100644 --- a/tests/ConfigProviderBaseTest.php +++ b/tests/ConfigProviderBaseTest.php @@ -5,6 +5,7 @@ use Exception; use Packaged\Config\ConfigProviderInterface; use Packaged\Config\Provider\ConfigSection; +use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; abstract class ConfigProviderBaseTest extends TestCase @@ -15,10 +16,7 @@ public function testCanBeLoaded() $this->assertNotNull($provider); } - /** - * @return ConfigProviderInterface - */ - abstract public function getConfigProvider(); + abstract public function getConfigProvider(): ConfigProviderInterface; public function testValidProvider() { @@ -29,9 +27,7 @@ public function testValidProvider() ); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testCanAddItem() { $provider = $this->getConfigProvider(); @@ -58,9 +54,7 @@ public function testCanAddItem() ); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testCanAddItemAndRetrieve() { $provider = $this->getConfigProvider(); @@ -69,9 +63,7 @@ public function testCanAddItemAndRetrieve() $this->assertEquals("localhost", $item); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testCanAddItemAndRetrieveSection() { $provider = $this->getConfigProvider(); @@ -83,9 +75,7 @@ public function testCanAddItemAndRetrieveSection() ); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testCanAddRemoveItem() { $provider = $this->getConfigProvider(); @@ -95,9 +85,7 @@ public function testCanAddRemoveItem() $this->assertEquals("rm", $provider->getItem("db", "hostname", 'rm')); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testGetSections() { $provider = $this->getConfigProvider(); @@ -113,9 +101,7 @@ public function testGetSections() ); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionAdd() { $section = new ConfigSection("db"); @@ -129,9 +115,7 @@ public function testSectionAdd() $provider->addSection($section); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionSet() { $section = new ConfigSection("db"); @@ -143,9 +127,7 @@ public function testSectionSet() $provider->setSection($section); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionGetItem() { $provider = $this->getConfigProvider(); @@ -154,9 +136,7 @@ public function testSectionGetItem() $this->assertEquals("localhost", $section->getItem("hostname", "notset")); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testMissingSectionThrows() { $provider = $this->getConfigProvider(); @@ -165,9 +145,7 @@ public function testMissingSectionThrows() $provider->getSection("database"); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testMissingSectionNoThrow() { $provider = $this->getConfigProvider(); @@ -176,9 +154,7 @@ public function testMissingSectionNoThrow() $this->assertEquals("missing", $section->getName()); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testGetMissingItem() { $provider = $this->getConfigProvider(); @@ -193,9 +169,7 @@ public function testGetMissingItem() $this->assertEquals("notset", $section->getItem("hostname", "notset")); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testDefaultExceptionThrown() { $provider = $this->getConfigProvider(); @@ -205,9 +179,7 @@ public function testDefaultExceptionThrown() $provider->getItem('', 'gone', new Exception("Config Item Not Found", 999)); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionExists() { $provider = $this->getConfigProvider(); @@ -226,9 +198,7 @@ public function testSectionExists() $this->assertFalse($provider->sectionExists("database")); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testHasItem() { $provider = $this->getConfigProvider(); @@ -239,9 +209,7 @@ public function testHasItem() $this->assertTrue($provider->hasItem('newsection', 'newitem')); } - /** - * @depends testValidProvider - */ + #[Depends('testValidProvider')] public function testSectionNameGet() { $provider = $this->getConfigProvider(); diff --git a/tests/ConfigProviderTest.php b/tests/ConfigProviderTest.php index a9dc72f..55b068c 100644 --- a/tests/ConfigProviderTest.php +++ b/tests/ConfigProviderTest.php @@ -6,7 +6,7 @@ class ConfigProviderTest extends ConfigProviderBaseTest { - public function getConfigProvider() + public function getConfigProvider(): ConfigProvider { return new ConfigProvider([]); } diff --git a/tests/ConfigSectionBaseTest.php b/tests/ConfigSectionBaseTest.php index fcad5d9..ab6e50d 100644 --- a/tests/ConfigSectionBaseTest.php +++ b/tests/ConfigSectionBaseTest.php @@ -14,10 +14,7 @@ public function testNameSetAndGet() $this->assertEquals("testing", $section->getName()); } - /** - * @return ConfigSectionInterface - */ - abstract public function getConfigSection(); + abstract public function getConfigSection(): ConfigSectionInterface; public function testCanAddItemAndRetrieve() { diff --git a/tests/ConfigSectionTest.php b/tests/ConfigSectionTest.php index 0820fc0..9f3c72f 100644 --- a/tests/ConfigSectionTest.php +++ b/tests/ConfigSectionTest.php @@ -30,10 +30,7 @@ public function testArrayAccess() $section->getItem('ghj', new Exception("Config Item Not Found", 999)); } - /** - * @return ConfigSectionInterface - */ - public function getConfigSection() + public function getConfigSection(): ConfigSection { return new ConfigSection(); } diff --git a/tests/ConfigurableTraitTest.php b/tests/ConfigurableTraitTest.php index 73a11f4..2089cc3 100644 --- a/tests/ConfigurableTraitTest.php +++ b/tests/ConfigurableTraitTest.php @@ -28,10 +28,7 @@ class MockConfigurableTrait { use ConfigurableTrait; - /** - * @return ConfigSectionInterface - */ - public function config() + public function config(): ConfigSectionInterface { return $this->_config(); } diff --git a/tests/IniCachedConfigProviderTest.php b/tests/IniCachedConfigProviderTest.php index 829fca1..1658ada 100644 --- a/tests/IniCachedConfigProviderTest.php +++ b/tests/IniCachedConfigProviderTest.php @@ -3,10 +3,9 @@ namespace Packaged\Config\Test; use Packaged\Config\Provider\Ini\CachedIniConfigProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; -/** - * @requires extension apcu - */ +#[RequiresPhpExtension('apcu')] class IniCachedConfigProviderTest extends ConfigProviderBaseTest { public function testMissingLoadFile() @@ -16,15 +15,12 @@ public function testMissingLoadFile() $this->assertSame($provider, $result); } - /** - * @return CachedIniConfigProvider - */ - public function getConfigProvider() + public function getConfigProvider(): CachedIniConfigProvider { return new CachedIniConfigProvider(); } - private function _dataDir() + private function _dataDir(): array { return [__DIR__ . '/testData']; } @@ -63,6 +59,10 @@ public function testLoadFileMissingFirstDir() public function testCachedLoad() { + if(!ini_get('apc.enable_cli')) + { + $this->markTestSkipped('Requires apc.enable_cli=1'); + } $dir = sys_get_temp_dir(); $tempFile = tempnam($dir, 'cached-ini'); $filename = basename($tempFile); diff --git a/tests/IniConfigProviderTest.php b/tests/IniConfigProviderTest.php index 9a2c2a2..9126c57 100644 --- a/tests/IniConfigProviderTest.php +++ b/tests/IniConfigProviderTest.php @@ -15,7 +15,7 @@ public function testMissingLoadFile() $provider->loadFile($file); } - public function getConfigProvider() + public function getConfigProvider(): IniConfigProvider { return new IniConfigProvider(); } diff --git a/tests/TestConfigProviderTest.php b/tests/TestConfigProviderTest.php index e199b2a..33b48cf 100644 --- a/tests/TestConfigProviderTest.php +++ b/tests/TestConfigProviderTest.php @@ -6,7 +6,7 @@ class TestConfigProviderTest extends ConfigProviderBaseTest { - public function getConfigProvider() + public function getConfigProvider(): TestConfigProvider { return new TestConfigProvider(); } diff --git a/tests/TestConfigSectionTest.php b/tests/TestConfigSectionTest.php index 7763e24..34eade8 100644 --- a/tests/TestConfigSectionTest.php +++ b/tests/TestConfigSectionTest.php @@ -7,10 +7,7 @@ class TestConfigSectionTest extends ConfigSectionBaseTest { - /** - * @return ConfigSectionInterface - */ - public function getConfigSection() + public function getConfigSection(): TestConfigSection { return new TestConfigSection(); }