11
11
use Doctrine \ORM \Mapping \ClassMetadataFactory ;
12
12
use Doctrine \ORM \ORMSetup ;
13
13
use Doctrine \ORM \Tools \SchemaTool ;
14
+ use Linkage \DoctrineRowLevelSecurity \RowLevelSecurityAwarePostgreSqlConnection ;
15
+ use Linkage \DoctrineRowLevelSecurity \RowLevelSecurityListener ;
14
16
use Linkage \DoctrineRowLevelSecurity \Tests \Entity \Dog ;
15
17
use Linkage \DoctrineRowLevelSecurity \Tests \Entity \DogOwner ;
16
18
use PHPUnit \Framework \TestCase ;
@@ -28,6 +30,7 @@ protected function setUp(): void
28
30
'password ' => 'password ' ,
29
31
'host ' => 'localhost ' ,
30
32
'driver ' => 'pdo_pgsql ' ,
33
+ 'wrapperClass ' => RowLevelSecurityAwarePostgreSqlConnection::class,
31
34
];
32
35
$ conn = DriverManager::getConnection ($ connectionParams );
33
36
foreach (explode ('; ' , (string ) file_get_contents (__DIR__ . '/drop_table.sql ' )) as $ dropSql ) {
@@ -53,17 +56,22 @@ protected function setUp(): void
53
56
$ configuration ,
54
57
new EventManager (),
55
58
);
59
+ $ this ->em ->getEventManager ()->addEventSubscriber (new RowLevelSecurityListener ());
56
60
}
57
61
58
62
public function testCreateSchema (): void
59
63
{
60
64
$ schemaTool = new SchemaTool ($ this ->em );
65
+ $ this ->em ->getConnection ()->getDatabasePlatform ()->setEventManager ($ this ->em ->getEventManager ());
61
66
$ classMetadataFactory = new ClassMetadataFactory ();
62
67
$ classMetadataFactory ->setEntityManager ($ this ->em );
63
68
$ sql = $ schemaTool ->getCreateSchemaSql ([
64
69
$ classMetadataFactory ->getMetadataFor (DogOwner::class),
65
70
$ classMetadataFactory ->getMetadataFor (Dog::class),
66
71
]);
67
- var_dump ($ sql );
72
+
73
+ $ this ->assertContains ('CREATE POLICY dog_policy ON Dog TO dog_owner USING (owner_id = current_user::uuid) ' , $ sql );
74
+ $ this ->assertContains ('GRANT ALL ON TABLE Dog TO dog_owner ' , $ sql );
75
+ $ this ->assertContains ('ALTER TABLE Dog ENABLE ROW LEVEL SECURITY ' , $ sql );
68
76
}
69
77
}
0 commit comments