Skip to content

Commit 06c4658

Browse files
authored
Merge pull request #186 from pattonwebz/feature/add-custom-ruleset-wp_cli_cs
2 parents 0459270 + bc921ce commit 06c4658

16 files changed

+356
-325
lines changed

.distignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
.travis.yml
77
behat.yml
88
circle.yml
9+
phpcs.xml.dist
10+
phpunit.xml.dist
911
bin/
1012
features/
1113
utils/

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ vendor/
88
*.txt
99
*.log
1010
composer.lock
11+
phpunit.xml
12+
phpcs.xml
13+
.phpcs.xml

bin/install-package-tests.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

bin/test.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

circle.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ jobs:
2828
- run: |
2929
dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
3030
- run: |
31-
composer require wp-cli/wp-cli:dev-master
31+
composer validate
3232
composer install
3333
composer prepare-tests
3434
- run: |
3535
echo 'export PATH=$HOME/wp-cli/package-tests/vendor/bin:$PATH' >> $BASH_ENV
3636
source $BASH_ENV
3737
- run: |
38-
composer validate
3938
WP_VERSION=latest composer test
4039
rm -rf '/tmp/wp-cli-test core-download-cache'
4140
WP_VERSION=trunk composer test

features/scaffold-package-readme.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ Feature: Scaffold a README.md file for an existing package
230230
*This README.md is generated dynamically from the project's codebase
231231
"""
232232

233+
@broken
233234
Scenario: Error when commands are specified but not present
234235
Given an empty directory
235236
And a foo/composer.json file:

features/scaffold-package-tests.feature

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ Feature: Scaffold the test suite for an existing package
5656
When I run `wp scaffold package-tests community-command`
5757
Then STDOUT should not be empty
5858
And the community-command/.travis.yml file should exist
59-
"""
60-
require-wp
61-
"""
6259
And the community-command/features directory should contain:
6360
"""
6461
load-wp-cli.feature
@@ -124,9 +121,10 @@ Feature: Scaffold the test suite for an existing package
124121
"""
125122
- MY_APPEND_ENV="my-append-env"
126123
"""
127-
And a community-command/travis-matrix-append.yml file:
124+
And a community-command/travis-jobs-append.yml file:
128125
"""
129-
- php: 99.97
126+
- stage: test
127+
php: 99.97
130128
env: WP_VERSION=9997.9997
131129
"""
132130
And a community-command/travis-before_install-append.yml file:
@@ -138,10 +136,6 @@ Feature: Scaffold the test suite for an existing package
138136
"""
139137
- bash bin/my-append-install.sh
140138
"""
141-
And a community-command/travis-before_script-append.yml file:
142-
"""
143-
- bash bin/my-append-before_script.sh
144-
"""
145139
And a community-command/travis-script-append.yml file:
146140
"""
147141
- bash bin/my-append-script.sh
@@ -176,15 +170,16 @@ Feature: Scaffold the test suite for an existing package
176170
"""
177171
- MY_APPEND_ENV="my-append-env"
178172
179-
matrix:
173+
before_install:
180174
"""
181175
And the community-command/.travis.yml file should contain:
182176
"""
183-
- php: 7.2
177+
php: 7.4
184178
"""
185179
And the community-command/.travis.yml file should contain:
186180
"""
187-
- php: 99.97
181+
- stage: test
182+
php: 99.97
188183
env: WP_VERSION=9997.9997
189184
190185
before_install:
@@ -202,27 +197,21 @@ Feature: Scaffold the test suite for an existing package
202197
"""
203198
And the community-command/.travis.yml file should contain:
204199
"""
205-
- bash bin/install-package-tests.sh
200+
- composer prepare-tests
206201
"""
207202
And the community-command/.travis.yml file should contain:
208203
"""
209204
- bash bin/my-append-install.sh
210205
211-
before_script:
206+
script:
212207
"""
213208
And the community-command/.travis.yml file should contain:
214209
"""
215210
- composer validate
216211
"""
217212
And the community-command/.travis.yml file should contain:
218213
"""
219-
- bash bin/my-append-before_script.sh
220-
221-
script:
222-
"""
223-
And the community-command/.travis.yml file should contain:
224-
"""
225-
- bash bin/test.sh
214+
- composer behat || composer behat-rerun
226215
- bash bin/my-append-script.sh
227216
"""
228217
And the community-command/.travis.yml file should contain:

features/scaffold-package.feature

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Feature: Scaffold WP-CLI commands
3737
"wp-cli/wp-cli": "^2.5"
3838
},
3939
"""
40-
And the {PACKAGE_PATH}/local/wp-cli/foo/command.php file should exist
40+
And the {PACKAGE_PATH}/local/wp-cli/foo/hello-world-command.php file should exist
4141
And the {PACKAGE_PATH}/local/wp-cli/foo/CONTRIBUTING.md file should exist
4242
And the {PACKAGE_PATH}/local/wp-cli/foo/CONTRIBUTING.md file should contain:
4343
"""
@@ -48,17 +48,24 @@ Feature: Scaffold WP-CLI commands
4848
And the {PACKAGE_PATH}/local/wp-cli/foo/.github/PULL_REQUEST_TEMPLATE file should exist
4949
And the {PACKAGE_PATH}/local/wp-cli/foo/.github/ISSUE_TEMPLATE file should exist
5050

51-
When I run `wp --require={PACKAGE_PATH}/local/wp-cli/foo/command.php hello-world`
51+
When I run `wp hello-world`
52+
Then STDOUT should be:
53+
"""
54+
Success: Hello World!
55+
"""
56+
57+
When I run `composer -q -n --working-dir={PACKAGE_PATH}/local/wp-cli/foo/ install`
58+
And I run `wp --require={PACKAGE_PATH}/local/wp-cli/foo/hello-world-command.php hello-world`
5259
Then STDOUT should be:
5360
"""
54-
Success: Hello world.
61+
Success: Hello World!
5562
"""
5663

5764
When I run `cat {PACKAGE_PATH}/local/wp-cli/foo/wp-cli.yml`
5865
Then STDOUT should contain:
5966
"""
6067
require:
61-
- command.php
68+
- hello-world-command.php
6269
"""
6370

6471
When I run `cat {PACKAGE_PATH}/local/wp-cli/foo/.gitignore`
@@ -91,7 +98,7 @@ Feature: Scaffold WP-CLI commands
9198
When I run `wp hello-world`
9299
Then STDOUT should be:
93100
"""
94-
Success: Hello world.
101+
Success: Hello World!
95102
"""
96103

97104
When I run `wp package uninstall wp-cli/without-require`
@@ -121,14 +128,15 @@ Feature: Scaffold WP-CLI commands
121128
And the custom-directory/.gitignore file should exist
122129
And the custom-directory/.editorconfig file should exist
123130
And the custom-directory/composer.json file should exist
124-
And the custom-directory/command.php file should exist
131+
And the custom-directory/hello-world-command.php file should exist
125132
And the custom-directory/wp-cli.yml file should exist
126133
And the custom-directory/.travis.yml file should not exist
127134

128-
When I run `wp --require=custom-directory/command.php hello-world`
135+
When I run `composer -q -n --working-dir=custom-directory/ install`
136+
And I run `wp --require=custom-directory/hello-world-command.php hello-world`
129137
Then STDOUT should be:
130138
"""
131-
Success: Hello world.
139+
Success: Hello World!
132140
"""
133141
When I run `wp package uninstall wp-cli/custom-directory`
134142
Then STDOUT should contain:
@@ -148,6 +156,7 @@ Feature: Scaffold WP-CLI commands
148156
s
149157
s
150158
s
159+
s
151160
"""
152161

153162
When I run `wp scaffold package wp-cli/same-package --skip-tests --skip-github`
@@ -187,14 +196,15 @@ Feature: Scaffold WP-CLI commands
187196
And the {PACKAGE_PATH}/local/wp-cli/with-tests/.gitignore file should exist
188197
And the {PACKAGE_PATH}/local/wp-cli/with-tests/.editorconfig file should exist
189198
And the {PACKAGE_PATH}/local/wp-cli/with-tests/composer.json file should exist
190-
And the {PACKAGE_PATH}/local/wp-cli/with-tests/command.php file should exist
199+
And the {PACKAGE_PATH}/local/wp-cli/with-tests/hello-world-command.php file should exist
191200
And the {PACKAGE_PATH}/local/wp-cli/with-tests/wp-cli.yml file should exist
192201
And the {PACKAGE_PATH}/local/wp-cli/with-tests/.travis.yml file should exist
193202
194-
When I run `wp --require={PACKAGE_PATH}/local/wp-cli/with-tests/command.php hello-world`
203+
When I run `composer -q -n --working-dir={PACKAGE_PATH}/local/wp-cli/with-tests/ install`
204+
And I run `wp --require={PACKAGE_PATH}/local/wp-cli/with-tests/hello-world-command.php hello-world`
195205
Then STDOUT should be:
196206
"""
197-
Success: Hello world.
207+
Success: Hello World!
198208
"""
199209
When I run `wp package uninstall wp-cli/with-tests`
200210
Then STDOUT should contain:

phpcs.xml.dist

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WP-CLI-scaffold-package">
3+
<description>Custom ruleset for WP-CLI scaffold-package-command</description>
4+
5+
<!--
6+
#############################################################################
7+
COMMAND LINE ARGUMENTS
8+
For help understanding this file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
9+
For help using PHPCS: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage
10+
#############################################################################
11+
-->
12+
13+
<!-- What to scan. -->
14+
<file>.</file>
15+
16+
<!-- Show progress. -->
17+
<arg value="p"/>
18+
19+
<!-- Strip the filepaths down to the relevant bit. -->
20+
<arg name="basepath" value="./"/>
21+
22+
<!-- Check up to 8 files simultaneously. -->
23+
<arg name="parallel" value="8"/>
24+
25+
<!--
26+
#############################################################################
27+
USE THE WP_CLI_CS RULESET
28+
#############################################################################
29+
-->
30+
31+
<rule ref="WP_CLI_CS"/>-
32+
33+
<!--
34+
#############################################################################
35+
PROJECT SPECIFIC CONFIGURATION FOR SNIFFS
36+
#############################################################################
37+
-->
38+
39+
<!-- For help understanding the `testVersion` configuration setting:
40+
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
41+
<config name="testVersion" value="5.6-"/>
42+
43+
<!-- Verify that everything in the global namespace is either namespaced or prefixed.
44+
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace -->
45+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
46+
<properties>
47+
<property name="prefixes" type="array">
48+
<element value="WP_CLI"/><!-- Namespaces. -->
49+
<element value="wpcli_scaffold_package"/><!-- Global variables and such. -->
50+
</property>
51+
</properties>
52+
</rule>
53+
54+
</ruleset>

scaffold-package-command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
return;
77
}
88

9-
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
10-
if ( file_exists( $autoload ) ) {
11-
require_once $autoload;
9+
$wpcli_scaffold_package_autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
10+
if ( file_exists( $wpcli_scaffold_package_autoload ) ) {
11+
require_once $wpcli_scaffold_package_autoload;
1212
}
1313

1414
WP_CLI::add_command( 'scaffold package', [ ScaffoldPackageCommand::class, 'package' ] );

0 commit comments

Comments
 (0)