Skip to content

Commit

Permalink
Increase PHPStan level
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Jan 5, 2025
1 parent ff64b4e commit e4f3f1e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
1 change: 1 addition & 0 deletions http-kernel-fixtures/sub-folder/cookie_page1.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/** @var \Symfony\Component\HttpFoundation\Request $request */
$requestUri = $request->server->get('REQUEST_URI');
assert(is_string($requestUri));
$resp = new Symfony\Component\HttpFoundation\Response();
$cook = Symfony\Component\HttpFoundation\Cookie::create('srvr_cookie', 'srv_var_is_set_sub_folder', 0, dirname($requestUri));
$resp->headers->setCookie($cook);
Expand Down
5 changes: 4 additions & 1 deletion http-kernel-fixtures/sub-folder/cookie_page4.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
/** @var \Symfony\Component\HttpFoundation\Request $request */
$resp = new Symfony\Component\HttpFoundation\Response();
$cookiePath = dirname($request->server->get('REQUEST_URI')) . '/';
$requestUri = $request->server->get('REQUEST_URI');
assert(is_string($requestUri));
$cookiePath = dirname($requestUri) . '/';
assert(is_string($cookiePath));
$cookie = Symfony\Component\HttpFoundation\Cookie::create('srvr_cookie', 'srv_var_is_set', 0, $cookiePath);
$resp->headers->setCookie($cookie);
?>
Expand Down
2 changes: 1 addition & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 8
level: 9
paths:
- src
- tests
Expand Down
2 changes: 1 addition & 1 deletion tests/Form/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function testSubmitEmptyTextarea(): void
/**
* @dataProvider provideInvalidValues
*
* @param mixed $value
* @param array<array-key, mixed>|bool|string $value
*/
public function testSetInvalidValueInField(string $field, $value): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Form/Html5Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function testHtml5FormMethod(): void
/**
* @dataProvider provideInvalidValues
*
* @param mixed $value
* @param array<array-key, mixed>|bool|string $value
*/
public function testSetInvalidValueInField(string $field, $value): void
{
Expand Down
48 changes: 28 additions & 20 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@

abstract class TestCase extends BaseTestCase
{
private const DRIVER_CONFIG_FACTORY_KEY = 'driver_config_factory';
private const MINK_SESSION_KEY = 'sess';

/**
* Mink session manager.
*
* @var Mink
* @var Mink|null
*/
private static $mink;
private static $mink = null;

/**
* @var AbstractConfig
* @var AbstractConfig|null
*/
private static $config;
private static $config = null;

/**
* @beforeClass
Expand All @@ -32,26 +35,29 @@ public static function prepareSession()
{
if (null === self::$mink) {
$session = new Session(self::getConfig()->createDriver());
self::$mink = new Mink(['sess' => $session]);
self::$mink = new Mink([self::MINK_SESSION_KEY => $session]);
}
}

/**
* @return AbstractConfig
*
* @throws \UnexpectedValueException if the global driver_config_factory returns an invalid object
* @throws \UnexpectedValueException
*/
private static function getConfig(): AbstractConfig
private static function createConfig(): AbstractConfig
{
if (null === self::$config) {
self::$config = call_user_func($GLOBALS['driver_config_factory']);

if (!self::$config instanceof AbstractConfig) {
throw new \UnexpectedValueException('The "driver_config_factory" global variable must return a \Behat\Mink\Tests\Driver\AbstractConfig.');
}
$config = call_user_func($GLOBALS[self::DRIVER_CONFIG_FACTORY_KEY]);
if (!$config instanceof AbstractConfig) {
throw new \UnexpectedValueException(sprintf(
'The "%s" global variable must return a %s.',
self::DRIVER_CONFIG_FACTORY_KEY,
AbstractConfig::class
));
}
return $config;
}

return self::$config;
private static function getConfig(): AbstractConfig
{
return self::$config ?? (self::$config = self::createConfig());
}

/**
Expand Down Expand Up @@ -84,7 +90,8 @@ protected function resetSessions()
*/
protected function getSession()
{
return self::$mink->getSession('sess');
assert(self::$mink !== null);
return self::$mink->getSession(self::MINK_SESSION_KEY);
}

/**
Expand All @@ -94,7 +101,8 @@ protected function getSession()
*/
protected function getAssertSession()
{
return self::$mink->assertSession('sess');
assert(self::$mink !== null);
return self::$mink->assertSession(self::MINK_SESSION_KEY);
}

/**
Expand Down Expand Up @@ -145,13 +153,13 @@ protected function mapRemoteFilePath($file)
*/
protected function pathTo($path)
{
return rtrim(self::getConfig()->getWebFixturesUrl(), '/').'/'.ltrim($path, '/');
return rtrim(self::getConfig()->getWebFixturesUrl(), '/') . '/' . ltrim($path, '/');
}

/**
* Waits for a condition to be true, considering than it is successful for drivers not supporting wait().
*
* @param int $time
* @param int $time
* @param string $condition A JS condition to evaluate
*
* @return bool
Expand Down

0 comments on commit e4f3f1e

Please sign in to comment.