-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for Captcha and HTML.
- Loading branch information
1 parent
cf439d8
commit 05ad25a
Showing
24 changed files
with
937 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Captcha; | ||
|
||
use App\Captcha\AbstractAlphaCaptcha; | ||
use App\Service\DictionaryService; | ||
use App\Tests\TranslatorMockTrait; | ||
use PHPUnit\Framework\MockObject\Exception; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
/** | ||
* @template TCaptcha as AbstractAlphaCaptcha | ||
*/ | ||
abstract class AlphaCaptchaTestCase extends TestCase | ||
{ | ||
use TranslatorMockTrait; | ||
|
||
protected MockObject&DictionaryService $service; | ||
protected MockObject&TranslatorInterface $translator; | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$letters = \implode('', \range('A', 'Z')); | ||
$this->translator = $this->createTranslator(); | ||
$this->service = $this->createMock(DictionaryService::class); | ||
$this->service->expects(self::any()) | ||
->method('getRandomWord') | ||
->willReturn($letters); | ||
} | ||
|
||
public function testCheckAnswer(): void | ||
{ | ||
$captcha = $this->createCaptcha($this->service); | ||
$captcha->setTranslator($this->translator); | ||
|
||
$challenge = $captcha->getChallenge(); | ||
self::assertCount(2, $challenge); | ||
$actual = $captcha->checkAnswer($challenge[1], $challenge[1]); | ||
self::assertTrue($actual); | ||
} | ||
|
||
/** | ||
* @psalm-return TCaptcha | ||
*/ | ||
abstract protected function createCaptcha(DictionaryService $service): AbstractAlphaCaptcha; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Captcha; | ||
|
||
use App\Captcha\AbstractAlphaCaptcha; | ||
use App\Captcha\ConsonantCaptcha; | ||
use App\Service\DictionaryService; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
|
||
/** | ||
* @extends AlphaCaptchaTestCase<ConsonantCaptcha> | ||
*/ | ||
#[CoversClass(ConsonantCaptcha::class)] | ||
#[CoversClass(AbstractAlphaCaptcha::class)] | ||
class ConsonantCaptchaTest extends AlphaCaptchaTestCase | ||
{ | ||
protected function createCaptcha(DictionaryService $service): ConsonantCaptcha | ||
{ | ||
return new ConsonantCaptcha($service); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Captcha; | ||
|
||
use App\Captcha\AbstractAlphaCaptcha; | ||
use App\Captcha\LetterCaptcha; | ||
use App\Service\DictionaryService; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
|
||
/** | ||
* @extends AlphaCaptchaTestCase<LetterCaptcha> | ||
*/ | ||
#[CoversClass(LetterCaptcha::class)] | ||
#[CoversClass(AbstractAlphaCaptcha::class)] | ||
class LetterCaptchaTest extends AlphaCaptchaTestCase | ||
{ | ||
protected function createCaptcha(DictionaryService $service): LetterCaptcha | ||
{ | ||
return new LetterCaptcha($service); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Captcha; | ||
|
||
use App\Captcha\AbstractAlphaCaptcha; | ||
use App\Captcha\VowelCaptcha; | ||
use App\Service\DictionaryService; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
|
||
/** | ||
* @extends AlphaCaptchaTestCase<VowelCaptcha> | ||
*/ | ||
#[CoversClass(VowelCaptcha::class)] | ||
#[CoversClass(AbstractAlphaCaptcha::class)] | ||
class VowelCaptchaTest extends AlphaCaptchaTestCase | ||
{ | ||
protected function createCaptcha(DictionaryService $service): VowelCaptcha | ||
{ | ||
return new VowelCaptcha($service); | ||
} | ||
} |
Oops, something went wrong.