Debian Codegraph @

tests/classes/Users/UserTest.php

raw symbols SCIP
1 <?php
2
3 namespace Liuch\DmarcSrg;
4
5 use Liuch\DmarcSrg\Users\User;
6 use Liuch\DmarcSrg\Exception\SoftException;
7 use PHPUnit\Framework\Attributes\DataProvider;
8
9 class UserTest extends \PHPUnit\Framework\TestCase
10 {
11 public function testConstantsExistence(): void
12 {
13 $this->assertIsInt(User::LEVEL_ADMIN);
14 $this->assertIsInt(User::LEVEL_MANAGER);
15 $this->assertIsInt(User::LEVEL_USER);
16 }
17
18 public function testLevelValue(): void
19 {
20 $this->assertGreaterThan(User::LEVEL_MANAGER, User::LEVEL_ADMIN);
21 $this->assertGreaterThan(User::LEVEL_USER, User::LEVEL_MANAGER);
22 }
23
24 /**
25 * @dataProvider dataProvider1
26 */
27 #[DataProvider('dataProvider1')]
28 public function testLevelToStringCorrectValue(int $ilevel, string $slevel): void
29 {
30 $this->assertSame(User::levelToString($ilevel), $slevel);
31 }
32
33 /**
34 * @dataProvider dataProvider1
35 */
36 #[DataProvider('dataProvider1')]
37 public function testLevelToStringIncorrectValue(int $ilevel, string $slevel): void
38 {
39 if ($ilevel === User::LEVEL_USER) {
40 $this->assertSame(User::levelToString($ilevel - 1), $slevel);
41 } else {
42 $this->assertNotSame(User::levelToString($ilevel - 1), $slevel);
43 }
44 }
45
46 /**
47 * @dataProvider dataProvider1
48 */
49 #[DataProvider('dataProvider1')]
50 public function testStringToLevelCorrectValue(int $ilevel, string $slevel): void
51 {
52 $this->assertSame(User::stringToLevel($slevel), $ilevel);
53 }
54
55 public function testStringToLevelIncorrectValue(): void
56 {
57 $this->expectException(SoftException::class);
58 User::stringToLevel('wrong_level');
59 }
60
61 public static function dataProvider1(): array
62 {
63 return [
64 [ User::LEVEL_ADMIN, 'admin' ],
65 [ User::LEVEL_MANAGER, 'manager' ],
66 [ User::LEVEL_USER, 'user' ]
67 ];
68 }
69 }