Skip to content

Commit

Permalink
Upgrade unit 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 ea851be commit 5d682e4
Show file tree
Hide file tree
Showing 18 changed files with 226 additions and 216 deletions.
31 changes: 14 additions & 17 deletions .tests/php/unit/AutoVerify/AutoVerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDecl
*
* @return void
*/
public function test_init_and_init_hooks() {
public function test_init_and_init_hooks(): void {
$subject = new AutoVerify();

WP_Mock::expectActionAdded( 'init', [ $subject, 'verify_form' ], -PHP_INT_MAX );
Expand All @@ -61,7 +61,7 @@ public function test_init_and_init_hooks() {
/**
* Test content_filter() on frontend.
*/
public function test_content_filter_on_frontend() {
public function test_content_filter_on_frontend(): void {
FunctionMocker::replace(
'\HCaptcha\Helpers\Request::is_frontend',
true
Expand All @@ -81,7 +81,7 @@ public function test_content_filter_on_frontend() {
/**
* Test content_filter() not on frontend.
*/
public function test_content_filter_not_on_frontend() {
public function test_content_filter_not_on_frontend(): void {
FunctionMocker::replace(
'\HCaptcha\Helpers\Request::is_frontend',
false
Expand All @@ -97,7 +97,7 @@ public function test_content_filter_not_on_frontend() {
/**
* Test widget_block_content_filter() on frontend.
*/
public function test_widget_block_content_filter_on_frontend() {
public function test_widget_block_content_filter_on_frontend(): void {
FunctionMocker::replace(
'\HCaptcha\Helpers\Request::is_frontend',
true
Expand All @@ -118,7 +118,7 @@ public function test_widget_block_content_filter_on_frontend() {
/**
* Test verify_form() not on frontend.
*/
public function test_verify_form_not_on_frontend() {
public function test_verify_form_not_on_frontend(): void {
FunctionMocker::replace(
'\HCaptcha\Helpers\Request::is_frontend',
false
Expand All @@ -131,7 +131,7 @@ public function test_verify_form_not_on_frontend() {
/**
* Test verify_form() when not POST request.
*/
public function test_verify_form_when_not_post_request() {
public function test_verify_form_when_not_post_request(): void {
FunctionMocker::replace(
'\HCaptcha\Helpers\Request::is_frontend',
true
Expand All @@ -148,10 +148,7 @@ public function test_verify_form_when_not_post_request() {
/**
* Test verify_form() when no path.
*/
public function test_verify_form_when_no_path() {
$url = '';
$path = '';

public function test_verify_form_when_no_path(): void {
FunctionMocker::replace(
'\HCaptcha\Helpers\Request::is_frontend',
true
Expand Down Expand Up @@ -181,7 +178,7 @@ static function ( $value ) {
/**
* Test verify_form() when form is not registered.
*/
public function test_verify_form_when_form_is_not_registered() {
public function test_verify_form_when_form_is_not_registered(): void {
$url = 'https://test.test/auto-verify?test=1';

// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
Expand Down Expand Up @@ -219,7 +216,7 @@ static function ( $value ) {
/**
* Test verify_form() when the form is verified.
*/
public function test_verify_form_when_the_form_is_verified() {
public function test_verify_form_when_the_form_is_verified(): void {
$url = 'https://test.test/auto-verify?test=1';

// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
Expand Down Expand Up @@ -258,7 +255,7 @@ static function ( $value ) {
/**
* Test verify_form() when the form is not verified.
*/
public function test_verify_form_when_the_form_is_not_verified() {
public function test_verify_form_when_the_form_is_not_verified(): void {
$url = 'https://test.test/auto-verify?test=1';
$result = 'Some hCaptcha error.';

Expand Down Expand Up @@ -314,7 +311,7 @@ static function ( $value ) {
*
* @return void
*/
public function test_register_forms_with_empty_forms() {
public function test_register_forms_with_empty_forms(): void {
$subject = Mockery::mock( AutoVerify::class )->makePartial();

$subject->shouldAllowMockingProtectedMethods();
Expand All @@ -328,7 +325,7 @@ public function test_register_forms_with_empty_forms() {
*
* @return void
*/
public function test_register_forms() {
public function test_register_forms(): void {
$forms = [ $this->get_test_form() ];
$action = '/action-page';
$expected = [
Expand Down Expand Up @@ -394,7 +391,7 @@ static function ( $url, $component ) {
* @dataProvider dp_test_update_transient
* @throws ReflectionException ReflectionException.
*/
public function test_update_transient( $transient, array $forms_data, array $expected ) {
public function test_update_transient( $transient, array $forms_data, array $expected ): void {
$day_in_seconds = 24 * 60 * 60;

FunctionMocker::replace(
Expand Down Expand Up @@ -549,7 +546,7 @@ public function dp_test_update_transient(): array {
* @dataProvider dp_test_is_form_registered
* @return void
*/
public function test_is_form_registered( $transient, string $path, array $post, bool $expected ) {
public function test_is_form_registered( $transient, string $path, array $post, bool $expected ): void {
$_POST = $post;

WP_Mock::userFunction( 'get_transient' )
Expand Down
10 changes: 5 additions & 5 deletions .tests/php/unit/Divi/FixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FixTest extends HCaptchaTestCase {
/**
* Test init().
*/
public function test_init() {
public function test_init(): void {
$mock = Mockery::mock( Fix::class )->makePartial();
$mock->shouldReceive( 'init_hooks' )->with()->once();

Expand All @@ -37,7 +37,7 @@ public function test_init() {
/**
* Test init_hooks().
*/
public function test_init_hooks() {
public function test_init_hooks(): void {
$subject = new Fix();

WP_Mock::expectActionAdded( 'init', [ $subject, 'register_autoload' ], - PHP_INT_MAX );
Expand All @@ -48,7 +48,7 @@ public function test_init_hooks() {
/**
* Test register_autoload().
*/
public function test_register_autoload() {
public function test_register_autoload(): void {
$autoload = FunctionMocker::replace( 'spl_autoload_register' );

FunctionMocker::replace(
Expand All @@ -67,7 +67,7 @@ static function ( $constant_name ) {
/**
* Test register_autoload() without the Divi theme.
*/
public function test_register_autoload_without_divi_theme() {
public function test_register_autoload_without_divi_theme(): void {
$autoload = FunctionMocker::replace( 'spl_autoload_register' );

$subject = new Fix();
Expand All @@ -79,7 +79,7 @@ public function test_register_autoload_without_divi_theme() {
/**
* Test prevent_loading_of_wp_test_case().
*/
public function test_prevent_loading_of_wp_test_case() {
public function test_prevent_loading_of_wp_test_case(): void {
$subject = new Fix();

$codeception_wp_test_case = 'Codeception\TestCase\WPTestCase';
Expand Down
8 changes: 4 additions & 4 deletions .tests/php/unit/HCaptchaTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDecl
*
* @throws ReflectionException Reflection exception.
*/
protected function get_protected_property( $subject, string $property_name ) {
protected function get_protected_property( object $subject, string $property_name ) {
$property = ( new ReflectionClass( $subject ) )->getProperty( $property_name );
$property->setAccessible( true );
$value = $property->getValue( $subject );
Expand All @@ -74,7 +74,7 @@ protected function get_protected_property( $subject, string $property_name ) {
*
* @throws ReflectionException Reflection exception.
*/
protected function set_protected_property( $subject, string $property_name, $value ) {
protected function set_protected_property( object $subject, string $property_name, $value ): void {
$property = ( new ReflectionClass( $subject ) )->getProperty( $property_name );
$property->setAccessible( true );
$property->setValue( $subject, $value );
Expand All @@ -92,7 +92,7 @@ protected function set_protected_property( $subject, string $property_name, $val
*
* @throws ReflectionException Reflection exception.
*/
protected function set_method_accessibility( $subject, string $method_name, bool $accessible = true ): ReflectionMethod {
protected function set_method_accessibility( object $subject, string $method_name, bool $accessible = true ): ReflectionMethod {
$method = ( new ReflectionClass( $subject ) )->getMethod( $method_name );
$method->setAccessible( $accessible );

Expand Down Expand Up @@ -331,7 +331,7 @@ protected function get_test_form_fields(): array {
* @return void
* @noinspection PhpUnusedParameterInspection
*/
protected function set_defaults( array &$field, string $id ) {
protected function set_defaults( array &$field, string $id ): void {
$field = array_merge(
[
'default' => '',
Expand Down
4 changes: 2 additions & 2 deletions .tests/php/unit/MainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MainTest extends HCaptchaTestCase {
/**
* Test init().
*/
public function test_is_xml_rpc() {
public function test_is_xml_rpc(): void {
$mock = Mockery::mock( Main::class )->makePartial();

$mock->shouldAllowMockingProtectedMethods();
Expand Down Expand Up @@ -50,7 +50,7 @@ static function ( $name ) {
* @return void
* @noinspection UnusedFunctionResultInspection
*/
public function test_declare_wc_compatibility() {
public function test_declare_wc_compatibility(): void {
$mock = Mockery::mock( 'alias:Automattic\WooCommerce\Utilities\FeaturesUtil' );
$mock->shouldReceive( 'declare_compatibility' )
->with( 'custom_order_tables', HCAPTCHA_TEST_FILE, true )
Expand Down
Loading

0 comments on commit 5d682e4

Please sign in to comment.