Skip to content

Commit

Permalink
support php8.0 & php8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Erwane committed Jul 28, 2022
1 parent 663243c commit dd52728
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
},
"require": {
"php": "^7.2",
"php": "^7.2 | ^8.0",
"cakephp/cakephp": "^4.0"
},
"require-dev": {
Expand All @@ -36,5 +36,11 @@
"scripts": {
"cscheck": "vendor/bin/phpcs -p src/ tests/",
"csfix": "vendor/bin/phpcbf src/ tests/"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpro/grumphp": true
}
}
}
10 changes: 5 additions & 5 deletions tests/TestCase/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ protected function setUp(): void
public function testInitialize(): void
{
$listeners = EventManager::instance()->listeners('View.beforeRender');
self::assertCount(1, $listeners);
self::assertInstanceOf('\Hcaptcha\Plugin', $listeners[0]['callable'][0]);
self::assertSame('addWidget', $listeners[0]['callable'][1]);
$this->assertCount(1, $listeners);
$this->assertInstanceOf('\Hcaptcha\Plugin', $listeners[0]['callable'][0]);
$this->assertSame('addWidget', $listeners[0]['callable'][1]);
}

/**
Expand All @@ -56,7 +56,7 @@ public function testAddWidgetNoFormHelper(): void
/** @noinspection PhpVoidFunctionResultUsedInspection */
$result = $this->plugin->addWidget($event);

self::assertNull($result);
$this->assertNull($result);
}

/**
Expand All @@ -75,6 +75,6 @@ public function testAddWidget(): void

/** @var \Cake\View\Helper\FormHelper $formHelper */
$formHelper = $view->helpers()->get('Form');
self::assertInstanceOf(HCaptchaWidget::class, $formHelper->getWidgetLocator()->get('hcaptcha'));
$this->assertInstanceOf(HCaptchaWidget::class, $formHelper->getWidgetLocator()->get('hcaptcha'));
}
}
28 changes: 14 additions & 14 deletions tests/TestCase/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class ValidationTest extends TestCase
public function testGetClient(): void
{
$client = Validation::getClient();
self::assertInstanceOf(Client::class, $client);
self::assertSame(3, $client->getConfig('timeout'));
$this->assertInstanceOf(Client::class, $client);
$this->assertSame(3, $client->getConfig('timeout'));
}

/**
Expand All @@ -38,18 +38,18 @@ public function testHcaptchaResponseFail(): void

$response = $this->createPartialMock(Client\Response::class, ['isSuccess']);

$client->expects(self::once())
$client->expects($this->once())
->method('post')
->with('https://hcaptcha.com/siteverify', [
'secret' => 'hcaptcha-secret',
'response' => 'testing-post-fail',
])
->willReturn($response);
$response->expects(self::once())->method('isSuccess')->willReturn(false);
$response->expects($this->once())->method('isSuccess')->willReturn(false);

Validation::setClient($client);
$result = Validation::hcaptcha('testing-post-fail');
self::assertFalse($result);
$this->assertFalse($result);
}

/**
Expand All @@ -62,25 +62,25 @@ public function testHcaptchaSuccessNotSet(): void
$client = $this->createPartialMock(Client::class, ['post']);
$response = $this->createPartialMock(Client\Response::class, ['isSuccess', 'getJson']);

$client->expects(self::exactly(2))
$client->expects($this->exactly(2))
->method('post')
->willReturn($response);

$response->expects(self::exactly(2))
$response->expects($this->exactly(2))
->method('isSuccess')
->willReturn(true);

$response->expects(self::exactly(2))
$response->expects($this->exactly(2))
->method('getJson')
->willReturnOnConsecutiveCalls(false, ['response']);

Validation::setClient($client);

$result = Validation::hcaptcha('testing-success');
self::assertFalse($result);
$this->assertFalse($result);

$result = Validation::hcaptcha('testing-success');
self::assertFalse($result);
$this->assertFalse($result);
}

/**
Expand All @@ -93,21 +93,21 @@ public function testHcaptchaSuccess(): void
$client = $this->createPartialMock(Client::class, ['post']);
$response = $this->createPartialMock(Client\Response::class, ['isSuccess', 'getJson']);

$client->expects(self::once())
$client->expects($this->once())
->method('post')
->willReturn($response);

$response->expects(self::once())
$response->expects($this->once())
->method('isSuccess')
->willReturn(true);

$response->expects(self::once())
$response->expects($this->once())
->method('getJson')
->willReturn(['success' => true]);

Validation::setClient($client);

$result = Validation::hcaptcha('testing-success');
self::assertTrue($result);
$this->assertTrue($result);
}
}
14 changes: 7 additions & 7 deletions tests/TestCase/View/Widget/HCaptchaWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public function testRenderWithoutJs(): void
{
$context = new ArrayContext([]);

$this->form->expects(self::exactly(2))
$this->form->expects($this->exactly(2))
->method('unlockField')
->withConsecutive(['field'], ['g-recaptcha-response']);

$this->html->expects(self::never())->method('script');
$this->html->expects($this->never())->method('script');

$result = $this->widget->render(['fieldName' => 'field', 'withoutJs' => true], $context);
self::assertSame('<div class="h-captcha" data-sitekey=""></div>', $result);
$this->assertSame('<div class="h-captcha" data-sitekey=""></div>', $result);
}

/**
Expand All @@ -82,7 +82,7 @@ public function testRenderNoKey(): void
Log::setConfig('error', $log);

$this->widget->render(['fieldName' => 'field'], $context);
self::assertSame(['error Configure HCaptcha.key in your app_local.php file'], $log->read());
$this->assertSame(['error: Configure HCaptcha.key in your app_local.php file'], $log->read());
}

/**
Expand All @@ -94,12 +94,12 @@ public function testRender(): void
Configure::write('HCaptcha.key', 'testing-site-key');
$context = new ArrayContext([]);

$this->html->expects(self::once())
$this->html->expects($this->once())
->method('script')
->with('https://hcaptcha.com/1/api.js', ['block' => 'script']);

$result = $this->widget->render(['fieldName' => 'field'], $context);
self::assertSame('<div class="h-captcha" data-sitekey="testing-site-key"></div>', $result);
$this->assertSame('<div class="h-captcha" data-sitekey="testing-site-key"></div>', $result);
}

/**
Expand All @@ -108,6 +108,6 @@ public function testRender(): void
*/
public function testSecureFields(): void
{
self::assertSame([], $this->widget->secureFields(['name' => 'testing']));
$this->assertSame([], $this->widget->secureFields(['name' => 'testing']));
}
}

0 comments on commit dd52728

Please sign in to comment.