From 1ce276b14e8b09771ef9728cdb7958e3570a17d3 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Thu, 20 Jul 2023 02:02:02 +0300 Subject: [PATCH] Fix test for PHP 7. --- .tests/php/integration/Mailchimp/FormTest.php | 40 ++++++++++--------- src/php/Mailchimp/Form.php | 3 ++ src/php/NF/Fields.php | 3 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.tests/php/integration/Mailchimp/FormTest.php b/.tests/php/integration/Mailchimp/FormTest.php index 9a1ce6d1..e895ba52 100644 --- a/.tests/php/integration/Mailchimp/FormTest.php +++ b/.tests/php/integration/Mailchimp/FormTest.php @@ -5,10 +5,15 @@ * @package HCaptcha\Tests */ +// phpcs:ignore Generic.Commenting.DocComment.MissingShort +/** @noinspection PhpUndefinedClassInspection */ + namespace HCaptcha\Tests\Integration\Mailchimp; use HCaptcha\Mailchimp\Form; use HCaptcha\Tests\Integration\HCaptchaWPTestCase; +use MC4WP_Form; +use MC4WP_Form_Element; use Mockery; /** @@ -18,11 +23,9 @@ class FormTest extends HCaptchaWPTestCase { /** * Test add_hcap_error_messages(). - * - * @noinspection PhpParamsInspection */ public function test_add_hcap_error_messages() { - $form = Mockery::mock( 'MC4WP_Form' ); + $form = Mockery::mock( MC4WP_Form::class ); $messages = [ 'foo' => [ @@ -86,46 +89,47 @@ public function test_add_hcap_error_messages() { /** * Test add_captcha(). - * - * @noinspection PhpParamsInspection */ public function test_add_captcha() { - $content = ''; - $expected = + $content = ''; + $expected = $this->get_hcap_form() . wp_nonce_field( 'hcaptcha_mailchimp', 'hcaptcha_mailchimp_nonce', true, false ) . ''; - $mc4wp_form = (object) [ - 'ID' => 5, - ]; - $subject = new Form(); - self::assertSame( $expected, $subject->add_captcha( $content, $mc4wp_form, null ) ); + $mc4wp_form = Mockery::mock( MC4WP_Form::class ); + $mc4wp_form->ID = 5; + + $element = Mockery::mock( MC4WP_Form_Element::class ); + + $subject = new Form(); + + self::assertSame( $expected, $subject->add_captcha( $content, $mc4wp_form, $element ) ); } /** * Test verify(). - * - * @noinspection PhpParamsInspection */ public function test_verify() { $this->prepare_hcaptcha_verify_POST( 'hcaptcha_mailchimp_nonce', 'hcaptcha_mailchimp' ); + $mc4wp_form = Mockery::mock( MC4WP_Form::class ); + $subject = new Form(); - self::assertSame( [], $subject->verify( [], null ) ); + self::assertSame( [], $subject->verify( [], $mc4wp_form ) ); } /** * Test verify() not verified. - * - * @noinspection PhpParamsInspection */ public function test_verify_not_verified() { $this->prepare_hcaptcha_verify_POST( 'hcaptcha_mailchimp_nonce', 'hcaptcha_mailchimp', false ); + $mc4wp_form = Mockery::mock( MC4WP_Form::class ); + $subject = new Form(); - self::assertSame( [ 'fail' ], $subject->verify( [], null ) ); + self::assertSame( [ 'fail' ], $subject->verify( [], $mc4wp_form ) ); } } diff --git a/src/php/Mailchimp/Form.php b/src/php/Mailchimp/Form.php index 42e29a5e..458f7df6 100644 --- a/src/php/Mailchimp/Form.php +++ b/src/php/Mailchimp/Form.php @@ -11,6 +11,8 @@ namespace HCaptcha\Mailchimp; use HCaptcha\Helpers\HCaptcha; +use MC4WP_Form; +use MC4WP_Form_Element; /** * Class Form. @@ -74,6 +76,7 @@ public function add_hcap_error_messages( array $messages, MC4WP_Form $form ): ar * * @return string * @noinspection PhpUnusedParameterInspection + * @noinspection PhpUndefinedFieldInspection */ public function add_captcha( string $content, MC4WP_Form $form, MC4WP_Form_Element $element ): string { $args = [ diff --git a/src/php/NF/Fields.php b/src/php/NF/Fields.php index d465b749..fcb10ea6 100644 --- a/src/php/NF/Fields.php +++ b/src/php/NF/Fields.php @@ -67,9 +67,8 @@ public function __construct() { * @param mixed $data Data. * * @return null|string - * @noinspection PhpUnusedParameterInspection */ - public function validate( array $field, $data ) { + public function validate( $field, $data ) { $value = $field['value'] ?? ''; return hcaptcha_request_verify( $value );