|
| 1 | +Feature: Lint scaffolded code |
| 2 | + |
| 3 | + Background: |
| 4 | + Given a WP install |
| 5 | + And I run `wp plugin path` |
| 6 | + And save STDOUT as {PLUGIN_DIR} |
| 7 | + |
| 8 | + # Create a helper plugin to install phpcs once for all scenarios |
| 9 | + When I run `wp scaffold plugin phpcs-helper --skip-tests` |
| 10 | + Then the return code should be 0 |
| 11 | + |
| 12 | + # Install coding standards |
| 13 | + When I run `composer config --working-dir={PLUGIN_DIR}/phpcs-helper allow-plugins.dealerdirect/phpcodesniffer-composer-installer true` |
| 14 | + Then the return code should be 0 |
| 15 | + |
| 16 | + When I run `composer require --dev --working-dir={PLUGIN_DIR}/phpcs-helper dealerdirect/phpcodesniffer-composer-installer wp-coding-standards/wpcs --no-interaction --quiet` |
| 17 | + Then the return code should be 0 |
| 18 | + |
| 19 | + Scenario: Scaffold plugin and lint it |
| 20 | + When I run `wp scaffold plugin test-plugin` |
| 21 | + Then STDOUT should not be empty |
| 22 | + And the {PLUGIN_DIR}/test-plugin/test-plugin.php file should exist |
| 23 | + And the {PLUGIN_DIR}/test-plugin/.phpcs.xml.dist file should exist |
| 24 | + |
| 25 | + When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {PLUGIN_DIR}/test-plugin/test-plugin.php` |
| 26 | + Then the return code should be 0 |
| 27 | + |
| 28 | + Scenario: Scaffold post-type and lint it |
| 29 | + When I run `wp theme install twentytwentyone --force --activate` |
| 30 | + And I run `wp eval 'echo STYLESHEETPATH;'` |
| 31 | + And save STDOUT as {STYLESHEETPATH} |
| 32 | + |
| 33 | + And I run `wp scaffold post-type movie --theme` |
| 34 | + Then STDOUT should not be empty |
| 35 | + And the {STYLESHEETPATH}/post-types/movie.php file should exist |
| 36 | + |
| 37 | + When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {STYLESHEETPATH}/post-types/movie.php` |
| 38 | + Then the return code should be 0 |
| 39 | + |
| 40 | + Scenario: Scaffold taxonomy and lint it |
| 41 | + When I run `wp theme install twentytwentyone --force --activate` |
| 42 | + And I run `wp eval 'echo STYLESHEETPATH;'` |
| 43 | + And save STDOUT as {STYLESHEETPATH} |
| 44 | + |
| 45 | + And I run `wp scaffold taxonomy genre --theme` |
| 46 | + Then STDOUT should not be empty |
| 47 | + And the {STYLESHEETPATH}/taxonomies/genre.php file should exist |
| 48 | + |
| 49 | + When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {STYLESHEETPATH}/taxonomies/genre.php` |
| 50 | + Then the return code should be 0 |
| 51 | + |
| 52 | + Scenario: Scaffold plugin tests and lint them |
| 53 | + When I run `wp scaffold plugin test-plugin` |
| 54 | + Then STDOUT should not be empty |
| 55 | + And the {PLUGIN_DIR}/test-plugin/tests directory should exist |
| 56 | + And the {PLUGIN_DIR}/test-plugin/tests/bootstrap.php file should exist |
| 57 | + And the {PLUGIN_DIR}/test-plugin/tests/test-sample.php file should exist |
| 58 | + |
| 59 | + # Run phpcs on the test files |
| 60 | + When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {PLUGIN_DIR}/test-plugin/tests/bootstrap.php {PLUGIN_DIR}/test-plugin/tests/test-sample.php` |
| 61 | + Then the return code should be 0 |
| 62 | + |
| 63 | + Scenario: Scaffold child theme and lint it |
| 64 | + When I run `wp theme install twentytwentyone --force --activate` |
| 65 | + And I run `wp theme path` |
| 66 | + And save STDOUT as {THEME_DIR} |
| 67 | + |
| 68 | + And I run `wp scaffold child-theme test-child --parent_theme=twentytwentyone` |
| 69 | + Then STDOUT should not be empty |
| 70 | + And the {THEME_DIR}/test-child/functions.php file should exist |
| 71 | + |
| 72 | + When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {THEME_DIR}/test-child/functions.php` |
| 73 | + Then the return code should be 0 |
| 74 | + |
| 75 | + Scenario: Scaffold block and lint it |
| 76 | + When I run `wp scaffold plugin movies` |
| 77 | + And I run `wp plugin path movies --dir` |
| 78 | + And save STDOUT as {MOVIES_DIR} |
| 79 | + |
| 80 | + And I run `wp scaffold block the-green-mile --plugin=movies` |
| 81 | + Then STDOUT should not be empty |
| 82 | + And the {MOVIES_DIR}/blocks/the-green-mile.php file should exist |
| 83 | + |
| 84 | + When I run `{PLUGIN_DIR}/phpcs-helper/vendor/bin/phpcs --standard=WordPress {MOVIES_DIR}/blocks/the-green-mile.php` |
| 85 | + Then the return code should be 0 |
0 commit comments