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 ...@@ -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 [ yield 'no configuration and no environment variable' => [
'no configuration and no environment variable' => [ [],
[], null,
null, false,
false, ];
], yield 'empty configuration and no environment variable' => [
'empty configuration and no environment variable' => [ [
[ 'dummy' => [],
'dummy' => [],
],
null,
false,
],
'truthy configuration and no environment variable' => [
[
'dummy' => [
'enable' => true,
],
],
null,
true,
], ],
'truthy configuration and falsy environment variable' => [ null,
[ false,
'dummy' => [ ];
'enable' => true, yield 'truthy configuration and no environment variable' => [
], [
'dummy' => [
'enable' => true,
], ],
'0',
false,
], ],
'falsy configuration and truthy environment variable' => [ null,
[ true,
'dummy' => [ ];
'enable' => false, yield 'truthy configuration and falsy environment variable' => [
], [
'dummy' => [
'enable' => true,
], ],
'1',
true,
], ],
'empty configuration and truthy environment variable' => [ '0',
[ false,
'dummy' => [], ];
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 ...@@ -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 [ yield 'no service configuration' => [
'no service configuration' => [ [],
[], ];
], yield 'available service configuration' => [
'available service configuration' => [ [
[ 'email' => [],
'email' => [],
],
], ],
'missing URL configuration' => [ ];
[ yield 'missing URL configuration' => [
'email' => [ [
'sender' => 'foo', 'email' => [
'receivers' => 'baz', 'sender' => 'foo',
], 'receivers' => 'baz',
], ],
], ],
]; ];
} }
/** /**
* @return array<string, array> * @return \Generator<string, array>
*/ */
public function reportSendsUpdateReportSuccessfullyDataProvider(): array public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{ {
return [ yield 'secure package' => [
'secure package' => [ false,
false, '',
'', ];
], yield 'insecure package' => [
'insecure package' => [ true,
true, ' <strong style="color: red;">(insecure)</strong>',
' <strong style="color: red;">(insecure)</strong>',
],
]; ];
} }
......
...@@ -211,43 +211,39 @@ class GitLabTest extends AbstractTestCase ...@@ -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 [ yield 'no service configuration' => [
'no service configuration' => [ [],
[], ];
], yield 'available service configuration' => [
'available service configuration' => [ [
[ 'gitlab' => [],
'gitlab' => [],
],
], ],
'missing URL configuration' => [ ];
[ yield 'missing URL configuration' => [
'gitlab' => [ [
'authKey' => 'foo', 'gitlab' => [
], 'authKey' => 'foo',
], ],
], ],
]; ];
} }
/** /**
* @return array<string, array> * @return \Generator<string, array>
*/ */
public function reportSendsUpdateReportSuccessfullyDataProvider(): array public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{ {
return [ yield 'secure package' => [
'secure package' => [ false,
false, '',
'', ];
], yield 'insecure package' => [
'insecure package' => [ true,
true, ' (insecure)',
' (insecure)',
],
]; ];
} }
......
...@@ -226,43 +226,39 @@ class MattermostTest extends AbstractTestCase ...@@ -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 [ yield 'no service configuration' => [
'no service configuration' => [ [],
[], ];
], yield 'available service configuration' => [
'available service configuration' => [ [
[ 'mattermost' => [],
'mattermost' => [],
],
], ],
'missing URL configuration' => [ ];
[ yield 'missing URL configuration' => [
'mattermost' => [ [
'channel' => 'foo', 'mattermost' => [
], 'channel' => 'foo',
], ],
], ],
]; ];
} }
/** /**
* @return array<string, array> * @return \Generator<string, array>
*/ */
public function reportSendsUpdateReportSuccessfullyDataProvider(): array public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{ {
return [ yield 'secure package' => [
'secure package' => [ false,
false, '',
'', ];
], yield 'insecure package' => [
'insecure package' => [ true,
true, ' :warning: **`insecure`**',
' :warning: **`insecure`**',
],
]; ];
} }
......
...@@ -272,42 +272,34 @@ class SlackTest extends AbstractTestCase ...@@ -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 [ yield 'no service configuration' => [
'no service configuration' => [ [],
[], ];
], yield 'available service configuration' => [
'available service configuration' => [ [
[ 'slack' => [],
'slack' => [],
],
], ],
'missing URL configuration' => [ ];
[ yield 'missing URL configuration' => [
'slack' => [ [
'enable' => true, 'slack' => [
], 'enable' => true,
], ],
], ],
]; ];
} }
/** /**
* @return array<string, array> * @return \Generator<string, array>
*/ */
public function reportSendsUpdateReportSuccessfullyDataProvider(): array public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{ {
return [ yield 'secure package' => [false];
'secure package' => [ yield 'insecure package' => [true];
false,
],
'insecure package' => [
true,
],
];
} }
protected function tearDown(): void protected function tearDown(): void
......
...@@ -182,43 +182,39 @@ class TeamsTest extends AbstractTestCase ...@@ -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 [ yield 'no service configuration' => [
'no service configuration' => [ [],
[], ];
], yield 'available service configuration' => [
'available service configuration' => [ [
[ 'teams' => [],
'teams' => [],
],
], ],
'missing URL configuration' => [ ];
[ yield 'missing URL configuration' => [
'teams' => [ [
'foo' => 'baz', 'teams' => [
], 'foo' => 'baz',
], ],
], ],
]; ];
} }
/** /**
* @return array<string, array> * @return \Generator<string, array>
*/ */
public function reportSendsUpdateReportSuccessfullyDataProvider(): array public function reportSendsUpdateReportSuccessfullyDataProvider(): \Generator
{ {
return [ yield 'secure package' => [
'secure package' => [ false,
false, '',
'', ];
], yield 'insecure package' => [
'insecure package' => [ true,
true, sprintf(' (%s insecure)', Emoji::warning()),
sprintf(' (%s insecure)', Emoji::warning()),
],
]; ];
} }
......
...@@ -56,62 +56,58 @@ class UtilTest extends AbstractTestCase ...@@ -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 [ yield 'only lowercase' => [
'only lowercase' => [ 'foo',
'foo', 'foo',
'foo', ];
], yield 'only uppercase' => [
'only uppercase' => [ 'FOO',
'FOO', 'F_O_O',
'F_O_O', ];
], yield 'camel case' => [
'camel case' => [ 'FooBaz',
'FooBaz', 'Foo_Baz',
'Foo_Baz',
],
]; ];
} }
/** /**
* @return array<string, array> * @return \Generator<string, array>
*/ */
public function arrayDiffRecursiveReturnsDiffBetweenArraysDataProvider(): array public function arrayDiffRecursiveReturnsDiffBetweenArraysDataProvider(): \Generator
{ {
return [ yield 'empty arrays' => [
'empty arrays' => [ [],
[], [],
[], [],
[], ];
], yield 'empty first array' => [
'empty first array' => [ [],
[], ['foo' => 'baz'],
['foo' => 'baz'], [],
[], ];
], yield 'empty second array' => [
'empty second array' => [ ['foo' => 'baz'],
['foo' => 'baz'], [],
[], ['foo' => 'baz'],
['foo' => 'baz'], ];
], yield 'diff on first level' => [
'diff on first level' => [ ['foo' => 'baz'],
['foo' => 'baz'], ['baz' => 'foo'],
['baz' => 'foo'], ['foo' => 'baz'],
['foo' => 'baz'], ];
], yield 'diff on deeper level' => [
'diff on deeper level' => [ ['foo' => ['baz' => 'bummer']],
['foo' => ['baz' => 'bummer']], ['foo' => ['foo' => 'bummer']],
['foo' => ['foo' => 'bummer']], ['foo' => ['baz' => 'bummer']],
['foo' => ['baz' => 'bummer']], ];
], yield 'equal multi-dimensional arrays' => [
'equal multi-dimensional arrays' => [ ['foo' => ['baz' => 'bummer']],
['foo' => ['baz' => 'bummer']], ['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