-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
206 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoEventLog\migrations; | ||
|
||
use common_ext_ExtensionsManager; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use oat\oatbox\event\EventManager; | ||
use oat\tao\scripts\tools\migrations\AbstractMigration; | ||
use oat\taoEventLog\model\eventLog\LoggerService; | ||
|
||
final class Version202310191436392752_taoEventLog extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Attach DacChangedEvent to LoggerService'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
if ($this->getExtensionsManager()->isEnabled('taoDacSimple')) { | ||
$this->getEventManager()->attach( | ||
'oat\taoDacSimple\model\event\DacChangedEvent', | ||
[LoggerService::class, 'log'] | ||
); | ||
} | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->getEventManager()->detach( | ||
'oat\taoDacSimple\model\event\DacChangedEvent', | ||
[LoggerService::class, 'log'] | ||
); | ||
} | ||
|
||
private function getExtensionsManager(): common_ext_ExtensionsManager | ||
{ | ||
return $this->getServiceLocator()->get(common_ext_ExtensionsManager::SERVICE_ID); | ||
} | ||
|
||
private function getEventManager(): EventManager | ||
{ | ||
return $this->getServiceLocator()->get(EventManager::SERVICE_ID); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,12 @@ | |
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2017 (original work) Open Assessment Technologies SA; | ||
* | ||
* | ||
* Copyright (c) 2017-2023 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
namespace oat\taoEventLog\test\model\requestLog\rds; | ||
|
||
use oat\oatbox\log\LoggerService; | ||
use oat\tao\test\TaoPhpUnitTestRunner; | ||
use oat\taoEventLog\model\eventLog\RdsStorage; | ||
use oat\oatbox\service\ServiceManager; | ||
|
@@ -32,13 +31,11 @@ | |
use oat\taoEventLog\scripts\install\RegisterRdsStorage; | ||
|
||
/** | ||
* Class RdsStorageTest | ||
* @package oat\taoEventLog\test\model\requestLog\rds | ||
* @author Aleh Hutnikau, <[email protected]> | ||
*/ | ||
class RdsStorageTest extends TaoPhpUnitTestRunner | ||
{ | ||
public function testCount() | ||
public function testCount(): void | ||
{ | ||
$storage = $this->getService(); | ||
$this->assertEquals(60, $storage->count()); | ||
|
@@ -49,7 +46,7 @@ public function testCount() | |
$this->assertEquals(11, count($result)); | ||
} | ||
|
||
public function testSearch() | ||
public function testSearch(): void | ||
{ | ||
$storage = $this->getService(); | ||
$this->assertEquals(60, count($storage->search())); | ||
|
@@ -96,10 +93,52 @@ public function testSearch() | |
$this->assertEquals('test_event_10', $result[0][RdsStorage::EVENT_LOG_EVENT_NAME]); | ||
} | ||
|
||
/** | ||
* @return RdsStorage | ||
*/ | ||
protected function getService() | ||
public function testLogMultiple(): void | ||
{ | ||
$storage = $this->getService(); | ||
|
||
$event = $this->createMock(Event::class); | ||
$event->expects($this->any()) | ||
->method('getName') | ||
->willReturn('testEvent'); | ||
|
||
$user = $this->createMock(User::class); | ||
$user->expects($this->any()) | ||
->method('getRoles') | ||
->willReturn([]); | ||
|
||
$entities = [ | ||
new LogEntity( | ||
$event, | ||
'action1', | ||
$user, | ||
new DateTime() | ||
), | ||
new LogEntity( | ||
$event, | ||
'action2', | ||
$user, | ||
new DateTime() | ||
) | ||
]; | ||
|
||
$this->assertTrue($storage->logMultiple(...$entities)); | ||
|
||
$result = $storage->search( | ||
[ | ||
[ | ||
RdsStorage::EVENT_LOG_EVENT_NAME, '=', 'testEvent'] | ||
], | ||
[ | ||
'sort' => RdsStorage::EVENT_LOG_OCCURRED, | ||
'order' => 'ASC' | ||
] | ||
); | ||
|
||
$this->assertEquals(2, count($result)); | ||
} | ||
|
||
private function getService(): RdsStorage | ||
{ | ||
$persistenceManager = $this->getSqlMock('test_eventlog'); | ||
(new RegisterRdsStorage())->createTable($persistenceManager->getPersistenceById('test_eventlog')); | ||
|
@@ -109,20 +148,21 @@ protected function getService() | |
$config = new \common_persistence_KeyValuePersistence([], new \common_persistence_InMemoryKvDriver()); | ||
$config->set(\common_persistence_Manager::SERVICE_ID, $persistenceManager); | ||
$serviceManager = new ServiceManager($config); | ||
$serviceManager->register(LoggerService::SERVICE_ID, $this->createMock(LoggerService::class)); | ||
$storage->setServiceManager($serviceManager); | ||
$this->loadFixtures($storage); | ||
return $storage; | ||
} | ||
|
||
protected function loadFixtures(RdsStorage $storage) | ||
private function loadFixtures(RdsStorage $storage): void | ||
{ | ||
for ($i = 0; $i < 60; $i++) { | ||
$eventProphecy = $this->prophesize(Event::class); | ||
$eventProphecy->getName()->willReturn('test_event_' . $i); | ||
|
||
$userProphecy = $this->prophesize(User::class); | ||
$userProphecy->getIdentifier()->willReturn('test_user_' . $i); | ||
$userProphecy->getRoles()->willReturn(['role_' . (($i % 5) + 1) , 'role_2' . (($i % 5) + 2)]); | ||
$userProphecy->getRoles()->willReturn(['role_' . (($i % 5) + 1), 'role_2' . (($i % 5) + 2)]); | ||
|
||
$logEntity = new LogEntity( | ||
$eventProphecy->reveal(), | ||
|