File tree Expand file tree Collapse file tree 3 files changed +71
-1
lines changed
Expand file tree Collapse file tree 3 files changed +71
-1
lines changed Original file line number Diff line number Diff line change @@ -1454,3 +1454,32 @@ function vipgoci_option_phpcs_runtime_set(
14541454 }
14551455}
14561456
1457+ /*
1458+ * Return options as key-value pairs that start
1459+ * with $start_with, but skip any options in
1460+ * $options_skip. Will sort the results according
1461+ * to key.
1462+ */
1463+ function vipgoci_options_get_starting_with (
1464+ array $ options ,
1465+ string $ starts_with ,
1466+ array $ options_skip
1467+ ) :array {
1468+ $ ret_vals = array ();
1469+
1470+ foreach ( array_keys ( $ options ) as $ option_name ) {
1471+ if ( 0 !== strpos ( $ option_name , $ starts_with ) ) {
1472+ continue ;
1473+ }
1474+
1475+ if ( in_array ( $ option_name , $ options_skip ) ) {
1476+ continue ;
1477+ }
1478+
1479+ $ ret_vals [ $ option_name ] = $ options [ $ option_name ];
1480+ }
1481+
1482+ ksort ( $ ret_vals );
1483+
1484+ return $ ret_vals ;
1485+ }
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ public function testGitHubPrsImplicatedIncludeDraftPrs() {
8888 );
8989
9090 $ this ->assertSame (
91- '80ebd6d65db88e87665b6ff1aa045f68d17ddeb7 ' ,
91+ '0d205d30dbd0917f53d00171a602806d964cd915 ' ,
9292 $ prs_implicated [9 ]->merge_commit_sha
9393 );
9494
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Vipgoci \tests ;
4+
5+ require_once ( __DIR__ . '/IncludesForTests.php ' );
6+
7+ use PHPUnit \Framework \TestCase ;
8+
9+ // phpcs:disable PSR1.Files.SideEffects
10+
11+ final class OptionsGetStartingWithTest extends TestCase {
12+ /**
13+ * @covers ::vipgoci_options_get_starting_with
14+ */
15+ public function testOptionsStartingWith () {
16+ $ expected = array (
17+ 'test0 ' => 't0 ' ,
18+ 'test2 ' => 't9 ' ,
19+ );
20+
21+ $ result = vipgoci_options_get_starting_with (
22+ array (
23+ 'test1 ' => 't1 ' ,
24+ 'test0 ' => 't0 ' ,
25+ 'test2 ' => 't9 ' ,
26+ 'atest3 ' => '999 ' ,
27+ 'atest4 ' => '888 ' ,
28+ 'atest0 ' => '777 '
29+ ),
30+ 'test ' ,
31+ array (
32+ 'test1 ' ,
33+ )
34+ );
35+
36+ $ this ->assertsame (
37+ $ expected ,
38+ $ result
39+ );
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments