Skip to content

Commit

Permalink
Upgrade integration tests to PHP 7.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 21, 2024
1 parent 5d682e4 commit 5aece80
Show file tree
Hide file tree
Showing 63 changed files with 441 additions and 465 deletions.
42 changes: 21 additions & 21 deletions .tests/php/integration/AAAMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AAAMainTest extends HCaptchaWPTestCase {
*
* @throws ReflectionException ReflectionException.
*/
public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound
public function tearDown(): void {
$hcaptcha = hcaptcha();

$loaded_classes = $this->get_protected_property( $hcaptcha, 'loaded_classes' );
Expand Down Expand Up @@ -105,7 +105,7 @@ public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDecl
*
* @return void
*/
public function test_init() {
public function test_init(): void {
$hcaptcha = hcaptcha();

// The plugin was loaded by codeception.
Expand Down Expand Up @@ -133,7 +133,7 @@ public function test_init() {
* @noinspection PhpUnitTestsInspection
* @noinspection UnusedFunctionResultInspection
*/
public function test_init_and_init_hooks( bool $logged_in, string $hcaptcha_off_when_logged_in, $whitelisted, bool $hcaptcha_active ) {
public function test_init_and_init_hooks( bool $logged_in, string $hcaptcha_off_when_logged_in, $whitelisted, bool $hcaptcha_active ): void {
global $current_user;

$hcaptcha = hcaptcha();
Expand Down Expand Up @@ -256,7 +256,7 @@ public function test_init_and_init_hooks_on_elementor_pro_edit_page(
array $get,
array $post,
bool $hcaptcha_active
) {
): void {
global $current_user;

add_filter(
Expand Down Expand Up @@ -368,7 +368,7 @@ public function dp_test_init_and_init_hooks_on_elementor_pro_edit_page(): array
*
* @throws ReflectionException ReflectionException.
*/
public function test_init_and_init_hooks_on_xml_rpc_request() {
public function test_init_and_init_hooks_on_xml_rpc_request(): void {
$subject = Mockery::mock( Main::class )->makePartial();
$subject->shouldAllowMockingProtectedMethods()->shouldReceive( 'is_xml_rpc' )->andReturn( true );

Expand All @@ -389,7 +389,7 @@ public function test_init_and_init_hooks_on_xml_rpc_request() {
/**
* Test prefetch_hcaptcha_dns().
*/
public function test_prefetch_hcaptcha_dns() {
public function test_prefetch_hcaptcha_dns(): void {
$urls = [
'//s.w.org',
];
Expand All @@ -409,7 +409,7 @@ public function test_prefetch_hcaptcha_dns() {
*
* @return void
*/
public function test_csp_headers() {
public function test_csp_headers(): void {
$headers = [
'some_header' => 'some header content',
];
Expand Down Expand Up @@ -457,7 +457,7 @@ static function ( $add, $h ) use ( &$headers ) {
* @dataProvider dp_test_print_inline_styles
* @noinspection CssUnusedSymbol
*/
public function test_print_inline_styles( $custom_themes ) {
public function test_print_inline_styles( $custom_themes ): void {
$license = 'pro';
$bg = '#f0f0f0';
$config_params = 'on' === $custom_themes
Expand Down Expand Up @@ -614,7 +614,7 @@ public function dp_test_print_inline_styles(): array {
* Test login_head().
*
* @noinspection CssUnusedSymbol*/
public function test_login_head() {
public function test_login_head(): void {
FunctionMocker::replace(
'defined',
static function ( $constant_name ) {
Expand Down Expand Up @@ -664,7 +664,7 @@ static function ( $name ) {
* @return void
* @dataProvider dp_test_get_api_url
*/
public function test_get_api_url( string $api_host, string $expected ) {
public function test_get_api_url( string $api_host, string $expected ): void {
update_option(
'hcaptcha_settings',
[
Expand Down Expand Up @@ -699,7 +699,7 @@ public function dp_test_get_api_url(): array {
*
* @return void
*/
public function test_get_api_src() {
public function test_get_api_src(): void {
update_option(
'hcaptcha_settings',
[
Expand Down Expand Up @@ -733,7 +733,7 @@ public function test_get_api_src() {
* @return void
* @dataProvider dp_test_get_verify_url
*/
public function test_get_verify_url( string $backend, string $expected ) {
public function test_get_verify_url( string $backend, string $expected ): void {
update_option(
'hcaptcha_settings',
[
Expand Down Expand Up @@ -772,7 +772,7 @@ public function dp_test_get_verify_url(): array {
* @return void
* @dataProvider dp_test_get_check_site_config_url
*/
public function test_get_check_site_config_url( string $backend, string $expected ) {
public function test_get_check_site_config_url( string $backend, string $expected ): void {
update_option(
'hcaptcha_settings',
[
Expand Down Expand Up @@ -814,7 +814,7 @@ public function dp_test_get_check_site_config_url(): array {
* @throws ReflectionException ReflectionException.
* @noinspection BadExpressionStatementJS
*/
public function test_print_footer_scripts( $compat, $language, $custom_themes, string $expected_script_src ) {
public function test_print_footer_scripts( $compat, $language, $custom_themes, string $expected_script_src ): void {
FunctionMocker::replace(
'defined',
static function ( $constant_name ) {
Expand Down Expand Up @@ -984,7 +984,7 @@ function delayedLoad() {
*
* @return void
*/
public function test_print_footer_script_when_blocked_by_filter() {
public function test_print_footer_script_when_blocked_by_filter(): void {
add_filter( 'hcap_activate', '__return_true' );
add_filter( 'hcap_print_hcaptcha_scripts', '__return_false' );

Expand Down Expand Up @@ -1058,7 +1058,7 @@ public function dp_test_print_footer_scripts(): array {
* @dataProvider dp_test_whitelist_ip
* @return void
*/
public function test_whitelist_ip( $whitelisted_ips, $client_ip, bool $expected ) {
public function test_whitelist_ip( $whitelisted_ips, $client_ip, bool $expected ): void {
update_option( 'hcaptcha_settings', [ 'whitelisted_ips' => $whitelisted_ips ] );

$subject = new Main();
Expand Down Expand Up @@ -1087,7 +1087,7 @@ public function dp_test_whitelist_ip(): array {
/**
* Test print_footer_scripts() when form NOT shown.
*/
public function test_print_footer_scripts_when_form_NOT_shown() {
public function test_print_footer_scripts_when_form_NOT_shown(): void {
self::assertFalse( wp_script_is( 'hcaptcha' ) );

$site_key = 'some key';
Expand Down Expand Up @@ -1116,8 +1116,8 @@ public function test_print_footer_scripts_when_form_NOT_shown() {
* @dataProvider dp_test_load_modules
* @throws ReflectionException ReflectionException.
*/
public function test_load_modules( array $module ) {
list( $option_name, $option_value ) = $module[0];
public function test_load_modules( array $module ): void {
[ $option_name, $option_value ] = $module[0];

update_option(
'hcaptcha_settings',
Expand Down Expand Up @@ -1668,7 +1668,7 @@ static function ( &$value ) {
/**
* Test load_textdomain().
*/
public function test_load_textdomain() {
public function test_load_textdomain(): void {
$subject = new Main();
$subject->init_hooks();

Expand Down Expand Up @@ -1721,7 +1721,7 @@ private function normalize_path( $path ) {
*
* @param array $component Component.
*/
public function check_component_loaded( array $component ) {
public function check_component_loaded( array $component ): void {
$intersect = array_intersect( $component, $this->normalize_path( get_included_files() ) );
$included = array_intersect( $component, self::$included_components );
self::assertSame( $included, $intersect );
Expand Down
20 changes: 10 additions & 10 deletions .tests/php/integration/ACFE/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FormTest extends HCaptchaWPTestCase {
/**
* Tear down the test.
*/
public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound
public function tearDown(): void {
unset( $_POST['_acf_post_id'], $_POST[ HCaptcha::HCAPTCHA_WIDGET_ID ] );

wp_dequeue_script( 'hcaptcha' );
Expand All @@ -44,7 +44,7 @@ public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDecl
/**
* Test init_hooks().
*/
public function test_init_hooks() {
public function test_init_hooks(): void {
$subject = new Form();

self::assertSame( 10, has_action( 'acfe/form/render/before_fields', [ $subject, 'before_fields' ] ) );
Expand All @@ -61,7 +61,7 @@ public function test_init_hooks() {
* @return void
* @throws ReflectionException ReflectionException.
*/
public function test_before_fields() {
public function test_before_fields(): void {
$id = 5;

$subject = new Form();
Expand All @@ -82,7 +82,7 @@ public function test_before_fields() {
* @dataProvider dp_test_remove_recaptcha_render
* @noinspection UnusedFunctionResultInspection
*/
public function test_remove_recaptcha_render( array $field, $expected ) {
public function test_remove_recaptcha_render( array $field, $expected ): void {
$recaptcha = Mockery::mock( 'acfe_field_recaptcha' );
$recaptcha->shouldReceive( 'render_field' );

Expand Down Expand Up @@ -126,7 +126,7 @@ public function dp_test_remove_recaptcha_render(): array {
* @return void
* @dataProvider dp_test_add_hcaptcha
*/
public function test_add_hcaptcha( array $field, string $expected ) {
public function test_add_hcaptcha( array $field, string $expected ): void {
$subject = new Form();

hcaptcha()->init_hooks();
Expand Down Expand Up @@ -176,7 +176,7 @@ public function dp_test_add_hcaptcha(): array {
* @return void
* @noinspection UnusedFunctionResultInspection
*/
public function test_remove_recaptcha_verify() {
public function test_remove_recaptcha_verify(): void {
$value = 'some value';
$field = [ 'type' => 'some' ];
$input = 'some_input_name';
Expand Down Expand Up @@ -207,7 +207,7 @@ public function test_remove_recaptcha_verify() {
* @dataProvider dp_test_verify
* @throws ReflectionException ReflectionException.
*/
public function test_verify( bool $result, bool $expected ) {
public function test_verify( bool $result, bool $expected ): void {
$valid = ! $expected;
$value = 'some hcaptcha response';
$input = 'some_input_name';
Expand Down Expand Up @@ -242,7 +242,7 @@ public function dp_test_verify(): array {
*
* @return void
*/
public function test_verify_when_NOT_required() {
public function test_verify_when_NOT_required(): void {
$value = 'some hcaptcha response';
$input = 'some_input_name';
$field = [ 'required' => false ];
Expand All @@ -259,7 +259,7 @@ public function test_verify_when_NOT_required() {
* @return void
* @throws ReflectionException ReflectionException.
*/
public function test_verify_ajax() {
public function test_verify_ajax(): void {
$value = 'some hcaptcha response';
$input = 'some_input_name';
$field = [ 'required' => true ];
Expand All @@ -279,7 +279,7 @@ public function test_verify_ajax() {
/**
* Test enqueue_scripts().
*/
public function test_enqueue_scripts() {
public function test_enqueue_scripts(): void {
$field = [
'type' => 'acfe_recaptcha',
'key' => 'some-key',
Expand Down
24 changes: 12 additions & 12 deletions .tests/php/integration/Admin/Events/EventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EventsTest extends HCaptchaWPTestCase {
*
* @return void
*/
public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound
public function tearDown(): void {
unset( $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_TRUE_CLIENT_IP'] );

$this->drop_table();
Expand All @@ -42,7 +42,7 @@ public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDecl
*
* @return void
*/
public function test_constructor_and_init_hooks() {
public function test_constructor_and_init_hooks(): void {
update_option( 'hcaptcha_settings', [ 'statistics' => [ 'on' ] ] );

hcaptcha()->init_hooks();
Expand All @@ -60,7 +60,7 @@ public function test_constructor_and_init_hooks() {
*
* @return void
*/
public function test_save_event() {
public function test_save_event(): void {
global $wpdb;

$result = 'empty';
Expand Down Expand Up @@ -94,7 +94,7 @@ public function test_save_event() {

// Query the database to check if the event was saved.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$event = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}$table_name ORDER BY id DESC LIMIT 1" );
$event = $wpdb->get_row( "SELECT * FROM $wpdb->prefix$table_name ORDER BY id DESC LIMIT 1" );

// Check that the event data matches the test data.
// phpcs:disable WordPress.WP.AlternativeFunctions.json_encode_json_encode
Expand All @@ -112,7 +112,7 @@ public function test_save_event() {
*
* @return void
*/
public function test_save_event_with_wrong_params() {
public function test_save_event_with_wrong_params(): void {

$subject = new Events();

Expand All @@ -126,7 +126,7 @@ public function test_save_event_with_wrong_params() {
*
* @return void
*/
public function test_save_event_from_check_config() {
public function test_save_event_from_check_config(): void {

$subject = new Events();

Expand All @@ -151,7 +151,7 @@ public function test_save_event_from_check_config() {
*
* @return void
*/
public function test_get_events() {
public function test_get_events(): void {
$date = wp_date( 'Y-m-d H:i:s' );

$expected = [
Expand Down Expand Up @@ -208,7 +208,7 @@ public function test_get_events() {
*
* @return void
*/
public function test_get_forms() {
public function test_get_forms(): void {
$date = wp_date( 'Y-m-d H:i:s' );

$expected = [
Expand Down Expand Up @@ -261,7 +261,7 @@ public function test_get_forms() {
*
* @return void
*/
public function test_create_table() {
public function test_create_table(): void {
global $wpdb;

$charset_collate = $wpdb->get_charset_collate();
Expand Down Expand Up @@ -294,7 +294,7 @@ public function test_create_table() {
*
* @return void
*/
public function test_get_where_date_gmt() {
public function test_get_where_date_gmt(): void {
$dates = [ '2024-05-01', '2024-05-02' ];

$expected = "date_gmt BETWEEN '2024-05-01 00:00:00' AND '2024-05-02 23:59:59'";
Expand All @@ -315,12 +315,12 @@ public function test_get_where_date_gmt() {
*
* @return void
*/
private function drop_table() {
private function drop_table(): void {
global $wpdb;

$table_name = Events::TABLE_NAME;

// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$table_name" );
$wpdb->query( "DROP TABLE IF EXISTS $wpdb->prefix$table_name" );
}
}
Loading

0 comments on commit 5aece80

Please sign in to comment.