diff --git a/CHANGELOG.md b/CHANGELOG.md index a7a2bb9..7a94c6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.2.0](https://github.com/crowdsecurity/php-capi-client/releases/tag/v0.2.0) - 2022-10-28 +[_Compare with previous release_](https://github.com/crowdsecurity/php-capi-client/compare/v0.1.0...v0.2.0) + +### Changed +- *Breaking change*: Missing `scenarios` key in `configs` will throw an exception + +--- + ## [0.1.0](https://github.com/crowdsecurity/php-capi-client/releases/tag/v0.1.0) - 2022-10-21 [_Compare with previous release_](https://github.com/crowdsecurity/php-capi-client/compare/v0.0.1...v0.1.0) diff --git a/src/Configuration.php b/src/Configuration.php index 747b024..ea02300 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -59,7 +59,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->thenInvalid('Invalid user agent suffix. Length must be <= 16. Allowed chars are A-Za-z0-9') ->end() ->end() - ->arrayNode('scenarios')->cannotBeEmpty() + ->arrayNode('scenarios')->isRequired()->cannotBeEmpty() ->validate() ->ifArray() ->then(function (array $value) { diff --git a/src/Constants.php b/src/Constants.php index b746563..dc0ff2d 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -39,5 +39,5 @@ class Constants /** * @var string The current version of this library */ - public const VERSION = 'v0.1.0'; + public const VERSION = 'v0.2.0'; } diff --git a/tests/Unit/CurlTest.php b/tests/Unit/CurlTest.php index bc590d5..3546b0b 100644 --- a/tests/Unit/CurlTest.php +++ b/tests/Unit/CurlTest.php @@ -222,7 +222,7 @@ public function testOptions() $url = Constants::URL_DEV . 'watchers'; $method = 'POST'; $parameters = ['machine_id' => 'test', 'password' => 'test']; - $configs = []; + $configs = ['scenarios' => TestConstants::SCENARIOS]; $client = new Watcher($configs, new FileStorage()); $curlRequester = $client->getRequestHandler(); diff --git a/tests/Unit/WatcherTest.php b/tests/Unit/WatcherTest.php index ecdb6bd..5bad28d 100644 --- a/tests/Unit/WatcherTest.php +++ b/tests/Unit/WatcherTest.php @@ -356,6 +356,20 @@ public function testConfigure() 'Scenarios should be indexed array' ); + $error = ''; + try { + new Watcher([], new FileStorage()); + } catch (Exception $e) { + $error = $e->getMessage(); + } + + PHPUnitUtil::assertRegExp( + $this, + '/The child config "scenarios" under "config" must be configured./', + $error, + 'Scenarios key must be in configs' + ); + $error = ''; try { new Watcher(['scenarios' => []], new FileStorage()); @@ -412,7 +426,7 @@ public function testConfigure() 'machine_id_prefix should contain allowed chars' ); - $client = new Watcher(['machine_id_prefix' => ''], new FileStorage()); + $client = new Watcher(['scenarios' => TestConstants::SCENARIOS, 'machine_id_prefix' => ''], new FileStorage()); $this->assertEquals( '', @@ -448,7 +462,7 @@ public function testConfigure() 'user_agent_suffix should contain allowed chars' ); - $client = new Watcher(['user_agent_suffix' => ''], new FileStorage()); + $client = new Watcher(['scenarios' => TestConstants::SCENARIOS, 'user_agent_suffix' => ''], new FileStorage()); $this->assertEquals( '',