Verified Commit ad4371aa authored by Elias Häußler's avatar Elias Häußler 🐛
Browse files

[TASK] Use Generators for data providers in Unit tests

parent d57c7f91
......@@ -119,62 +119,60 @@ class AbstractServiceTest extends AbstractTestCase
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function isEnabledReturnsStateOfAvailabilityDataProvider(): array
public function isEnabledReturnsStateOfAvailabilityDataProvider(): \Generator
{
return [
'no configuration and no environment variable' => [
[],
null,
false,
],
'empty configuration and no environment variable' => [
[
'dummy' => [],
],
null,
false,
],
'truthy configuration and no environment variable' => [
[
'dummy' => [
'enable' => true,
],
],
null,
true,
yield 'no configuration and no environment variable' => [
[],
null,
false,
];
yield 'empty configuration and no environment variable' => [
[
'dummy' => [],
],
'truthy configuration and falsy environment variable' => [
[
'dummy' => [
'enable' => true,
],
null,
false,
];
yield 'truthy configuration and no environment variable' => [
[
'dummy' => [
'enable' => true,
],
'0',
false,
],
'falsy configuration and truthy environment variable' => [
[
'dummy' => [
'enable' => false,
],
null,
true,
];
yield 'truthy configuration and falsy environment variable' => [
[
'dummy' => [
'enable' => true,
],
'1',
true,
],
'empty configuration and truthy environment variable' => [
[
'dummy' => [],
'0',
false,
];
yield 'falsy configuration and truthy environment variable' => [
[
'dummy' => [
'enable' => false,
],
'1',
true,
],
'no configuration and truthy environment variable' => [
[],
'1',
true,
'1',
true,
];
yield 'empty configuration and truthy environment variable' => [
[
'dummy' => [],
],
'1',
true,
];
yield 'no configuration and truthy environment variable' => [
[],
'1',
true,
];
}
......
......@@ -330,44 +330,40 @@ class EmailTest extends AbstractTestCase
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function fromConfigurationThrowsExceptionIfEmailDsnIsNotSetDataProvider(): array
public function fromConfigurationThrowsExceptionIfEmailDsnIsNotSetDataProvider(): \Generator
{
return [
'no service configuration' => [
[],
],
'available service configuration' => [
[
'email' => [],
],
yield 'no service configuration' => [
[],
];
yield 'available service configuration' => [
[
'email' => [],
],
'missing URL configuration' => [
[
'email' => [
'sender' => 'foo',
'receivers' => 'baz',
],
];
yield 'missing URL configuration' => [
[
'email' => [
'sender' => 'foo',
'receivers' => 'baz',
],
],
];
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function reportSendsUpdateReportSuccessfullyDataProvider(): array
public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{
return [
'secure package' => [
false,
'',
],
'insecure package' => [
true,
' <strong style="color: red;">(insecure)</strong>',
],
yield 'secure package' => [
false,
'',
];
yield 'insecure package' => [
true,
' <strong style="color: red;">(insecure)</strong>',
];
}
......
......@@ -211,43 +211,39 @@ class GitLabTest extends AbstractTestCase
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function fromConfigurationThrowsExceptionIfGitLabUrlIsNotSetDataProvider(): array
public function fromConfigurationThrowsExceptionIfGitLabUrlIsNotSetDataProvider(): \Generator
{
return [
'no service configuration' => [
[],
],
'available service configuration' => [
[
'gitlab' => [],
],
yield 'no service configuration' => [
[],
];
yield 'available service configuration' => [
[
'gitlab' => [],
],
'missing URL configuration' => [
[
'gitlab' => [
'authKey' => 'foo',
],
];
yield 'missing URL configuration' => [
[
'gitlab' => [
'authKey' => 'foo',
],
],
];
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function reportSendsUpdateReportSuccessfullyDataProvider(): array
public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{
return [
'secure package' => [
false,
'',
],
'insecure package' => [
true,
' (insecure)',
],
yield 'secure package' => [
false,
'',
];
yield 'insecure package' => [
true,
' (insecure)',
];
}
......
......@@ -226,43 +226,39 @@ class MattermostTest extends AbstractTestCase
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function fromConfigurationThrowsExceptionIfMattermostUrlIsNotSetDataProvider(): array
public function fromConfigurationThrowsExceptionIfMattermostUrlIsNotSetDataProvider(): \Generator
{
return [
'no service configuration' => [
[],
],
'available service configuration' => [
[
'mattermost' => [],
],
yield 'no service configuration' => [
[],
];
yield 'available service configuration' => [
[
'mattermost' => [],
],
'missing URL configuration' => [
[
'mattermost' => [
'channel' => 'foo',
],
];
yield 'missing URL configuration' => [
[
'mattermost' => [
'channel' => 'foo',
],
],
];
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function reportSendsUpdateReportSuccessfullyDataProvider(): array
public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{
return [
'secure package' => [
false,
'',
],
'insecure package' => [
true,
' :warning: **`insecure`**',
],
yield 'secure package' => [
false,
'',
];
yield 'insecure package' => [
true,
' :warning: **`insecure`**',
];
}
......
......@@ -272,42 +272,34 @@ class SlackTest extends AbstractTestCase
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function fromConfigurationThrowsExceptionIfSlackUrlIsNotSetDataProvider(): array
public function fromConfigurationThrowsExceptionIfSlackUrlIsNotSetDataProvider(): \Generator
{
return [
'no service configuration' => [
[],
],
'available service configuration' => [
[
'slack' => [],
],
yield 'no service configuration' => [
[],
];
yield 'available service configuration' => [
[
'slack' => [],
],
'missing URL configuration' => [
[
'slack' => [
'enable' => true,
],
];
yield 'missing URL configuration' => [
[
'slack' => [
'enable' => true,
],
],
];
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function reportSendsUpdateReportSuccessfullyDataProvider(): array
public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{
return [
'secure package' => [
false,
],
'insecure package' => [
true,
],
];
yield 'secure package' => [false];
yield 'insecure package' => [true];
}
protected function tearDown(): void
......
......@@ -182,43 +182,39 @@ class TeamsTest extends AbstractTestCase
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function fromConfigurationThrowsExceptionIfTeamsUrlIsNotSetDataProvider(): array
public function fromConfigurationThrowsExceptionIfTeamsUrlIsNotSetDataProvider(): \Generator
{
return [
'no service configuration' => [
[],
],
'available service configuration' => [
[
'teams' => [],
],
yield 'no service configuration' => [
[],
];
yield 'available service configuration' => [
[
'teams' => [],
],
'missing URL configuration' => [
[
'teams' => [
'foo' => 'baz',
],
];
yield 'missing URL configuration' => [
[
'teams' => [
'foo' => 'baz',
],
],
];
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function reportSendsUpdateReportSuccessfullyDataProvider(): array
public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{
return [
'secure package' => [
false,
'',
],
'insecure package' => [
true,
sprintf(' (%s insecure)', Emoji::warning()),
],
yield 'secure package' => [
false,
'',
];
yield 'insecure package' => [
true,
sprintf(' (%s insecure)', Emoji::warning()),
];
}
......
......@@ -56,62 +56,58 @@ class UtilTest extends AbstractTestCase
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function uppercaseToUnderscoredReturnsUnderscoredStringDataProvider(): array
public function uppercaseToUnderscoredReturnsUnderscoredStringDataProvider(): \Generator
{
return [
'only lowercase' => [
'foo',
'foo',
],
'only uppercase' => [
'FOO',
'F_O_O',
],
'camel case' => [
'FooBaz',
'Foo_Baz',
],
yield 'only lowercase' => [
'foo',
'foo',
];
yield 'only uppercase' => [
'FOO',
'F_O_O',
];
yield 'camel case' => [
'FooBaz',
'Foo_Baz',
];
}
/**
* @return array<string, array>
* @return \Generator<string, array>
*/
public function arrayDiffRecursiveReturnsDiffBetweenArraysDataProvider(): array
public function arrayDiffRecursiveReturnsDiffBetweenArraysDataProvider(): \Generator
{
return [
'empty arrays' => [
[],
[],
[],
],
'empty first array' => [
[],
['foo' => 'baz'],
[],
],
'empty second array' => [
['foo' => 'baz'],
[],
['foo' => 'baz'],
],
'diff on first level' => [
['foo' => 'baz'],
['baz' => 'foo'],
['foo' => 'baz'],
],
'diff on deeper level' => [
['foo' => ['baz' => 'bummer']],
['foo' => ['foo' => 'bummer']],
['foo' => ['baz' => 'bummer']],
],
'equal multi-dimensional arrays' => [
['foo' => ['baz' => 'bummer']],
['foo' => ['baz' => 'bummer']],
[],
],
yield 'empty arrays' => [
[],
[],
[],
];
yield 'empty first array' => [
[],
['foo' => 'baz'],
[],
];
yield 'empty second array' => [
['foo' => 'baz'],
[],
['foo' => 'baz'],
];
yield 'diff on first level' => [
['foo' => 'baz'],
['baz' => 'foo'],
['foo' => 'baz'],
];
yield 'diff on deeper level' => [
['foo' => ['baz' => 'bummer']],
['foo' => ['foo' => 'bummer']],
['foo' => ['baz' => 'bummer']],
];
yield 'equal multi-dimensional arrays' => [
['foo' => ['baz' => 'bummer']],
['foo' => ['baz' => 'bummer']],
[],
];
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment