diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index a72e437..eda5b18 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '8.3', '8.4', '8.5' ] + php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ] name: PHP ${{ matrix.php }} diff --git a/composer.json b/composer.json index 6070388..015b6b7 100644 --- a/composer.json +++ b/composer.json @@ -9,13 +9,13 @@ } ], "require": { - "php": ">=8.0" + "php": ">=7.4" }, "suggest": { "ext-apcu": "*" }, "require-dev": { - "phpunit/phpunit": "^12" + "phpunit/phpunit": "~9" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 89f26ad..564f4ce 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,15 +1,23 @@ - + + + + src + + tests - tests/ConfigProviderBaseTest.php - tests/ConfigSectionBaseTest.php - - - src - - diff --git a/src/ConfigProviderInterface.php b/src/ConfigProviderInterface.php index 9ee61d0..a3df917 100644 --- a/src/ConfigProviderInterface.php +++ b/src/ConfigProviderInterface.php @@ -15,39 +15,106 @@ interface ConfigProviderInterface * * @return ConfigSectionInterface[] */ - public function getSections(): array; + public function getSections(); /** - * @throws \Exception when the section does not exist (and $throw is true) + * @param string $name Name/Key of the configuration section + * + * @return ConfigSectionInterface + * @throws \Exception */ - public function getSection(string $name): ConfigSectionInterface; + public function getSection($name); /** + * @param ConfigSectionInterface $section Section container to add + * + * @return $this * @throws \Exception when the section already exists */ - public function addSection(ConfigSectionInterface $section): static; + public function addSection(ConfigSectionInterface $section); /** * 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): static; + public function setSection(ConfigSectionInterface $section); - 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 sectionExists($name); - public function has(string $name): bool; + /** + * Check to see if a section exists within the configuration + * + * @param string $name Section name + * + * @return bool + */ + public function has($name); /** - * @throws \Exception when $default is passed as an Exception + * @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(string $section, string $key, mixed $default = null): mixed; + public function getItem($section, $key, $default = null); - public function hasItem(string $section, string $key): bool; + /** + * @param string $section Section Name + * @param string $key Config Item Key + * + * @return bool + */ + public function hasItem($section, $key); - public function addItem(string $section, string $item, mixed $value): static; + /** + * 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 removeItem(string $section, string $item): static; + /** + * Remove an item from the configuration + * + * @param $section + * @param $item + * + * @return $this + */ + public function removeItem($section, $item); - public function removeSection(ConfigSectionInterface $section): static; + /** + * Remove a section from the configuration + * + * @param ConfigSectionInterface $section Section container to remove + * + * @return $this + */ + public function removeSection(ConfigSectionInterface $section); - public function removeSectionByName(string $sectionName): static; + /** + * Remove a section from the configuration by its name + * + * @param string $sectionName Section name to remove + * + * @return $this + */ + public function removeSectionByName($sectionName); } diff --git a/src/ConfigSectionInterface.php b/src/ConfigSectionInterface.php index 0df78fc..3f62978 100644 --- a/src/ConfigSectionInterface.php +++ b/src/ConfigSectionInterface.php @@ -14,38 +14,64 @@ interface ConfigSectionInterface { /** * Get the name of the current section e.g. database + * + * @return string */ - public function getName(): string; + public function getName(); /** * Name the current section + * + * @param string $name Name of this section + * + * @return $this */ - public function setName(string $name): static; + public function setName($name); /** * Retrieve an item from the configuration * - * @throws \Exception when $default is passed as an Exception + * @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(string $key, mixed $default = null): mixed; + public function getItem($key, $default = null); /** * Check to see if a config item exists within the configuration + * + * @param $key + * + * @return bool */ - public function has(string $key): bool; + public function has($key); /** * Retrieve all the items in the configuration section + * + * @return array */ - public function getItems(): array; + public function getItems(); /** * Add an item to the configuration section + * + * @param string $item Config Item Key + * @param mixed $value Config Item Value + * + * @return $this */ - public function addItem(string $item, mixed $value): static; + public function addItem($item, $value); /** * Remove a configuration item + * + * @param string $key Configuration item key e.g. hostname + * + * @return $this */ - public function removeItem(string $key): static; + public function removeItem($key); } diff --git a/src/ConfigurableInterface.php b/src/ConfigurableInterface.php index dc01289..0bcf4de 100644 --- a/src/ConfigurableInterface.php +++ b/src/ConfigurableInterface.php @@ -3,5 +3,12 @@ interface ConfigurableInterface { - public function configure(ConfigSectionInterface $configuration): static; + /** + * Configure the data connection + * + * @param ConfigSectionInterface $configuration + * + * @return static + */ + public function configure(ConfigSectionInterface $configuration); } diff --git a/src/ConfigurableTrait.php b/src/ConfigurableTrait.php index d9624ea..2e234e7 100644 --- a/src/ConfigurableTrait.php +++ b/src/ConfigurableTrait.php @@ -5,15 +5,30 @@ trait ConfigurableTrait { - protected ?ConfigSectionInterface $_configuration = null; + /** + * @var ConfigSectionInterface + */ + protected $_configuration; - public function configure(ConfigSectionInterface $configuration): static + /** + * Configure the data connection + * + * @param ConfigSectionInterface $configuration + * + * @return $this + */ + public function configure(ConfigSectionInterface $configuration) { $this->_configuration = $configuration; return $this; } - protected function _config(): ConfigSectionInterface + /** + * Retrieve the configuration + * + * @return ConfigSectionInterface + */ + protected function _config() { if($this->_configuration === null) { diff --git a/src/Provider/AbstractConfigProvider.php b/src/Provider/AbstractConfigProvider.php index 4f7d910..5b4b615 100644 --- a/src/Provider/AbstractConfigProvider.php +++ b/src/Provider/AbstractConfigProvider.php @@ -7,11 +7,22 @@ abstract class AbstractConfigProvider implements ConfigProviderInterface { - /** @var ConfigSection[] */ - protected array $_sections = []; + /** + * @var ConfigSection[] + */ + protected $_sections; - #[\Override] - public function addItem(string $section, string $item, mixed $value): static + /** + * 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) { if(isset($this->_sections[$section])) { @@ -25,8 +36,15 @@ public function addItem(string $section, string $item, mixed $value): static return $this; } - #[\Override] - public function removeItem(string $section, string $item): static + /** + * Remove an item from the configuration + * + * @param $section + * @param $item + * + * @return $this + */ + public function removeItem($section, $item) { if(isset($this->_sections[$section])) { @@ -35,8 +53,16 @@ public function removeItem(string $section, string $item): static return $this; } - #[\Override] - public function getItem(string $section, string $key, mixed $default = null): mixed + /** + * @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) { if(!$this->sectionExists($section)) { @@ -49,8 +75,13 @@ public function getItem(string $section, string $key, mixed $default = null): mi return $this->getSection($section)->getItem($key, $default); } - #[\Override] - public function hasItem(string $section, string $key): bool + /** + * @param string $section Section Name + * @param string $key Config Item Key + * + * @return bool + */ + public function hasItem($section, $key) { try { @@ -63,18 +94,24 @@ public function hasItem(string $section, string $key): bool } /** + * Retrieve all configuration sections + * * @return ConfigSectionInterface[] */ - #[\Override] - public function getSections(): array + public function getSections() { return $this->_sections; } /** - * @throws Exception when the section does not exist and $throw is true + * @param string $name Name/Key of the configuration section + * + * @param bool $throw + * + * @return ConfigSectionInterface + * @throws Exception */ - public function getSection(string $name, bool $throw = true): ConfigSectionInterface + public function getSection($name, $throw = true) { if(isset($this->_sections[$name])) { @@ -87,20 +124,39 @@ public function getSection(string $name, bool $throw = true): ConfigSectionInter throw new Exception("Configuration section $name could not be found"); } - #[\Override] - public function sectionExists(string $name): bool + /** + * Check to see if a section exists within the configuration + * + * @alias has + * + * @param string $name Section name + * + * @return bool + */ + public function sectionExists($name) { return isset($this->_sections[$name]); } - #[\Override] - public function has(string $name): bool + /** + * Check to see if a section exists within the configuration + * + * @param string $name Section name + * + * @return bool + */ + public function has($name) { return isset($this->_sections[$name]); } - #[\Override] - public function addSection(ConfigSectionInterface $section): static + /** + * @param ConfigSectionInterface $section Section container to add + * + * @return $this + * @throws \Exception when the section already exists + */ + public function addSection(ConfigSectionInterface $section) { if($this->sectionExists($section->getName())) { @@ -113,22 +169,40 @@ public function addSection(ConfigSectionInterface $section): static return $this; } - #[\Override] - public function setSection(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) { $this->_sections[$section->getName()] = $section; return $this; } - #[\Override] - public function removeSection(ConfigSectionInterface $section): static + /** + * Remove a section from the configuration + * + * @param ConfigSectionInterface $section Section container to remove + * + * @return $this + */ + public function removeSection(ConfigSectionInterface $section) { $this->removeSectionByName($section->getName()); return $this; } - #[\Override] - public function removeSectionByName(string $sectionName): static + /** + * Remove a section from the configuration by its name + * + * @param string $sectionName Section name to remove + * + * @return $this + */ + public function removeSectionByName($sectionName) { if(isset($this->_sections[$sectionName])) { diff --git a/src/Provider/ConfigSection.php b/src/Provider/ConfigSection.php index 07572a8..7529f65 100644 --- a/src/Provider/ConfigSection.php +++ b/src/Provider/ConfigSection.php @@ -5,64 +5,117 @@ use Exception; use Packaged\Config\ConfigSectionInterface; +/** + * Configuration section + */ class ConfigSection implements ConfigSectionInterface, ArrayAccess { - protected string $_name; - protected array $_items; + protected $_name; + protected $_items; - public function __construct(string $name = '', 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 = []) { $this->_name = $name; $this->_items = $items; } - #[\Override] - public function setName(string $name): static + /** + * Name the current section + * + * @param string $name Name of this section + * + * @return $this + */ + public function setName($name) { $this->_name = $name; return $this; } - #[\Override] - public function getName(): string + /** + * Get the name of the current section e.g. database + * + * @return string + */ + public function getName() { return $this->_name; } - #[\Override] - public function has(string $key): bool + /** + * Check to see if a config item exists within the configuration + * + * @param $key + * + * @return bool + */ + public function has($key) { return isset($this->_items[$key]); } - #[\Override] - public function getItem(string $key, mixed $default = null): mixed + /** + * 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) { if(isset($this->_items[$key])) { return $this->_items[$key]; } - if($default instanceof Exception) + else { - throw $default; + if($default instanceof Exception) + { + throw $default; + } + return $default; } - return $default; } - #[\Override] - public function getItems(): array + /** + * Retrieve all the items in the configuration section + * + * @return array + */ + public function getItems() { return $this->_items; } - #[\Override] - public function addItem(string $key, mixed $value): static + /** + * 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) { $this->_items[$key] = $value; return $this; } - public function addItems(array $keyValueItems): static + /** + * Add a new configuration item + * + * @param array $keyValueItems + * + * @return $this + */ + public function addItems(array $keyValueItems) { foreach($keyValueItems as $k => $v) { @@ -71,33 +124,90 @@ public function addItems(array $keyValueItems): static return $this; } - #[\Override] - public function removeItem(string $key): static + /** + * Remove a configuration item + * + * @param string $key Configuration item key e.g. hostname + * + * @return $this + */ + public function removeItem($key) { unset($this->_items[$key]); return $this; } - #[\Override] - public function offsetExists(mixed $offset): bool + /** + * (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 { return isset($this->_items[$offset]); } - #[\Override] - public function offsetGet(mixed $offset): mixed + /** + * (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) { return $this->getItem($offset); } - #[\Override] - public function offsetSet(mixed $offset, mixed $value): void + /** + * (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 { $this->addItem($offset, $value); } - #[\Override] - public function offsetUnset(mixed $offset): void + /** + * (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 { unset($this->_items[$offset]); } diff --git a/src/Provider/Ini/AbstractIniConfigProvider.php b/src/Provider/Ini/AbstractIniConfigProvider.php index c8a3c99..bfed470 100644 --- a/src/Provider/Ini/AbstractIniConfigProvider.php +++ b/src/Provider/Ini/AbstractIniConfigProvider.php @@ -9,8 +9,11 @@ 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(string $iniString, bool $parseEnv): void + protected function _loadString($iniString, $parseEnv) { if($parseEnv) { @@ -28,7 +31,12 @@ protected function _loadString(string $iniString, bool $parseEnv): void $this->_buildFromData($data); } - protected function _buildFromData(array $iniData): void + /** + * Build up the configuration from the sectioned array + * + * @param array $iniData + */ + protected function _buildFromData(array $iniData) { foreach($iniData as $section => $sectionData) { @@ -49,12 +57,16 @@ protected function _buildFromData(array $iniData): void * 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(string $iniString): string + protected function _parseEnvVars($iniString) { return preg_replace_callback( '/{{ENV:([0-9A-Za-z_]*)(:([^{}]*))?}}/', - function(array $matches): string { + function ($matches) { $varName = $matches[1]; $default = $matches[3] ?? ''; $value = getenv($varName); diff --git a/src/Provider/Ini/CachedIniConfigProvider.php b/src/Provider/Ini/CachedIniConfigProvider.php index f9f09a7..0e3b4c4 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 = [], ?string $filename = null, bool $parseEnv = false, int $cacheTTL = 5) + public function __construct(array $directories = [], $filename = null, $parseEnv = false, $cacheTTL = 5) { self::$_hasApcu = self::$_hasApcu ?? function_exists('apcu_fetch'); @@ -15,7 +15,7 @@ public function __construct(array $directories = [], ?string $filename = null, b } } - public function loadCached(array $directories, string $filename, bool $parseEnv = false, int $cacheTTL = 5): static + public function loadCached($directories, $filename, $parseEnv = false, $cacheTTL = 5) { $dirsHash = md5(implode('|', $directories)); $lastCheckKey = 'CachedIniCP:' . $dirsHash . ':lastCheck:' . $filename; diff --git a/src/Provider/Ini/IniConfigProvider.php b/src/Provider/Ini/IniConfigProvider.php index e6fd195..2e02b17 100644 --- a/src/Provider/Ini/IniConfigProvider.php +++ b/src/Provider/Ini/IniConfigProvider.php @@ -5,7 +5,11 @@ class IniConfigProvider extends AbstractIniConfigProvider { - public function __construct(?string $file = null, bool $parseEnv = false) + /** + * @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) { if($file !== null) { @@ -14,9 +18,15 @@ public function __construct(?string $file = null, bool $parseEnv = false) } /** - * @throws RuntimeException + * 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 */ - public function loadFile(string $fullPath, bool $parseEnv = false): static + public function loadFile($fullPath, $parseEnv = false) { if(!file_exists($fullPath)) { @@ -42,7 +52,16 @@ public function loadFile(string $fullPath, bool $parseEnv = false): static return $this; } - public function loadFiles(array $paths, bool $parseEnv = false, bool $throw = false): static + /** + * 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) { foreach($paths as $path) { @@ -62,9 +81,15 @@ public function loadFiles(array $paths, bool $parseEnv = false, bool $throw = fa } /** - * @throws RuntimeException + * 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 */ - public function loadString(string $iniString, bool $parseEnv = false): static + public function loadString($iniString, $parseEnv = false) { $this->_loadString($iniString, $parseEnv); return $this; diff --git a/src/Provider/Test/TestConfigProvider.php b/src/Provider/Test/TestConfigProvider.php index 7c9aaa4..ce75523 100644 --- a/src/Provider/Test/TestConfigProvider.php +++ b/src/Provider/Test/TestConfigProvider.php @@ -3,7 +3,15 @@ use Packaged\Config\Provider\ConfigProvider; -/** @deprecated Use \Packaged\Config\Provider\ConfigProvider directly */ +/** + * @deprecated \Packaged\Config\Provider\ConfigProvider + * + * Class TestConfigProvider + * + * Config provider for testing basics + * + * @package Packaged\Config\Provider\Test + */ class TestConfigProvider extends ConfigProvider { } diff --git a/src/Provider/Test/TestConfigSection.php b/src/Provider/Test/TestConfigSection.php index eb73e2f..6570af9 100644 --- a/src/Provider/Test/TestConfigSection.php +++ b/src/Provider/Test/TestConfigSection.php @@ -3,7 +3,15 @@ use Packaged\Config\Provider\ConfigSection; -/** @deprecated Use \Packaged\Config\Provider\ConfigSection directly */ +/** + * @deprecated \Packaged\Config\Provider\ConfigSection + * + * Class TestConfigSection + * + * Configuration section + * + * @package Packaged\Config\Provider\Test + */ class TestConfigSection extends ConfigSection { } diff --git a/tests/ConfigProviderBaseTest.php b/tests/ConfigProviderBaseTest.php index 36d416c..2c7f5fd 100644 --- a/tests/ConfigProviderBaseTest.php +++ b/tests/ConfigProviderBaseTest.php @@ -5,7 +5,6 @@ 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 @@ -16,7 +15,10 @@ public function testCanBeLoaded() $this->assertNotNull($provider); } - abstract public function getConfigProvider(): ConfigProviderInterface; + /** + * @return ConfigProviderInterface + */ + abstract public function getConfigProvider(); public function testValidProvider() { @@ -27,7 +29,9 @@ public function testValidProvider() ); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testCanAddItem() { $provider = $this->getConfigProvider(); @@ -54,7 +58,9 @@ public function testCanAddItem() ); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testCanAddItemAndRetrieve() { $provider = $this->getConfigProvider(); @@ -63,7 +69,9 @@ public function testCanAddItemAndRetrieve() $this->assertEquals("localhost", $item); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testCanAddItemAndRetrieveSection() { $provider = $this->getConfigProvider(); @@ -75,7 +83,9 @@ public function testCanAddItemAndRetrieveSection() ); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testCanAddRemoveItem() { $provider = $this->getConfigProvider(); @@ -85,7 +95,9 @@ public function testCanAddRemoveItem() $this->assertEquals("rm", $provider->getItem("db", "hostname", 'rm')); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testGetSections() { $provider = $this->getConfigProvider(); @@ -101,7 +113,9 @@ public function testGetSections() ); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testSectionAdd() { $section = new ConfigSection("db"); @@ -115,7 +129,9 @@ public function testSectionAdd() $provider->addSection($section); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testSectionSet() { $section = new ConfigSection("db"); @@ -127,7 +143,9 @@ public function testSectionSet() $provider->setSection($section); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testSectionGetItem() { $provider = $this->getConfigProvider(); @@ -136,7 +154,9 @@ public function testSectionGetItem() $this->assertEquals("localhost", $section->getItem("hostname", "notset")); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testMissingSectionThrows() { $provider = $this->getConfigProvider(); @@ -145,7 +165,9 @@ public function testMissingSectionThrows() $provider->getSection("database"); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testMissingSectionNoThrow() { $provider = $this->getConfigProvider(); @@ -154,7 +176,9 @@ public function testMissingSectionNoThrow() $this->assertEquals("missing", $section->getName()); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testGetMissingItem() { $provider = $this->getConfigProvider(); @@ -169,7 +193,9 @@ public function testGetMissingItem() $this->assertEquals("notset", $section->getItem("hostname", "notset")); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testDefaultExceptionThrown() { $provider = $this->getConfigProvider(); @@ -179,7 +205,9 @@ public function testDefaultExceptionThrown() $provider->getItem('', 'gone', new Exception("Config Item Not Found", 999)); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testSectionExists() { $provider = $this->getConfigProvider(); @@ -198,7 +226,9 @@ public function testSectionExists() $this->assertFalse($provider->sectionExists("database")); } - #[Depends('testValidProvider')] + /** + * @depends testValidProvider + */ public function testHasItem() { $provider = $this->getConfigProvider(); @@ -209,7 +239,9 @@ 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 55b068c..a9dc72f 100644 --- a/tests/ConfigProviderTest.php +++ b/tests/ConfigProviderTest.php @@ -6,7 +6,7 @@ class ConfigProviderTest extends ConfigProviderBaseTest { - public function getConfigProvider(): ConfigProvider + public function getConfigProvider() { return new ConfigProvider([]); } diff --git a/tests/ConfigSectionBaseTest.php b/tests/ConfigSectionBaseTest.php index ab6e50d..fcad5d9 100644 --- a/tests/ConfigSectionBaseTest.php +++ b/tests/ConfigSectionBaseTest.php @@ -14,7 +14,10 @@ public function testNameSetAndGet() $this->assertEquals("testing", $section->getName()); } - abstract public function getConfigSection(): ConfigSectionInterface; + /** + * @return ConfigSectionInterface + */ + abstract public function getConfigSection(); public function testCanAddItemAndRetrieve() { diff --git a/tests/ConfigSectionTest.php b/tests/ConfigSectionTest.php index 9f3c72f..0820fc0 100644 --- a/tests/ConfigSectionTest.php +++ b/tests/ConfigSectionTest.php @@ -30,7 +30,10 @@ public function testArrayAccess() $section->getItem('ghj', new Exception("Config Item Not Found", 999)); } - public function getConfigSection(): ConfigSection + /** + * @return ConfigSectionInterface + */ + public function getConfigSection() { return new ConfigSection(); } diff --git a/tests/ConfigurableTraitTest.php b/tests/ConfigurableTraitTest.php index 2089cc3..73a11f4 100644 --- a/tests/ConfigurableTraitTest.php +++ b/tests/ConfigurableTraitTest.php @@ -28,7 +28,10 @@ class MockConfigurableTrait { use ConfigurableTrait; - public function config(): ConfigSectionInterface + /** + * @return ConfigSectionInterface + */ + public function config() { return $this->_config(); } diff --git a/tests/IniCachedConfigProviderTest.php b/tests/IniCachedConfigProviderTest.php index 1658ada..829fca1 100644 --- a/tests/IniCachedConfigProviderTest.php +++ b/tests/IniCachedConfigProviderTest.php @@ -3,9 +3,10 @@ namespace Packaged\Config\Test; use Packaged\Config\Provider\Ini\CachedIniConfigProvider; -use PHPUnit\Framework\Attributes\RequiresPhpExtension; -#[RequiresPhpExtension('apcu')] +/** + * @requires extension apcu + */ class IniCachedConfigProviderTest extends ConfigProviderBaseTest { public function testMissingLoadFile() @@ -15,12 +16,15 @@ public function testMissingLoadFile() $this->assertSame($provider, $result); } - public function getConfigProvider(): CachedIniConfigProvider + /** + * @return CachedIniConfigProvider + */ + public function getConfigProvider() { return new CachedIniConfigProvider(); } - private function _dataDir(): array + private function _dataDir() { return [__DIR__ . '/testData']; } @@ -59,10 +63,6 @@ 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 9126c57..9a2c2a2 100644 --- a/tests/IniConfigProviderTest.php +++ b/tests/IniConfigProviderTest.php @@ -15,7 +15,7 @@ public function testMissingLoadFile() $provider->loadFile($file); } - public function getConfigProvider(): IniConfigProvider + public function getConfigProvider() { return new IniConfigProvider(); } diff --git a/tests/TestConfigProviderTest.php b/tests/TestConfigProviderTest.php index 33b48cf..e199b2a 100644 --- a/tests/TestConfigProviderTest.php +++ b/tests/TestConfigProviderTest.php @@ -6,7 +6,7 @@ class TestConfigProviderTest extends ConfigProviderBaseTest { - public function getConfigProvider(): TestConfigProvider + public function getConfigProvider() { return new TestConfigProvider(); } diff --git a/tests/TestConfigSectionTest.php b/tests/TestConfigSectionTest.php index 34eade8..7763e24 100644 --- a/tests/TestConfigSectionTest.php +++ b/tests/TestConfigSectionTest.php @@ -7,7 +7,10 @@ class TestConfigSectionTest extends ConfigSectionBaseTest { - public function getConfigSection(): TestConfigSection + /** + * @return ConfigSectionInterface + */ + public function getConfigSection() { return new TestConfigSection(); }