Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Annotation/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use Attribute;
use Ray\Di\Di\Qualifier;

#[Attribute, Qualifier]
#[Attribute]
#[Qualifier]
final class Cookie
{
}
3 changes: 2 additions & 1 deletion src/Annotation/DeleteCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use Attribute;
use Ray\Di\Di\Qualifier;

#[Attribute, Qualifier]
#[Attribute]
#[Qualifier]
final class DeleteCookie
{
}
6 changes: 2 additions & 4 deletions src/AuraSessionInject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@

use Aura\Session\Session;

/**
* @deprecated Use PHP 8.0: Class constructor property promotion instead
*/
/** @deprecated Use PHP 8.0: Class constructor property promotion instead */
trait AuraSessionInject
{
/** @var Session */
protected $session;

public function setSession(Session $session)
public function setSession(Session $session): void
{
$this->session = $session;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AuraSessionModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class AuraSessionModule extends AbstractModule
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure()
{
Expand Down
3 changes: 2 additions & 1 deletion src/CookieProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
class CookieProvider implements ProviderInterface
{
/**
* {@inheritdoc}
* {@inheritDoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
* @psalm-taint-source input
*/
public function get()
{
Expand Down
5 changes: 1 addition & 4 deletions src/DeleteCookieInvoker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

namespace Ray\AuraSessionModule;

use function setcookie;
use function time;

final class DeleteCookieInvoker
{
/**
Expand All @@ -25,7 +22,7 @@ public function __invoke(string $name, array $params): void
'',
time() - 42000,
$params['path'],
$params['domain']
$params['domain'],
);
}
}
15 changes: 8 additions & 7 deletions src/SessionProvider.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Ray.AuraSessionModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/

namespace Ray\AuraSessionModule;

use Aura\Session\SessionFactory;
use Ray\Di\ProviderInterface;

/**
* @deprecated
*/
/** @deprecated */
class SessionProvider implements ProviderInterface
{
/**
* {@inheritdoc}
* {@inheritDoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
* @psalm-taint-source input
*/
public function get()
{
return (new SessionFactory)->newInstance($_COOKIE);
return (new SessionFactory())->newInstance($_COOKIE);
}
}
30 changes: 30 additions & 0 deletions tests/AuraSessionInjectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Ray\AuraSessionModule;

use Aura\Session\Session;
use PHPUnit\Framework\TestCase;

class FakeSessionConsumer
{
use AuraSessionInject;

public function getSession(): Session
{
return $this->session;
}
}

class AuraSessionInjectTest extends TestCase
{
public function testSetSession(): void
{
$session = $this->createMock(Session::class);
$consumer = new FakeSessionConsumer();
$consumer->setSession($session);

$this->assertSame($session, $consumer->getSession());
}
}
63 changes: 63 additions & 0 deletions tests/DeleteCookieInvokerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace Ray\AuraSessionModule;

use PHPUnit\Framework\TestCase;

/** @var array<int, array{name: string, value: string, expires: int, path: string, domain: string}> */
$setCookieCalls = [];

/**
* Override time function for testing
*/
function time(): int
{
return 1000000;
}

/**
* Override setcookie function for testing
*
* @return bool
*/
function setcookie(string $name, string $value = '', int $expires = 0, string $path = '', string $domain = '')
{
global $setCookieCalls;

$setCookieCalls[] = [
'name' => $name,
'value' => $value,
'expires' => $expires,
'path' => $path,
'domain' => $domain,
];

return true;
}

class DeleteCookieInvokerTest extends TestCase
{
protected function setUp(): void
{
global $setCookieCalls;

$setCookieCalls = [];
}

public function testInvoke(): void
{
global $setCookieCalls;

$invoker = new DeleteCookieInvoker();
$invoker('test_cookie', ['path' => '/app', 'domain' => 'example.com']);

$this->assertCount(1, $setCookieCalls);
$this->assertSame('test_cookie', $setCookieCalls[0]['name']);
$this->assertSame('', $setCookieCalls[0]['value']);
$this->assertSame(1000000 - 42000, $setCookieCalls[0]['expires']);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
$this->assertSame('/app', $setCookieCalls[0]['path']);
$this->assertSame('example.com', $setCookieCalls[0]['domain']);
}
}
18 changes: 18 additions & 0 deletions tests/SessionProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Ray\AuraSessionModule;

use Aura\Session\Session;
use PHPUnit\Framework\TestCase;

class SessionProviderTest extends TestCase
{
public function testGet(): void
{
$provider = new SessionProvider();
$session = $provider->get();
$this->assertInstanceOf(Session::class, $session);
}
}
Loading