@@ -459,4 +459,118 @@ public function test_behat_tags_skip_db_type(): void {
459459
460460 putenv ( false === $ env_github_token ? 'GITHUB_TOKEN ' : "GITHUB_TOKEN= $ env_github_token " );
461461 }
462+
463+ /**
464+ * Write a feature file carrying the given tag.
465+ *
466+ * @param string $tag
467+ */
468+ private function write_tagged_feature ( $ tag ): void {
469+ file_put_contents (
470+ $ this ->temp_dir . DIRECTORY_SEPARATOR . 'features ' . DIRECTORY_SEPARATOR . 'tagged.feature ' ,
471+ $ tag . "\nFeature: Tagged \n"
472+ );
473+ }
474+
475+ /**
476+ * Run the script with the given environment, restoring it afterwards.
477+ *
478+ * @param array<string, ?string> $env Variables to set, or null to unset.
479+ * @return string|false
480+ */
481+ private function run_with_env ( array $ env ) {
482+ $ previous = array ();
483+
484+ foreach ( $ env as $ name => $ value ) {
485+ $ current = getenv ( $ name );
486+ $ previous [ $ name ] = false === $ current ? null : $ current ;
487+
488+ putenv ( null === $ value ? $ name : "{$ name }= {$ value }" );
489+ }
490+
491+ try {
492+ return $ this ->run_behat_tags_script ();
493+ } finally {
494+ foreach ( $ previous as $ name => $ value ) {
495+ putenv ( null === $ value ? $ name : "{$ name }= {$ value }" );
496+ }
497+ }
498+ }
499+
500+ public function test_require_wp_stable_is_skipped_for_an_archive (): void {
501+ $ this ->write_tagged_feature ( '@require-wp-stable ' );
502+
503+ $ output = $ this ->run_with_env (
504+ array (
505+ 'WP_VERSION ' => '6.4.2 ' ,
506+ 'WP_CLI_TEST_CORE_ZIP ' => $ this ->temp_dir . DIRECTORY_SEPARATOR . 'wordpress.zip ' ,
507+ )
508+ );
509+
510+ $ this ->assertStringContainsString ( '~@require-wp-stable ' , (string ) $ output );
511+ }
512+
513+ public function test_require_wp_stable_is_skipped_on_trunk (): void {
514+ $ this ->write_tagged_feature ( '@require-wp-stable ' );
515+
516+ $ output = $ this ->run_with_env (
517+ array (
518+ 'WP_VERSION ' => 'trunk ' ,
519+ 'WP_CLI_TEST_CORE_ZIP ' => null ,
520+ )
521+ );
522+
523+ $ this ->assertStringContainsString ( '~@require-wp-stable ' , (string ) $ output );
524+ }
525+
526+ public function test_require_wp_stable_runs_on_a_release (): void {
527+ $ this ->write_tagged_feature ( '@require-wp-stable ' );
528+
529+ $ output = $ this ->run_with_env (
530+ array (
531+ 'WP_VERSION ' => '6.4.2 ' ,
532+ 'WP_CLI_TEST_CORE_ZIP ' => null ,
533+ )
534+ );
535+
536+ $ this ->assertStringNotContainsString ( '@require-wp-stable ' , (string ) $ output );
537+ }
538+
539+ public function test_require_mysql_socket_is_skipped_without_a_socket (): void {
540+ $ this ->write_tagged_feature ( '@require-mysql-socket ' );
541+
542+ $ output = $ this ->run_with_env (
543+ array ( 'WP_CLI_TEST_DBSOCKET ' => $ this ->temp_dir . DIRECTORY_SEPARATOR . 'missing.sock ' )
544+ );
545+
546+ $ this ->assertStringContainsString ( '~@require-mysql-socket ' , (string ) $ output );
547+ }
548+
549+ public function test_require_mysql_socket_runs_with_a_socket (): void {
550+ $ this ->write_tagged_feature ( '@require-mysql-socket ' );
551+
552+ $ socket = $ this ->temp_dir . DIRECTORY_SEPARATOR . 'mysql.sock ' ;
553+ touch ( $ socket );
554+
555+ $ output = $ this ->run_with_env ( array ( 'WP_CLI_TEST_DBSOCKET ' => $ socket ) );
556+
557+ $ this ->assertStringNotContainsString ( '@require-mysql-socket ' , (string ) $ output );
558+ }
559+
560+ /**
561+ * Tags no scenario carries do not need to be filtered out.
562+ */
563+ public function test_unused_tags_are_not_filtered_out (): void {
564+ $ this ->write_tagged_feature ( '@some-other-tag ' );
565+
566+ $ output = $ this ->run_with_env (
567+ array (
568+ 'WP_VERSION ' => 'trunk ' ,
569+ 'WP_CLI_TEST_DBSOCKET ' => $ this ->temp_dir . DIRECTORY_SEPARATOR . 'missing.sock ' ,
570+ )
571+ );
572+
573+ $ this ->assertStringNotContainsString ( '@require-wp-stable ' , (string ) $ output );
574+ $ this ->assertStringNotContainsString ( '@require-mysql-socket ' , (string ) $ output );
575+ }
462576}
0 commit comments