Skip to content

Commit f66f444

Browse files
committed
Add CS for tests
1 parent 6204e92 commit f66f444

File tree

5 files changed

+70
-72
lines changed

5 files changed

+70
-72
lines changed

.phpcs.xml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<arg name="colors"/>
1515
<arg name="extensions" value="php"/>
1616
<arg name="parallel" value="100"/>
17-
<arg name="cache" value=".phpcs.cache"/>
1817

1918
<rule ref="WordPress">
2019
<!-- PSR4 -->
@@ -42,4 +41,35 @@
4241
<severity>0</severity>
4342
</rule>
4443
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"/>
44+
45+
<!-- Tests -->
46+
<rule ref="Squiz.Commenting.FunctionComment.EmptyThrows">
47+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
48+
<exclude-pattern>\.tests/php/*</exclude-pattern>
49+
</rule>
50+
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
51+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
52+
<exclude-pattern>\.tests/php/*</exclude-pattern>
53+
</rule>
54+
<rule ref="WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid">
55+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
56+
<exclude-pattern>\.tests/php/*</exclude-pattern>
57+
</rule>
58+
<rule ref="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase">
59+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
60+
<exclude-pattern>\.tests/php/*</exclude-pattern>
61+
</rule>
62+
<rule ref="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase">
63+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
64+
<exclude-pattern>\.tests/php/*</exclude-pattern>
65+
</rule>
66+
<rule ref="WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase">
67+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
68+
<exclude-pattern>\.tests/php/*</exclude-pattern>
69+
</rule>
70+
<rule ref="Squiz.NamingConventions">
71+
<exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"/>
72+
<include-pattern>\.codeception/_support/*</include-pattern>
73+
<include-pattern>\.tests/php/*</include-pattern>
74+
</rule>
4575
</ruleset>

.tests/php/acceptance/SettingsCest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,20 @@
1111

1212
/**
1313
* Class SettingsCest.
14-
*
15-
* phpcs:ignoreFile WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
16-
*
17-
* @since {VERSION}
1814
*/
1915
class SettingsCest {
2016

2117
/**
2218
* Check a Settings Page
2319
*
24-
* @since {VERSION}
25-
*
26-
* @param \AcceptanceTester $I Actor.
20+
* @param AcceptanceTester $i Actor.
2721
*
28-
* @throws \Exception Something when wrong.
22+
* @throws Exception Something when wrong.
2923
*/
30-
public function visitSettingsPage( AcceptanceTester $I ) {
31-
$I->loginAsAdmin();
32-
$I->amOnAdminPage( '/admin.php?page=plugin-name' );
33-
$I->see( 'Plugin Name Settings' );
24+
public function visitSettingsPage( AcceptanceTester $i ): void {
25+
$i->loginAsAdmin();
26+
$i->amOnAdminPage( '/admin.php?page=plugin-name' );
27+
$i->see( 'Plugin Name Settings' );
3428
}
3529

3630
}

.tests/php/unit/Admin/SettingsPageTest.php

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace PluginNameUnitTests\Admin;
1313

14+
use Brain\Monkey\Expectation\Exception\ExpectationArgsRequired;
1415
use PluginName\Plugin;
1516
use PluginNameTests\TestCase;
1617
use PluginName\Admin\SettingsPage;
@@ -20,19 +21,13 @@
2021

2122
/**
2223
* Class SettingsPageTest
23-
*
24-
* @since {VERSION}
25-
*
26-
* @package PluginNameUnitTests\Admin
2724
*/
2825
class SettingsPageTest extends TestCase {
2926

3027
/**
3128
* Test for adding hooks
32-
*
33-
* @since {VERSION}
3429
*/
35-
public function test_hooks() {
30+
public function testHooks(): void {
3631
$settings = new SettingsPage();
3732

3833
$settings->hooks();
@@ -44,10 +39,8 @@ public function test_hooks() {
4439

4540
/**
4641
* Test don't enqueue styles
47-
*
48-
* @since {VERSION}
4942
*/
50-
public function test_DONT_enqueue_styles() {
43+
public function testDontEnqueueStyles(): void {
5144
$settings = new SettingsPage();
5245

5346
$settings->enqueue_styles( 'hook-suffix' );
@@ -56,11 +49,9 @@ public function test_DONT_enqueue_styles() {
5649
/**
5750
* Test enqueue styles
5851
*
59-
* @since {VERSION}
60-
*
61-
* @throws \Brain\Monkey\Expectation\Exception\ExpectationArgsRequired Invalid arguments.
52+
* @throws ExpectationArgsRequired Invalid arguments.
6253
*/
63-
public function test_enqueue_styles() {
54+
public function testEnqueueStyles(): void {
6455
$settings = new SettingsPage();
6556
expect( 'wp_enqueue_style' )
6657
->once()
@@ -77,10 +68,8 @@ public function test_enqueue_styles() {
7768

7869
/**
7970
* Test don't enqueue scripts
80-
*
81-
* @since {VERSION}
8271
*/
83-
public function test_DONT_enqueue_scripts() {
72+
public function testDontEnqueueScripts(): void {
8473
$settings = new SettingsPage();
8574

8675
$settings->enqueue_scripts( 'hook-suffix' );
@@ -89,11 +78,9 @@ public function test_DONT_enqueue_scripts() {
8978
/**
9079
* Test enqueue scripts
9180
*
92-
* @since {VERSION}
93-
*
94-
* @throws \Brain\Monkey\Expectation\Exception\ExpectationArgsRequired Invalid arguments.
81+
* @throws ExpectationArgsRequired Invalid arguments.
9582
*/
96-
public function test_enqueue_scripts() {
83+
public function testEnqueueScripts(): void {
9784
$settings = new SettingsPage();
9885
expect( 'wp_enqueue_script' )
9986
->once()
@@ -111,11 +98,9 @@ public function test_enqueue_scripts() {
11198
/**
11299
* Test register menu
113100
*
114-
* @since {VERSION}
115-
*
116-
* @throws \Brain\Monkey\Expectation\Exception\ExpectationArgsRequired Invalid arguments.
101+
* @throws ExpectationArgsRequired
117102
*/
118-
public function test_add_menu() {
103+
public function testAddMenu(): void {
119104
$settings = new SettingsPage();
120105
when( 'esc_html__' )->returnArg();
121106
expect( 'add_menu_page' )
@@ -137,17 +122,15 @@ public function test_add_menu() {
137122
/**
138123
* Test view for settings page
139124
*
140-
* @since {VERSION}
141-
*
142-
* @throws \Brain\Monkey\Expectation\Exception\ExpectationArgsRequired Invalid arguments.
125+
* @throws ExpectationArgsRequired
143126
*/
144-
public function test_page_option() {
145-
$page_title = 'Plugin Name Settings';
146-
$settings = new SettingsPage();
127+
public function testPageOption(): void {
128+
$pageTitle = 'Plugin Name Settings';
129+
$settings = new SettingsPage();
147130
expect( 'get_admin_page_title' )
148131
->once()
149132
->withNoArgs()
150-
->andReturn( $page_title );
133+
->andReturn( $pageTitle );
151134
when( 'esc_html' )->returnArg();
152135

153136
$settings->page_options();

.tests/php/unit/Front/FrontTest.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace PluginNameUnitTests\Front;
1313

14+
use Brain\Monkey\Expectation\Exception\ExpectationArgsRequired;
1415
use PluginName\Plugin;
1516
use PluginName\Front\Front;
1617
use PluginNameTests\TestCase;
@@ -19,19 +20,13 @@
1920

2021
/**
2122
* Class FrontTest
22-
*
23-
* @since {VERSION}
24-
*
25-
* @package PluginNameUnitTests\Front
2623
*/
2724
class FrontTest extends TestCase {
2825

2926
/**
3027
* Test for adding hooks
31-
*
32-
* @since {VERSION}
3328
*/
34-
public function test_hooks() {
29+
public function testHooks(): void {
3530
$front = new Front();
3631

3732
$front->hooks();
@@ -43,11 +38,9 @@ public function test_hooks() {
4338
/**
4439
* Test enqueue styles
4540
*
46-
* @since {VERSION}
47-
*
48-
* @throws \Brain\Monkey\Expectation\Exception\ExpectationArgsRequired Invalid arguments.
41+
* @throws ExpectationArgsRequired Invalid arguments.
4942
*/
50-
public function test_enqueue_styles() {
43+
public function testEnqueueStyles(): void {
5144
$front = new Front();
5245
expect( 'wp_enqueue_style' )
5346
->once()
@@ -65,11 +58,9 @@ public function test_enqueue_styles() {
6558
/**
6659
* Test enqueue scripts
6760
*
68-
* @since {VERSION}
69-
*
70-
* @throws \Brain\Monkey\Expectation\Exception\ExpectationArgsRequired Invalid arguments.
61+
* @throws ExpectationArgsRequired Invalid arguments.
7162
*/
72-
public function test_enqueue_scripts() {
63+
public function testEnqueueScripts(): void {
7364
$front = new Front();
7465
expect( 'wp_enqueue_script' )
7566
->once()

.tests/php/unit/PluginTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,37 @@
1111

1212
namespace PluginNameUnitTests;
1313

14+
use Brain\Monkey\Expectation\Exception\ExpectationArgsRequired;
15+
use Exception;
1416
use PluginName\Plugin;
1517
use PluginName\Front\Front;
1618
use PluginNameTests\TestCase;
1719
use PluginName\Admin\SettingsPage;
1820

1921
use function Brain\Monkey\Functions\expect;
22+
use PluginName\Vendor\Auryn\Injector;
2023

2124
/**
2225
* Class FrontTest
23-
*
24-
* @since {VERSION}
25-
*
26-
* @package PluginNameUnitTests\Front
2726
*/
2827
class PluginTest extends TestCase {
2928

3029
/**
3130
* Test for adding hooks
3231
*
33-
* @since {VERSION}
32+
* @throws ExpectationArgsRequired
3433
*/
35-
public function test_run_admin() {
34+
public function testRunAdmin(): void {
3635
expect( 'is_admin' )
3736
->once()
3837
->withNoArgs()
3938
->andReturn( true );
40-
$settings = \Mockery::mock( '\PluginName\Admin\SettingsPage' );
39+
$settings = \Mockery::mock( SettingsPage::class );
4140
$settings
4241
->shouldReceive( 'hooks' )
4342
->once()
4443
->withNoArgs();
45-
$injector = \Mockery::mock( 'PluginName\Vendor\Auryn\Injector' );
44+
$injector = \Mockery::mock( Injector::class );
4645
$injector
4746
->shouldReceive( 'make' )
4847
->once()
@@ -56,19 +55,20 @@ public function test_run_admin() {
5655
/**
5756
* Test for adding hooks
5857
*
59-
* @since {VERSION}
58+
* @throws ExpectationArgsRequired
59+
* @throws Exception
6060
*/
61-
public function test_run_front() {
61+
public function testRunFront(): void {
6262
expect( 'is_admin' )
6363
->once()
6464
->withNoArgs()
6565
->andReturn( false );
66-
$front = \Mockery::mock( '\PluginName\Front\Front' );
66+
$front = \Mockery::mock( Front::class );
6767
$front
6868
->shouldReceive( 'hooks' )
6969
->once()
7070
->withNoArgs();
71-
$injector = \Mockery::mock( 'PluginName\Vendor\Auryn\Injector' );
71+
$injector = \Mockery::mock( Injector::class );
7272
$injector
7373
->shouldReceive( 'make' )
7474
->once()

0 commit comments

Comments
 (0)