1 | <?php |
||
21 | protected function setUp(): void |
||
22 | { |
||
23 | parent::setUp(); |
||
24 | $this->query = new TokenQuery(TokenRecordMock::class); |
||
25 | |||
26 | Carbon::setTestNow(Carbon::create(2014, 1, 1, 1)); |
||
27 | $token = new TokenRecordMock([ |
||
28 | 'id' => 1, |
||
29 | 'recipient' => "380500000001", |
||
30 | 'token' => "000001", |
||
31 | ]); |
||
32 | Validation\Exception::saveOrThrow($token); |
||
33 | Carbon::setTestNow(); |
||
34 | } |
||
35 | |||
36 | public function testModelClass(): void |
||
37 | { |
||
38 | $this->assertEquals( |
||
39 | TokenRecordMock::class, |
||
40 | $this->query->modelClass, |
||
41 | "Query should be equal to passed to constructor class" |
||
42 | ); |
||
43 | } |
||
44 | |||
45 | public function testWhereRecipient(): void |
||
46 | { |
||
47 | $tokenInstance = $this->query |
||
48 | ->whereRecipient($firstUserRecipient = '380500000001') |
||
49 | ->andWhere(['=', 'id', $fieldUserId = 1]) |
||
50 | ->one(); |
||
51 | |||
52 | $this->assertInstanceOf( |
||
53 | Token::class, |
||
54 | $tokenInstance, |
||
55 | "Query should use whereRecipient argument to find" |
||
56 | ); |
||
57 | |||
58 | $tokenInstance = $this->query |
||
59 | ->whereRecipient($invalidRecipient = '380500000000') |
||
60 | ->andWhere(['=', 'id', 1]) |
||
61 | ->one(); |
||
62 | |||
63 | $this->assertNull( |
||
64 | $tokenInstance |
||
65 | ); |
||
66 | } |
||
67 | |||
68 | public function testNotExpired(): void |
||
69 | { |
||
70 | // Setting now to hour bigger than first token created_at |
||
71 | Carbon::setTestNow(Carbon::create(2014, 1, 1, 2)); |
||
72 | |||
73 | $tokenInstance = $this->query |
||
74 | ->notExpired(CarbonInterval::hour(1)) |
||
75 | ->andWhere(['=', 'id', 1]) |
||
76 | ->one(); |
||
77 | $this->assertInstanceOf( |
||
78 | Token::class, |
||
79 | $tokenInstance |
||
80 | ); |
||
81 | |||
82 | $tokenInstance = $this->query |
||
83 | ->notExpired(CarbonInterval::minutes(30)) |
||
84 | ->andWhere(['=', 'id', 1]) |
||
85 | ->one(); |
||
86 | $this->assertNull( |
||
87 | $tokenInstance |
||
88 | ); |
||
89 | |||
90 | Carbon::setTestNow(); |
||
91 | } |
||
92 | } |
||
93 |