-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactoryTest.php
More file actions
82 lines (70 loc) · 2.55 KB
/
FactoryTest.php
File metadata and controls
82 lines (70 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php declare(strict_types=1);
namespace Tests\Csrf;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-csrf\Csrf\Factory
*
* @author fdipzone
*/
final class FactoryResponseTest extends TestCase
{
/**
* @covers \Csrf\Factory::getTokenClass
*/
public function testGetTokenClass()
{
$type = \Csrf\Type::INTERNAL_CSRF;
$token_class = \Csrf\Factory::getTokenClass($type);
$this->assertEquals('\Csrf\InternalCsrf', $token_class);
$type = \Csrf\Type::GOOGLE_RECAPTCHA_V2;
$token_class = \Csrf\Factory::getTokenClass($type);
$this->assertEquals('\Csrf\GoogleRecaptchaV2', $token_class);
$type = \Csrf\Type::GOOGLE_RECAPTCHA_V3;
$token_class = \Csrf\Factory::getTokenClass($type);
$this->assertEquals('\Csrf\GoogleRecaptchaV3', $token_class);
}
/**
* @covers \Csrf\Factory::getTokenClass
*/
public function testGetTokenClassException()
{
$this->expectException(\Csrf\Exception\TypeException::class);
$this->expectExceptionMessage('csrf type not exists');
$type = 'not_exists_type';
\Csrf\Factory::getTokenClass($type);
}
/**
* @covers \Csrf\Factory::make
*/
public function testMake()
{
$secret = 'abc123';
$type = \Csrf\Type::INTERNAL_CSRF;
$config = new \Csrf\Config\InternalCsrfConfig($secret);
$csrf = \Csrf\Factory::make($type, $config);
$this->assertEquals('Csrf\InternalCsrf', get_class($csrf));
$this->assertInstanceOf(\Csrf\ICsrf::class, $csrf);
$type = \Csrf\Type::GOOGLE_RECAPTCHA_V2;
$config = new \Csrf\Config\GoogleRecaptchaV2Config($secret);
$csrf = \Csrf\Factory::make($type, $config);
$this->assertEquals('Csrf\GoogleRecaptchaV2', get_class($csrf));
$this->assertInstanceOf(\Csrf\ICsrf::class, $csrf);
$type = \Csrf\Type::GOOGLE_RECAPTCHA_V3;
$config = new \Csrf\Config\GoogleRecaptchaV3Config($secret);
$csrf = \Csrf\Factory::make($type, $config);
$this->assertEquals('Csrf\GoogleRecaptchaV3', get_class($csrf));
$this->assertInstanceOf(\Csrf\ICsrf::class, $csrf);
}
/**
* @covers \Csrf\Factory::make
*/
public function testMakeException()
{
$this->expectException(\Csrf\Exception\FactoryException::class);
$this->expectExceptionMessage('csrf type not exists');
$type = 'not_exists_type';
$secret = 'abc123';
$config = new \Csrf\Config\InternalCsrfConfig($secret);
\Csrf\Factory::make($type, $config);
}
}