-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist device and platform in NoSQL database (#635)
- Loading branch information
Showing
6 changed files
with
108 additions
and
13 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
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
60 changes: 60 additions & 0 deletions
60
tests/Unit/EventListener/Audit/AbstractAuditListenerTest.php
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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Unit\EventListener\Audit; | ||
|
||
use App\EventListener\Audit\AbstractAuditListener; | ||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
final class AbstractAuditListenerTest extends KernelTestCase | ||
{ | ||
public const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'; | ||
|
||
private AbstractAuditListener $auditListener; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$requestStack = $this->createMock(RequestStack::class); | ||
$requestStack->expects(self::once()) | ||
->method('getCurrentRequest') | ||
->willReturn( | ||
new Request(server: [ | ||
'HTTP_USER_AGENT' => self::USER_AGENT, | ||
]) | ||
); | ||
|
||
$documentManager = $this->createMock(DocumentManager::class); | ||
$security = $this->createMock(Security::class); | ||
|
||
$auditListenerConcrete = new class ($documentManager, $requestStack, $security) extends AbstractAuditListener { | ||
public function getDevice(): string | ||
{ | ||
return parent::getDevice(); | ||
} | ||
|
||
public function getPlatform(): string | ||
{ | ||
return parent::getPlatform(); | ||
} | ||
}; | ||
|
||
$this->auditListener = new $auditListenerConcrete($documentManager, $requestStack, $security); | ||
} | ||
|
||
public function testGetDevice(): void | ||
{ | ||
$this->assertSame('Chrome', $this->auditListener->getDevice()); | ||
} | ||
|
||
public function testGetPlatform(): void | ||
{ | ||
$this->assertSame('Windows', $this->auditListener->getPlatform()); | ||
} | ||
} |