Skip to content

Commit a60178d

Browse files
authored
Use yield in data providers (#292)
1 parent 7f99077 commit a60178d

3 files changed

Lines changed: 72 additions & 78 deletions

File tree

tests/Subscriber/StatusChangeByCommentSubscriberTest.php

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,41 @@ public function testOnIssueComment($comment, $expectedStatus)
6161
}
6262

6363
/**
64-
* @return array<array{string, string|null}>
64+
* @return iterable<array{string, string|null}>
6565
*/
66-
public static function getCommentsForStatusChange(): array
66+
public static function getCommentsForStatusChange(): iterable
6767
{
68-
return [
69-
['Have a great day!', null],
70-
// basic tests for status change
71-
['Status: needs review', Status::NEEDS_REVIEW],
72-
['Status: needs work', Status::NEEDS_WORK],
73-
['Status: reviewed', Status::REVIEWED],
74-
// accept quotes
75-
['Status: "reviewed"', Status::REVIEWED],
76-
["Status: 'reviewed'", Status::REVIEWED],
77-
// accept trailing punctuation
78-
['Status: works for me!', Status::WORKS_FOR_ME],
79-
['Status: works for me.', Status::WORKS_FOR_ME],
80-
// play with different formatting
81-
['STATUS: REVIEWED', Status::REVIEWED],
82-
['**Status**: reviewed', Status::REVIEWED],
83-
['**Status:** reviewed', Status::REVIEWED],
84-
['**Status: reviewed**', Status::REVIEWED],
85-
['**Status: reviewed!**', Status::REVIEWED],
86-
['**Status: reviewed**.', Status::REVIEWED],
87-
['Status:reviewed', Status::REVIEWED],
88-
['Status: reviewed', Status::REVIEWED],
89-
// reject missing colon
90-
['Status reviewed', null],
91-
// multiple matches - use the last one
92-
["Status: needs review \r\n that is what the issue *was* marked as.\r\n Status: reviewed", Status::REVIEWED],
93-
// "needs review" does not come directly after status: , so there is no status change
94-
['Here is my status: I\'m really happy! I realize this needs review, but I\'m, having too much fun Googling cats!', null],
95-
// reject if the status is not on a line of its own
96-
// use case: someone posts instructions about how to change a status
97-
// in a comment
98-
['You should include e.g. the line `Status: needs review` in your comment', null],
99-
['Before the ticket was in state "Status: reviewed", but then the status was changed', null],
100-
];
68+
yield ['Have a great day!', null];
69+
// basic tests for status change
70+
yield ['Status: needs review', Status::NEEDS_REVIEW];
71+
yield ['Status: needs work', Status::NEEDS_WORK];
72+
yield ['Status: reviewed', Status::REVIEWED];
73+
// accept quotes
74+
yield ['Status: "reviewed"', Status::REVIEWED];
75+
yield ["Status: 'reviewed'", Status::REVIEWED];
76+
// accept trailing punctuation
77+
yield ['Status: works for me!', Status::WORKS_FOR_ME];
78+
yield ['Status: works for me.', Status::WORKS_FOR_ME];
79+
// play with different formatting
80+
yield ['STATUS: REVIEWED', Status::REVIEWED];
81+
yield ['**Status**: reviewed', Status::REVIEWED];
82+
yield ['**Status:** reviewed', Status::REVIEWED];
83+
yield ['**Status: reviewed**', Status::REVIEWED];
84+
yield ['**Status: reviewed!**', Status::REVIEWED];
85+
yield ['**Status: reviewed**.', Status::REVIEWED];
86+
yield ['Status:reviewed', Status::REVIEWED];
87+
yield ['Status: reviewed', Status::REVIEWED];
88+
// reject missing colon
89+
yield ['Status reviewed', null];
90+
// multiple matches - use the last one
91+
yield ["Status: needs review \r\n that is what the issue *was* marked as.\r\n Status: reviewed", Status::REVIEWED];
92+
// "needs review" does not come directly after status: , so there is no status change
93+
yield ['Here is my status: I\'m really happy! I realize this needs review, but I\'m, having too much fun Googling cats!', null];
94+
// reject if the status is not on a line of its own
95+
// use case: someone posts instructions about how to change a status
96+
// in a comment
97+
yield ['You should include e.g. the line `Status: needs review` in your comment', null];
98+
yield ['Before the ticket was in state "Status: reviewed", but then the status was changed', null];
10199
}
102100

103101
public function testOnIssueCommentAuthorSelfReview(): void

tests/Subscriber/StatusChangeByReviewSubscriberTest.php

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,43 +65,41 @@ public function testOnReview($comment, $expectedStatus)
6565
}
6666

6767
/**
68-
* @return array<array{string, string|null}>
68+
* @return iterable<array{string, string|null}>
6969
*/
70-
public static function getCommentsForStatusChange(): array
70+
public static function getCommentsForStatusChange(): iterable
7171
{
72-
return [
73-
['Have a great day!', null],
74-
// basic tests for status change
75-
['Status: needs review', Status::NEEDS_REVIEW],
76-
['Status: needs work', Status::NEEDS_WORK],
77-
['Status: reviewed', Status::REVIEWED],
78-
// accept quotes
79-
['Status: "reviewed"', Status::REVIEWED],
80-
["Status: 'reviewed'", Status::REVIEWED],
81-
// accept trailing punctuation
82-
['Status: works for me!', Status::WORKS_FOR_ME],
83-
['Status: works for me.', Status::WORKS_FOR_ME],
84-
// play with different formatting
85-
['STATUS: REVIEWED', Status::REVIEWED],
86-
['**Status**: reviewed', Status::REVIEWED],
87-
['**Status:** reviewed', Status::REVIEWED],
88-
['**Status: reviewed**', Status::REVIEWED],
89-
['**Status: reviewed!**', Status::REVIEWED],
90-
['**Status: reviewed**.', Status::REVIEWED],
91-
['Status:reviewed', Status::REVIEWED],
92-
['Status: reviewed', Status::REVIEWED],
93-
// reject missing colon
94-
['Status reviewed', null],
95-
// multiple matches - use the last one
96-
["Status: needs review \r\n that is what the issue *was* marked as.\r\n Status: reviewed", Status::REVIEWED],
97-
// "needs review" does not come directly after status: , so there is no status change
98-
['Here is my status: I\'m really happy! I realize this needs review, but I\'m, having too much fun Googling cats!', null],
99-
// reject if the status is not on a line of its own
100-
// use case: someone posts instructions about how to change a status
101-
// in a comment
102-
['You should include e.g. the line `Status: needs review` in your comment', null],
103-
['Before the ticket was in state "Status: reviewed", but then the status was changed', null],
104-
];
72+
yield ['Have a great day!', null];
73+
// basic tests for status change
74+
yield ['Status: needs review', Status::NEEDS_REVIEW];
75+
yield ['Status: needs work', Status::NEEDS_WORK];
76+
yield ['Status: reviewed', Status::REVIEWED];
77+
// accept quotes
78+
yield ['Status: "reviewed"', Status::REVIEWED];
79+
yield ["Status: 'reviewed'", Status::REVIEWED];
80+
// accept trailing punctuation
81+
yield ['Status: works for me!', Status::WORKS_FOR_ME];
82+
yield ['Status: works for me.', Status::WORKS_FOR_ME];
83+
// play with different formatting
84+
yield ['STATUS: REVIEWED', Status::REVIEWED];
85+
yield ['**Status**: reviewed', Status::REVIEWED];
86+
yield ['**Status:** reviewed', Status::REVIEWED];
87+
yield ['**Status: reviewed**', Status::REVIEWED];
88+
yield ['**Status: reviewed!**', Status::REVIEWED];
89+
yield ['**Status: reviewed**.', Status::REVIEWED];
90+
yield ['Status:reviewed', Status::REVIEWED];
91+
yield ['Status: reviewed', Status::REVIEWED];
92+
// reject missing colon
93+
yield ['Status reviewed', null];
94+
// multiple matches - use the last one
95+
yield ["Status: needs review \r\n that is what the issue *was* marked as.\r\n Status: reviewed", Status::REVIEWED];
96+
// "needs review" does not come directly after status: , so there is no status change
97+
yield ['Here is my status: I\'m really happy! I realize this needs review, but I\'m, having too much fun Googling cats!', null];
98+
// reject if the status is not on a line of its own
99+
// use case: someone posts instructions about how to change a status
100+
// in a comment
101+
yield ['You should include e.g. the line `Status: needs review` in your comment', null];
102+
yield ['Before the ticket was in state "Status: reviewed", but then the status was changed', null];
105103
}
106104

107105
#[DataProviderExternal(ValidCommandProvider::class, 'get')]

tests/Subscriber/StatusChangeOnPushSubscriberTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@ public function testOnPushingCommits($currentStatus, $statusChange)
6464
}
6565

6666
/**
67-
* @return array<array{string, string|null}>
67+
* @return iterable<array{string, string|null}>
6868
*/
69-
public static function getStatuses(): array
69+
public static function getStatuses(): iterable
7070
{
71-
return [
72-
[Status::NEEDS_WORK, Status::NEEDS_REVIEW],
73-
[Status::REVIEWED, null],
74-
[Status::WORKS_FOR_ME, null],
75-
[Status::NEEDS_REVIEW, null],
76-
];
71+
yield [Status::NEEDS_WORK, Status::NEEDS_REVIEW];
72+
yield [Status::REVIEWED, null];
73+
yield [Status::WORKS_FOR_ME, null];
74+
yield [Status::NEEDS_REVIEW, null];
7775
}
7876

7977
public function testOnNonPushPullRequestEvent()

0 commit comments

Comments
 (0)