1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wearesho\Yii\Tests\Configs; |
4
|
|
|
|
5
|
|
|
use Carbon\CarbonInterval; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
10
|
|
|
|
11
|
|
|
use Wearesho\Yii\Configs\TokenRepositoryConfig; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class TokenRepositorySettingsTest |
15
|
|
|
* @package Wearesho\Yii\Tests\Configs |
16
|
|
|
*/ |
17
|
|
|
class TokenRepositorySettingsTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** @var TokenRepositoryConfig */ |
20
|
|
|
protected $config; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @throws \yii\base\InvalidConfigException |
24
|
|
|
* @throws \yii\di\NotInstantiableException |
25
|
|
|
*/ |
26
|
|
|
protected function setUp() |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
$this->config = \Yii::$container->get(TokenRepositoryConfig::class); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function testExpire() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
putenv("{$this->config->expirePeriodKey}=0"); |
35
|
|
|
|
36
|
|
|
$this->config->defaultExpirePeriod = $expirePeriod = mt_rand(1, 10); |
37
|
|
|
$this->assertEquals($expirePeriod, $this->config->getExpirePeriod()->minutes); |
38
|
|
|
|
39
|
|
|
$this->config->defaultExpirePeriod = 0; |
40
|
|
|
putenv("{$this->config->expirePeriodKey}={$expirePeriod}"); |
41
|
|
|
$this->assertEquals($expirePeriod, $this->config->getExpirePeriod()->minutes); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function testDeliveryLimit() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
putenv("{$this->config->deliveryLimitKey}=0"); |
47
|
|
|
|
48
|
|
|
$this->config->defaultDeliveryLimit = $deliveryLimit = mt_rand(1, 10); |
49
|
|
|
$this->assertEquals($deliveryLimit, $this->config->getDeliveryLimit()); |
50
|
|
|
|
51
|
|
|
$this->config->defaultDeliveryLimit = 0; |
52
|
|
|
putenv("{$this->config->deliveryLimitKey}={$deliveryLimit}"); |
53
|
|
|
$this->assertEquals($deliveryLimit, $this->config->getDeliveryLimit()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function testVerifyLimit() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
putenv("{$this->config->verifyLimitKey}=0"); |
59
|
|
|
|
60
|
|
|
$this->config->defaultVerifyLimit = $verifyLimit = mt_rand(1, 10); |
61
|
|
|
$this->assertEquals($verifyLimit, $this->config->getVerifyLimit()); |
62
|
|
|
|
63
|
|
|
$this->config->defaultVerifyLimit = 0; |
64
|
|
|
putenv("{$this->config->verifyLimitKey}={$verifyLimit}"); |
65
|
|
|
$this->assertEquals($verifyLimit, $this->config->getVerifyLimit()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.