Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
run: composer install --dev --prefer-dist --no-progress

- name: PHPCSFixer check
run: ./vendor/bin/php-cs-fixer fix --dry-run --verbose
run: ./vendor/bin/php-cs-fixer fix --dry-run --allow-risky=yes --verbose
5 changes: 5 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@
'phpdoc_types_order' => array(
'null_adjustment' => 'always_last',
),
PhpCsFixerCustomFixers\Fixer\PhpUnitAssertArgumentsOrderFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\PhpUnitDedicatedAssertFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\NoUselessStrlenFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\NoUselessParenthesisFixer::name() => true,
);

$config = new PhpCsFixer\Config();
$config->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers());
$config->setRules( $rules );

return $config->setFinder( $finder );
Expand Down
2 changes: 1 addition & 1 deletion classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3413,7 +3413,7 @@ private static function get_time_strings() {
* @return int
*/
public static function get_last_record_num( $r_count, $current_p, $p_size ) {
return ( $r_count < $current_p * $p_size ? $r_count : $current_p * $p_size );
return $r_count < $current_p * $p_size ? $r_count : $current_p * $p_size;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"slevomat/coding-standard": "~8.0",
"friendsofphp/php-cs-fixer": "^3.54",
"rector/rector": "^2.3.4",
"phpstan/phpstan-strict-rules": "^2.0"
"phpstan/phpstan-strict-rules": "^2.0",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.36"
},
"config": {
"allow-plugins": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function process( File $phpcsFile, $stackPtr ) {

// Check if there's a boolean NOT before empty.
$prevToken = $phpcsFile->findPrevious( T_WHITESPACE, $stackPtr - 1, null, true );
$isNegated = ( false !== $prevToken && $tokens[ $prevToken ]['code'] === T_BOOLEAN_NOT );
$isNegated = false !== $prevToken && $tokens[ $prevToken ]['code'] === T_BOOLEAN_NOT;

// Determine the suggested replacement.
if ( $isNegated ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function process( File $phpcsFile, $stackPtr ) {

// Check if there's a boolean NOT before empty.
$prevToken = $phpcsFile->findPrevious( T_WHITESPACE, $stackPtr - 1, null, true );
$isNegated = ( false !== $prevToken && $tokens[ $prevToken ]['code'] === T_BOOLEAN_NOT );
$isNegated = false !== $prevToken && $tokens[ $prevToken ]['code'] === T_BOOLEAN_NOT;

// Determine the suggested replacement.
if ( $isNegated ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ private function findEchoTrueArg( File $phpcsFile, $openParen, $closeParen ) {

// Look for leading comma (this arg comes after another).
$beforeStart = $phpcsFile->findPrevious( T_WHITESPACE, $i - 1, $openParen, true );
$hasLeadingComma = ( false !== $beforeStart && $tokens[ $beforeStart ]['code'] === T_COMMA );
$hasLeadingComma = false !== $beforeStart && $tokens[ $beforeStart ]['code'] === T_COMMA;

// Look for trailing comma.
$afterEnd = $phpcsFile->findNext( T_WHITESPACE, $value + 1, $closeParen, true );
$hasTrailingComma = ( false !== $afterEnd && $tokens[ $afterEnd ]['code'] === T_COMMA );
$hasTrailingComma = false !== $afterEnd && $tokens[ $afterEnd ]['code'] === T_COMMA;

if ( $hasLeadingComma ) {
// Include the leading comma and whitespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private function getFunctionArguments( File $phpcsFile, $openParen ) {
$level--;
}

$nextIsSeparator = ( $code === T_COMMA && 0 === $level );
$nextIsSeparator = $code === T_COMMA && 0 === $level;

if ( false === $argStart ) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function processMissingAnnotations( File $phpcsFile, $stackPtr, $docbloc
}

// Check for missing @return tag.
$missingReturn = ( ! $hasReturnTag && null !== $returnType );
$missingReturn = ! $hasReturnTag && null !== $returnType;

if ( empty( $missingParams ) && ! $missingReturn ) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function process( File $phpcsFile, $stackPtr ) {

// Check if function has a docblock.
$docblock = $this->findDocblock( $phpcsFile, $stackPtr );
$hasDocblock = ( false !== $docblock );
$hasDocblock = false !== $docblock;
$existingParams = array();

if ( $hasDocblock ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function process( File $phpcsFile, $stackPtr ) {
// assertFalse(str_contains()) -> assertStringNotContainsString
// assertNotFalse(strpos()) -> assertStringContainsString
// assertFalse(strpos()) -> assertStringNotContainsString
$wantsContains = ( 'asserttrue' === $methodName || 'assertnotfalse' === $methodName );
$wantsContains = 'asserttrue' === $methodName || 'assertnotfalse' === $methodName;

// Negation flips the result.
if ( $isNegated ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function hasConcatenationAroundKses( File $phpcsFile, $stackPtr, $expres
}

$afterConcat = $phpcsFile->findNext( T_STRING_CONCAT, $closeParen + 1, $semicolon );
return ( false !== $afterConcat );
return false !== $afterConcat;
}

/**
Expand Down Expand Up @@ -259,7 +259,7 @@ private function fixKsesCall( File $phpcsFile, $stackPtr, $echoPtr, $expressionS
$leadingWhitespace = '';
}

$hasLeadingWhitespace = ( '' !== $leadingWhitespace );
$hasLeadingWhitespace = '' !== $leadingWhitespace;
$lineIndent = $indentation;

$newLines = array();
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/base/FrmUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static function import_xml() {
FrmXMLController::add_default_templates();

$form = FrmForm::getOne( 'contact-db12' );
self::assertEquals( $form->form_key, 'contact-db12' );
self::assertEquals( 'contact-db12', $form->form_key );
}

public static function create_files() {
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/database/test_FrmMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test_maybe_create_contact_form() {
// Check for auto contact form.
$form = FrmForm::getOne( 'contact-form' );
$this->assertNotEmpty( $form );
$this->assertSame( $form->form_key, 'contact-form' );
$this->assertSame( 'contact-form', $form->form_key );

// Make sure the form isn't recreated after delete
FrmForm::destroy( 'contact-form' );
Expand Down Expand Up @@ -363,7 +363,7 @@ public function test_migrate_from_12_to_current() {

$this->assertTrue( ! isset( $form->options['notification'] ), 'The migrated notification settings are not cleared from form.' );

$this->assertSame( 1, count( $form_actions ), 'Old form settings are not converted to email action.' );
$this->assertCount( 1, $form_actions, 'Old form settings are not converted to email action.' );

foreach ( $form_actions as $action ) {
$this->assertStringContainsString( 'emailto@test.com', $action->post_content['email_to'] );
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/emails/test_FrmEmailSummaryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function test_get_date_obj() {
);

$this->assertTrue( $date instanceof DateTime );
$this->assertSame( $date->format( 'Y-m-d' ), '2023-08-13' );
$this->assertSame( '2023-08-13', $date->format( 'Y-m-d' ) );

$this->assertFalse(
$this->run_private_method(
Expand All @@ -37,11 +37,11 @@ public function test_get_date_obj() {

public function test_get_date_diff() {
$this->assertSame(
4,
$this->run_private_method(
array( 'FrmEmailSummaryHelper', 'get_date_diff' ),
array( '2023-08-12', '2023-08-16' )
),
4
)
);

$this->assertFalse(
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/entries/test_FrmEntryValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ public function test_get_all_form_ids_and_flatten_meta() {
array( &$test_values )
);

$this->assertEquals( $form_ids, array( 1, 17, 11 ) );
$this->assertEquals( array( 1, 17, 11 ), $form_ids );
$this->assertFalse( isset( $test_values['item_meta'][163] ) );
$this->assertFalse( isset( $test_values['item_meta'][165] ) );
$this->assertEquals( $test_values['item_meta'][162], array( 'Option 2', 'Option 1' ) );
$this->assertEquals( $test_values['item_meta'][118], array( 'John Doe' ) );
$this->assertSame( $test_values['item_meta'][1], 'John Doe' );
$this->assertEquals( array( 'Option 2', 'Option 1' ), $test_values['item_meta'][162] );
$this->assertEquals( array( 'John Doe' ), $test_values['item_meta'][118] );
$this->assertSame( 'John Doe', $test_values['item_meta'][1] );
}

public function test_skip_adding_values_to_akismet() {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/entries/test_FrmTableHTMLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function test_remove_border() {
);

$html = '<div style="border-top:3px solid #eee;"></div>';
$this->assertSame( $table_generator->remove_border( $html ), '<div style=""></div>' );
$this->assertSame( '<div style=""></div>', $table_generator->remove_border( $html ) );
$this->assertEquals( $table_generator->remove_border( $html, 'bottom' ), $html );

$html = '<div style="border-top:1px solid #eee;"></div>';
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/fields/test_FrmField.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function test_getAll() {
$form_id = $this->factory->form->get_id_by_key( $form_key );
$fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id ) );
$this->assertNotEmpty( $fields );
$this->assertEquals( $expected_count, count( $fields ), 'An incorrect number of fields are retrieved with FrmField::getAll.' );
$this->assertCount( $expected_count, $fields, 'An incorrect number of fields are retrieved with FrmField::getAll.' );
}
}

Expand Down Expand Up @@ -69,7 +69,7 @@ public function test_get_all_for_form() {
}

$this->assertNotEmpty( $fields );
$this->assertEquals( $args['count'], count( $fields ), 'An incorrect number of fields are retrieved with FrmField::get_all_for_form for ' . $test . '.' );
$this->assertCount( $args['count'], $fields, 'An incorrect number of fields are retrieved with FrmField::get_all_for_form for ' . $test . '.' );
}
}
}
30 changes: 15 additions & 15 deletions tests/phpunit/fields/test_FrmFieldCombo.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function get_combo_field_with_sub_field_options() {
public function test_register_sub_fields() {
$combo_field = new FrmFieldCombo();

$this->assertEquals( $this->get_private_property( $combo_field, 'sub_fields' ), array() );
$this->assertEquals( array(), $this->get_private_property( $combo_field, 'sub_fields' ) );

$this->run_private_method(
array( $combo_field, 'register_sub_fields' ),
Expand All @@ -96,7 +96,6 @@ public function test_register_sub_fields() {
);

$this->assertEquals(
$this->get_private_property( $combo_field, 'sub_fields' ),
array(
'first' => array(
'name' => 'first',
Expand Down Expand Up @@ -126,7 +125,8 @@ public function test_register_sub_fields() {
),
'atts' => array(),
),
)
),
$this->get_private_property( $combo_field, 'sub_fields' )
);

$this->set_private_property( $combo_field, 'sub_fields', array() );
Expand All @@ -147,7 +147,6 @@ public function test_register_sub_fields() {
);

$this->assertEquals(
$this->get_private_property( $combo_field, 'sub_fields' ),
array(
'second' => array(
'name' => 'second',
Expand All @@ -173,50 +172,51 @@ public function test_register_sub_fields() {
'options' => array(),
'atts' => array(),
),
)
),
$this->get_private_property( $combo_field, 'sub_fields' )
);
}

public function test_extra_field_opts() {
$combo_field = $this->get_combo_field_without_sub_field_options();

$this->assertEquals( $this->run_private_method( array( $combo_field, 'extra_field_opts' ) ), array() );
$this->assertEquals( array(), $this->run_private_method( array( $combo_field, 'extra_field_opts' ) ) );

$combo_field = $this->get_combo_field_with_sub_field_options();

$this->assertEquals(
$this->run_private_method( array( $combo_field, 'extra_field_opts' ) ),
array(
'name_desc' => '',
'email_placeholder' => '',
'dob_desc' => '',
'dob_custom_opt' => '',
)
),
$this->run_private_method( array( $combo_field, 'extra_field_opts' ) )
);
}

public function test_get_default_value() {
$combo_field = $this->get_combo_field_without_sub_field_options();

$this->assertEquals(
$this->run_private_method( array( $combo_field, 'get_default_value' ) ),
array(
'first_child' => '',
'second_child' => '',
'third_child' => '',
'forth_child' => '',
)
),
$this->run_private_method( array( $combo_field, 'get_default_value' ) )
);

$combo_field = $this->get_combo_field_with_sub_field_options();

$this->assertEquals(
$this->run_private_method( array( $combo_field, 'get_default_value' ) ),
array(
'name' => '',
'email' => '',
'dob' => '',
)
),
$this->run_private_method( array( $combo_field, 'get_default_value' ) )
);
}

Expand Down Expand Up @@ -262,7 +262,7 @@ public function test_print_input_atts() {
);
$atts = ob_get_clean();

$this->assertSame( $atts, ' placeholder="First placeholder" class="frm-custom-class" maxlength="10" data-attr="custom-attr" ' );
$this->assertSame( ' placeholder="First placeholder" class="frm-custom-class" maxlength="10" data-attr="custom-attr" ', $atts );

$sub_field = array(
'name' => 'second',
Expand All @@ -283,7 +283,7 @@ public function test_print_input_atts() {
);
$atts = ob_get_clean();

$this->assertSame( $atts, ' class="frm-class1 frm-class2 frm_optional" ' );
$this->assertSame( ' class="frm-class1 frm-class2 frm_optional" ', $atts );

$sub_field = array(
'name' => 'forth',
Expand All @@ -299,7 +299,7 @@ public function test_print_input_atts() {
);
$atts = ob_get_clean();

$this->assertSame( $atts, ' ' );
$this->assertSame( ' ', $atts );
}

public function test_get_export_headings() {
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/fields/test_FrmFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ public function test_get_import_value() {

$checkbox = FrmFieldFactory::get_field_type( 'checkbox', $field );

$this->assertSame( $checkbox->get_import_value( 'a,b' ), 'a,b' );
$this->assertEquals( $checkbox->get_import_value( 'a,c' ), array( 'a', 'c' ) );
$this->assertSame( $checkbox->get_import_value( 'a,b,c' ), 'a,b,c' );
$this->assertSame( 'a,b', $checkbox->get_import_value( 'a,b' ) );
$this->assertEquals( array( 'a', 'c' ), $checkbox->get_import_value( 'a,c' ) );
$this->assertSame( 'a,b,c', $checkbox->get_import_value( 'a,b,c' ) );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/fields/test_FrmSubmitHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function test_copy_submit_field_settings_to_form() {
);

$new_form = FrmSubmitHelper::copy_submit_field_settings_to_form( $form );
$this->assertSame( $new_form->options['submit_value'], 'Submit form' );
$this->assertSame( 'Submit form', $new_form->options['submit_value'] );
}

public function test_only_contains_submit_field() {
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/forms/test_FrmForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function test_duplicate() {
// Check the number of form actions
$original_actions = FrmFormAction::get_action_for_form( $form->id );
$new_actions = FrmFormAction::get_action_for_form( $id );
$this->assertEquals( count( $original_actions ), count( $new_actions ) );
$this->assertCount( count( $original_actions ), $new_actions );
}

protected function _check_if_child_fields_duplicate( $old_child_forms, $new_child_forms ) {
Expand All @@ -45,7 +45,7 @@ protected function _check_if_child_fields_duplicate( $old_child_forms, $new_chil
$new_child_form_fields = FrmField::get_all_for_form( $new_child_form->id );

// Check if there are the same number of child form fields in the duplicated child form
$this->assertEquals( count( $old_child_form_fields ), count( $new_child_form_fields ), 'When a form is duplicated, the fields in the repeating section are not duplicated correctly.' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
$this->assertCount( count( $old_child_form_fields ), $new_child_form_fields, 'When a form is duplicated, the fields in the repeating section are not duplicated correctly.' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/forms/test_FrmFormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function run_message_after_create( $show_form = 0 ) {
);

// Test default action.
$this->assertEquals( $form->options['success_action'], 'message' );
$this->assertEquals( 'message', $form->options['success_action'] );

$this->create_on_submit_action(
$form->id,
Expand Down
Loading
Loading