From c038d1accac03ffc89d2ebb4293576ade104d325 Mon Sep 17 00:00:00 2001 From: karser Date: Tue, 21 Jan 2025 01:20:11 +0200 Subject: [PATCH] fixed tests --- ReCaptcha/ReCaptcha.php | 2 +- ReCaptcha/Response.php | 2 +- Tests/ReCaptcha/ReCaptchaTest.php | 3 -- Tests/ReCaptcha/RequestMethod/PostTest.php | 4 +++ .../RequestMethod/SocketPostTest.php | 2 +- phpunit.xml.dist | 35 +++++++++---------- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/ReCaptcha/ReCaptcha.php b/ReCaptcha/ReCaptcha.php index 472da00..ef68021 100644 --- a/ReCaptcha/ReCaptcha.php +++ b/ReCaptcha/ReCaptcha.php @@ -138,7 +138,7 @@ class ReCaptcha */ public function __construct(?string $secret, ?RequestMethod $requestMethod = null) { - if (null === $secret) { + if (!is_string($secret)) { throw new \RuntimeException('The provided secret must be a string'); } if ('' === $secret) { diff --git a/ReCaptcha/Response.php b/ReCaptcha/Response.php index 41191b9..8a8a261 100644 --- a/ReCaptcha/Response.php +++ b/ReCaptcha/Response.php @@ -91,7 +91,7 @@ public static function fromJson($json) { $responseData = json_decode($json, true); - if (false === $responseData) { + if (null === $responseData) { return new Response(false, array(ReCaptcha::E_INVALID_JSON)); } diff --git a/Tests/ReCaptcha/ReCaptchaTest.php b/Tests/ReCaptcha/ReCaptchaTest.php index 8e26c37..f38ced4 100644 --- a/Tests/ReCaptcha/ReCaptchaTest.php +++ b/Tests/ReCaptcha/ReCaptchaTest.php @@ -58,9 +58,6 @@ public static function invalidSecretProvider(): array return [ [''], [null], - [0], - [new \stdClass()], - [[]], ]; } diff --git a/Tests/ReCaptcha/RequestMethod/PostTest.php b/Tests/ReCaptcha/RequestMethod/PostTest.php index c5c50d6..f28157a 100644 --- a/Tests/ReCaptcha/RequestMethod/PostTest.php +++ b/Tests/ReCaptcha/RequestMethod/PostTest.php @@ -136,6 +136,10 @@ protected function assertCommonOptions(array $args) } } +namespace Karser\Recaptcha3Bundle\ReCaptcha\RequestMethod; + +use Karser\Recaptcha3Bundle\Tests\ReCaptcha\RequestMethod\PostTest; + function file_get_contents() { if (PostTest::$assert) { diff --git a/Tests/ReCaptcha/RequestMethod/SocketPostTest.php b/Tests/ReCaptcha/RequestMethod/SocketPostTest.php index 24dcb20..de379d8 100644 --- a/Tests/ReCaptcha/RequestMethod/SocketPostTest.php +++ b/Tests/ReCaptcha/RequestMethod/SocketPostTest.php @@ -134,7 +134,7 @@ public function testConnectionFailureReturnsError() $socket->expects(self::once()) ->method('fsockopen') - ->willReturn(false); + ->willReturn(null); $ps = new SocketPost($socket); $response = $ps->submit(new RequestParameters("secret", "response", "remoteip", "version")); self::assertEquals('{"success": false, "error-codes": ["'.ReCaptcha::E_CONNECTION_FAILED.'"]}', $response); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f32f070..dd1f11a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,23 +1,22 @@ - - - ./Tests - - - - - . - - - Resources - Tests - vendor - - + + + ./Tests + + + + + . + + + Resources + Tests + vendor + +