diff --git a/README.md b/README.md index e63d55a4..1e3ad437 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ If any constraint of config definition is not met a `UserException` is thrown. T ## Migration from version 6 to version 7 -The default entrypoint of component (in `index.php`) changed from `BaseComponent::run()` to `BaseComponent::execute()`. While running the component via `run` method is still supported, you need to use `execute()` if you want to take advantage of sync action support. +The default entrypoint of component (in `index.php`) changed from `BaseComponent::run()` to `BaseComponent::execute()`. Please also note, that the `run` method can no longer be public and can only be called from inside the component now. ## More reading diff --git a/src/Config/BaseConfig.php b/src/Config/BaseConfig.php index 4e69df3a..4b351638 100644 --- a/src/Config/BaseConfig.php +++ b/src/Config/BaseConfig.php @@ -136,7 +136,7 @@ public function getAuthorization(): array */ public function getAction(): string { - return $this->getValue(['action'], ''); + return $this->getValue(['action'], 'run'); } /** diff --git a/tests/BaseComponentTest.php b/tests/BaseComponentTest.php index da0cc3d3..6e000828 100644 --- a/tests/BaseComponentTest.php +++ b/tests/BaseComponentTest.php @@ -102,6 +102,29 @@ protected function run(): void $this->assertTrue($handler->hasAlert('Log message from run')); } + public function testWillNotFailWithEmptyConfigAction(): void + { + $logger = $this->getLogger(); + $handler = new TestHandler(); + $logger->setHandlers([$handler]); + putenv(sprintf( + 'KBC_DATADIR=%s', + __DIR__ . '/fixtures/base-component-data-dir/empty-config-file' + )); + $baseComponent = new class ($logger) extends BaseComponent + { + protected function run(): void + { + echo 'Shitty output'; + $this->getLogger()->alert('Log message from run'); + } + }; + $this->expectOutputString('Shitty output'); + $baseComponent->execute(); + + $this->assertTrue($handler->hasAlert('Log message from run')); + } + public function testLoadInputStateFileEmptyThrowsException(): void { putenv(sprintf( diff --git a/tests/Config/BaseConfigTest.php b/tests/Config/BaseConfigTest.php index 12dd2820..455aa6db 100644 --- a/tests/Config/BaseConfigTest.php +++ b/tests/Config/BaseConfigTest.php @@ -108,7 +108,7 @@ public function testGettersWillNotFailIfKeyIsMissing(): void ], ]); $this->assertSame([], $config->getParameters()); - $this->assertSame('', $config->getAction()); + $this->assertSame('run', $config->getAction()); $this->assertSame([], $config->getAuthorization()); $this->assertSame('', $config->getOAuthApiAppKey()); $this->assertSame('', $config->getOAuthApiAppSecret()); diff --git a/tests/fixtures/base-component-data-dir/empty-config-file/config.json b/tests/fixtures/base-component-data-dir/empty-config-file/config.json new file mode 100644 index 00000000..2c63c085 --- /dev/null +++ b/tests/fixtures/base-component-data-dir/empty-config-file/config.json @@ -0,0 +1,2 @@ +{ +}