mirror of
https://github.com/php/web-bugs.git
synced 2026-03-24 07:42:08 +01:00
- Added filter to phpunit config - This enables support for coverage support - Moved unit tests to dedicated directory - Also created constants for the locations of the fixtures and mocks for testing so we do not have to use relative paths in tests - Updated phpunit to 8 - Added type information to tests - Added return type and parameter type declarations for tests - Added strict types to tests - CS fixes in tests - Aligning arrays, consistent string concatenation, removed unused local vars - Added constant for test cache directory - Make the autoloader also properly work on windows - Windows does not care about the directory separator used so just trim both variant from the end.
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\Utils;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use App\Utils\Captcha;
|
|
|
|
class CaptchaTest extends TestCase
|
|
{
|
|
/** @var Captcha */
|
|
private $captcha;
|
|
|
|
public function setUp(): void
|
|
{
|
|
$this->captcha = new Captcha();
|
|
}
|
|
|
|
/**
|
|
* @dataProvider mathProvider
|
|
*/
|
|
public function testGetQuestion(int $first, int $last, string $operation, string $question, int $expected): void
|
|
{
|
|
$this->captcha->setFirst($first);
|
|
$this->captcha->setLast($last);
|
|
$this->captcha->setOperation($operation);
|
|
|
|
$this->assertEquals($question, $this->captcha->getQuestion());
|
|
$this->assertEquals($expected, $this->captcha->getAnswer());
|
|
}
|
|
|
|
public function mathProvider(): array
|
|
{
|
|
return [
|
|
[1, 2, 'addition', '1 + 2 = ?', 3],
|
|
[10, 50, 'subtraction', '50 - 10 = ?', 40],
|
|
[90, 50, 'subtraction', '90 - 50 = ?', 40],
|
|
[14, 14, 'subtraction', '14 - 14 = ?', 0],
|
|
[10, 5, 'multiplication', '10 + 5 = ?', 15],
|
|
[12, 2, 'foo', '12 + 2 = ?', 14],
|
|
];
|
|
}
|
|
}
|