xref: /web-bugs/tests/Unit/Utils/CaptchaTest.php (revision f762db34)
1<?php declare(strict_types=1);
2
3namespace App\Tests\Unit\Utils;
4
5use PHPUnit\Framework\TestCase;
6use App\Utils\Captcha;
7
8class CaptchaTest extends TestCase
9{
10    /** @var Captcha */
11    private $captcha;
12
13    public function setUp(): void
14    {
15        $this->captcha = new Captcha();
16    }
17
18    /**
19     * @dataProvider mathProvider
20     */
21    public function testGetQuestion(int $first, int $last, string $operation, string $question, int $expected): void
22    {
23        $this->captcha->setFirst($first);
24        $this->captcha->setLast($last);
25        $this->captcha->setOperation($operation);
26
27        $this->assertEquals($question, $this->captcha->getQuestion());
28        $this->assertEquals($expected, $this->captcha->getAnswer());
29    }
30
31    public function mathProvider(): array
32    {
33        return [
34            [1, 2, 'addition', '1 + 2 = ?', 3],
35            [10, 50, 'subtraction', '50 - 10 = ?', 40],
36            [90, 50, 'subtraction', '90 - 50 = ?', 40],
37            [14, 14, 'subtraction', '14 - 14 = ?', 0],
38            [10, 5, 'multiplication', '10 + 5 = ?', 15],
39            [12, 2, 'foo', '12 + 2 = ?', 14],
40        ];
41    }
42}
43