Skip to content

[HttpFoundation] Handle new tentative return types #41626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(\SessionHandlerInterface $currentHandler, \SessionHa
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
{
$result = $this->currentHandler->close();
Expand All @@ -52,6 +53,7 @@ public function close()
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function destroy($sessionId)
{
$result = $this->currentHandler->destroy($sessionId);
Expand All @@ -63,6 +65,7 @@ public function destroy($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
$result = $this->currentHandler->gc($maxlifetime);
Expand All @@ -74,6 +77,7 @@ public function gc($maxlifetime)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function open($savePath, $sessionName)
{
$result = $this->currentHandler->open($savePath, $sessionName);
Expand All @@ -85,6 +89,7 @@ public function open($savePath, $sessionName)
/**
* @return string
*/
#[\ReturnTypeWillChange]
public function read($sessionId)
{
// No reading from new handler until switch-over
Expand All @@ -94,6 +99,7 @@ public function read($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function write($sessionId, $sessionData)
{
$result = $this->currentHandler->write($sessionId, $sessionData);
Expand All @@ -105,6 +111,7 @@ public function write($sessionId, $sessionData)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function validateId($sessionId)
{
// No reading from new handler until switch-over
Expand All @@ -114,6 +121,7 @@ public function validateId($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $sessionData)
{
$result = $this->currentHandler->updateTimestamp($sessionId, $sessionData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class NullSessionHandler extends AbstractSessionHandler
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
{
return true;
Expand All @@ -29,6 +30,7 @@ public function close()
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function validateId($sessionId)
{
return true;
Expand All @@ -45,6 +47,7 @@ protected function doRead($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
{
return true;
Expand All @@ -69,6 +72,7 @@ protected function doDestroy($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public function isSessionExpired()
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function open($savePath, $sessionName)
{
$this->sessionExpired = false;
Expand All @@ -276,6 +277,7 @@ public function open($savePath, $sessionName)
/**
* @return string
*/
#[\ReturnTypeWillChange]
public function read($sessionId)
{
try {
Expand All @@ -290,6 +292,7 @@ public function read($sessionId)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function gc($maxlifetime)
{
// We delay gc() to close() so that it is executed outside the transactional and blocking read-write process.
Expand Down Expand Up @@ -369,6 +372,7 @@ protected function doWrite($sessionId, $data)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function updateTimestamp($sessionId, $data)
{
$expiry = time() + (int) ini_get('session.gc_maxlifetime');
Expand All @@ -393,6 +397,7 @@ public function updateTimestamp($sessionId, $data)
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
{
$this->commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ public function testGc()
$this->currentHandler->expects($this->once())
->method('gc')
->with($maxlifetime)
->willReturn(true);
->willReturn(1);

$this->writeOnlyHandler->expects($this->once())
->method('gc')
->with($maxlifetime)
->willReturn(false);

$result = $this->dualHandler->gc($maxlifetime);
$this->assertTrue($result);
$this->assertSame(1, $this->dualHandler->gc($maxlifetime));
}

public function testOpen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ public function __construct(string $driverName = null, int $errorMode = null)
$this->errorMode = null !== $errorMode ?: \PDO::ERRMODE_EXCEPTION;
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function getAttribute($attribute)
{
if (\PDO::ATTR_ERRMODE === $attribute) {
Expand All @@ -384,18 +388,24 @@ public function getAttribute($attribute)
return parent::getAttribute($attribute);
}

/**
* @return false|\PDOStatement
*/
#[\ReturnTypeWillChange]
public function prepare($statement, $driverOptions = [])
{
return \is_callable($this->prepareResult)
? ($this->prepareResult)($statement, $driverOptions)
: $this->prepareResult;
}

public function beginTransaction()
public function beginTransaction(): bool
{
return true;
}

public function rollBack()
public function rollBack(): bool
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ public function testGc()
{
$handler = $this->createMock(\SessionHandlerInterface::class);
$handler->expects($this->once())->method('gc')
->with(123)->willReturn(true);
->with(123)->willReturn(1);
$proxy = new StrictSessionHandler($handler);

$this->assertTrue($proxy->gc(123));
$this->assertSame(1, $proxy->gc(123));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public function testCloseFalse()
public function testRead()
{
$this->mock->expects($this->once())
->method('read');
->method('read')
->willReturn('foo')
;

$this->proxy->read('id');
}
Expand All @@ -117,7 +119,9 @@ public function testDestroy()
public function testGc()
{
$this->mock->expects($this->once())
->method('gc');
->method('gc')
->willReturn(1)
;

$this->proxy->gc(86400);
}
Expand Down