Skip to content

Commit 5a068b1

Browse files
authored
Merge pull request #58 from keboola/tf-make-run-optional-as-before
Make "run" default action if missing in config
2 parents 26d67e4 + 4551880 commit 5a068b1

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ If any constraint of config definition is not met a `UserException` is thrown. T
179179

180180
## Migration from version 6 to version 7
181181

182-
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.
182+
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.
183183

184184
## More reading
185185

src/Config/BaseConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function getAuthorization(): array
136136
*/
137137
public function getAction(): string
138138
{
139-
return $this->getValue(['action'], '');
139+
return $this->getValue(['action'], 'run');
140140
}
141141

142142
/**

tests/BaseComponentTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ protected function run(): void
102102
$this->assertTrue($handler->hasAlert('Log message from run'));
103103
}
104104

105+
public function testWillNotFailWithEmptyConfigAction(): void
106+
{
107+
$logger = $this->getLogger();
108+
$handler = new TestHandler();
109+
$logger->setHandlers([$handler]);
110+
putenv(sprintf(
111+
'KBC_DATADIR=%s',
112+
__DIR__ . '/fixtures/base-component-data-dir/empty-config-file'
113+
));
114+
$baseComponent = new class ($logger) extends BaseComponent
115+
{
116+
protected function run(): void
117+
{
118+
echo 'Shitty output';
119+
$this->getLogger()->alert('Log message from run');
120+
}
121+
};
122+
$this->expectOutputString('Shitty output');
123+
$baseComponent->execute();
124+
125+
$this->assertTrue($handler->hasAlert('Log message from run'));
126+
}
127+
105128
public function testLoadInputStateFileEmptyThrowsException(): void
106129
{
107130
putenv(sprintf(

tests/Config/BaseConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testGettersWillNotFailIfKeyIsMissing(): void
108108
],
109109
]);
110110
$this->assertSame([], $config->getParameters());
111-
$this->assertSame('', $config->getAction());
111+
$this->assertSame('run', $config->getAction());
112112
$this->assertSame([], $config->getAuthorization());
113113
$this->assertSame('', $config->getOAuthApiAppKey());
114114
$this->assertSame('', $config->getOAuthApiAppSecret());
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

0 commit comments

Comments
 (0)