-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserRepositoryTest.php
More file actions
63 lines (54 loc) · 2.19 KB
/
UserRepositoryTest.php
File metadata and controls
63 lines (54 loc) · 2.19 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
<?php
declare(strict_types=1);
namespace Tests\DependencyInversionPrinciple;
use PHPUnit\Framework\TestCase;
use SOLID\DependencyInversionPrinciple\DatabaseRow;
use SOLID\DependencyInversionPrinciple\MySQLDatabase;
use SOLID\DependencyInversionPrinciple\PostgresDatabase;
use SOLID\DependencyInversionPrinciple\UserRepository;
/**
* Class UserRepositoryTest.
*
* It tests the Dependency Inversion Principle by creating a
* UserRepository object with a Database object as a dependency.
* It then retrieves a user by ID and asserts that the user's properties match the expected values.
*
* @internal
*/
final class UserRepositoryTest extends TestCase
{
/**
* Test the Dependency Inversion Principle.
*
* This method tests the Dependency Inversion Principle by creating a UserRepository object with
* a MySQLDatabase object as a dependency.
* It then retrieves a user by ID and asserts that the user's properties
* (name, email, permission) match the expected values.
*/
public function testMySQLDatabaseDependencyInversionPrinciple(): void
{
$database = new MySQLDatabase(new DatabaseRow());
$userRepo = new UserRepository($database);
$actual = $userRepo->getById(1);
self::assertSame('name data', $actual->getName());
self::assertSame('email data', $actual->getEmail());
self::assertSame('permission data', $actual->getPermission());
}
/**
* Test the Dependency Inversion Principle.
*
* This method tests the Dependency Inversion Principle by creating a UserRepository object with
* a PostgresDatabase object as a dependency.
* It then retrieves a user by ID and asserts that the user's properties
* (name, email, permission) match the expected values.
*/
public function testPostgresDatabaseDependencyInversionPrinciple(): void
{
$database = new PostgresDatabase(new DatabaseRow());
$userRepo = new UserRepository($database);
$actual = $userRepo->getById(1);
self::assertSame('name data', $actual->getName());
self::assertSame('email data', $actual->getEmail());
self::assertSame('permission data', $actual->getPermission());
}
}