mirror of
https://github.com/flarum/core.git
synced 2025-01-17 22:29:15 +01:00
PHP 8 support, cookie unit tests (#2507)
This commit is contained in:
parent
08f72e7135
commit
65b5c2043c
8
.github/workflows/test.yml
vendored
8
.github/workflows/test.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
php: [7.2, 7.3, 7.4]
|
||||
php: [7.2, 7.3, 7.4, '8.0']
|
||||
service: ['mysql:5.7', mariadb]
|
||||
prefix: ['', flarum_]
|
||||
|
||||
@ -33,6 +33,12 @@ jobs:
|
||||
- php: 7.3
|
||||
service: mariadb
|
||||
prefix: flarum_
|
||||
- php: 8.0
|
||||
service: 'mysql:5.7'
|
||||
prefix: flarum_
|
||||
- php: 8.0
|
||||
service: mariadb
|
||||
prefix: flarum_
|
||||
|
||||
services:
|
||||
mysql:
|
||||
|
@ -42,9 +42,9 @@
|
||||
"php": ">=7.2",
|
||||
"axy/sourcemap": "^0.1.4",
|
||||
"components/font-awesome": "^5.14.0",
|
||||
"dflydev/fig-cookies": "^2.0.1",
|
||||
"dflydev/fig-cookies": "^3.0.0",
|
||||
"doctrine/dbal": "^2.7",
|
||||
"franzl/whoops-middleware": "^0.4.0",
|
||||
"franzl/whoops-middleware": "^2.0.0",
|
||||
"illuminate/bus": "^6.0",
|
||||
"illuminate/cache": "^6.0",
|
||||
"illuminate/config": "^6.0",
|
||||
@ -61,14 +61,14 @@
|
||||
"illuminate/validation": "^6.0",
|
||||
"illuminate/view": "^6.0",
|
||||
"intervention/image": "^2.5.0",
|
||||
"laminas/laminas-diactoros": "^1.8.4",
|
||||
"laminas/laminas-httphandlerrunner": "^1.0",
|
||||
"laminas/laminas-stratigility": "^3.0",
|
||||
"laminas/laminas-diactoros": "^2.4.1",
|
||||
"laminas/laminas-httphandlerrunner": "^1.2.0",
|
||||
"laminas/laminas-stratigility": "^3.2.2",
|
||||
"league/flysystem": "^1.0.11",
|
||||
"matthiasmullie/minify": "^1.3",
|
||||
"middlewares/base-path": "^1.1",
|
||||
"middlewares/base-path-router": "^0.2.1",
|
||||
"middlewares/request-handler": "^1.2",
|
||||
"middlewares/base-path": "^2.0.1",
|
||||
"middlewares/base-path-router": "^2.0.1",
|
||||
"middlewares/request-handler": "^2.0.1",
|
||||
"monolog/monolog": "^1.16.0",
|
||||
"nesbot/carbon": "^2.0",
|
||||
"nikic/fast-route": "^0.6",
|
||||
@ -86,8 +86,8 @@
|
||||
"wikimedia/less.php": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.0",
|
||||
"phpunit/phpunit": "^7.0"
|
||||
"mockery/mockery": "^1.3.3",
|
||||
"phpunit/phpunit": "^8.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -77,7 +77,7 @@ class CookieFactory
|
||||
* @param int $maxAge
|
||||
* @return \Dflydev\FigCookies\SetCookie
|
||||
*/
|
||||
public function make($name, $value = null, $maxAge = null)
|
||||
public function make(string $name, string $value = null, int $maxAge = null): SetCookie
|
||||
{
|
||||
$cookie = SetCookie::create($this->getName($name), $value);
|
||||
|
||||
@ -108,7 +108,7 @@ class CookieFactory
|
||||
* @param string $name
|
||||
* @return \Dflydev\FigCookies\SetCookie
|
||||
*/
|
||||
public function expire($name)
|
||||
public function expire(string $name): SetCookie
|
||||
{
|
||||
return $this->make($name)->expire();
|
||||
}
|
||||
@ -119,7 +119,7 @@ class CookieFactory
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function getName($name)
|
||||
public function getName(string $name): string
|
||||
{
|
||||
return $this->prefix.'_'.$name;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class UpdateTest extends TestCase
|
||||
|
||||
// Test for successful response and that the email is included in the response
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertContains('normal@machine.local', (string) $response->getBody());
|
||||
$this->assertStringContainsString('normal@machine.local', (string) $response->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,6 +61,6 @@ class UpdateTest extends TestCase
|
||||
|
||||
// Make sure sensitive information is not made public
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertNotContains('admin@machine.local', (string) $response->getBody());
|
||||
$this->assertStringNotContainsString('admin@machine.local', (string) $response->getBody());
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ class ModelTest extends TestCase
|
||||
$user = User::find(1);
|
||||
|
||||
$this->assertNotEquals([], $user->customRelation()->get()->toArray());
|
||||
$this->assertContains(json_encode(__CLASS__), json_encode($user->customRelation()->get()));
|
||||
$this->assertStringContainsString(json_encode(__CLASS__), json_encode($user->customRelation()->get()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@ class ContainerUtilTest extends TestCase
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
65
tests/unit/Http/CookieFactoryTest.php
Normal file
65
tests/unit/Http/CookieFactoryTest.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\unit\Http;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Foundation\Config;
|
||||
use Flarum\Http\CookieFactory;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
|
||||
class CookieFactoryTest extends TestCase
|
||||
{
|
||||
protected function factory(array $config = null): CookieFactory
|
||||
{
|
||||
$config = new Config(array_merge([
|
||||
'url' => 'http://flarum.test'
|
||||
], $config ?? []));
|
||||
|
||||
return new CookieFactory($config);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function can_create_cookies()
|
||||
{
|
||||
$cookie = $this->factory()->make('test', 'australia');
|
||||
|
||||
$this->assertEquals('flarum_test', $cookie->getName());
|
||||
$this->assertEquals('australia', $cookie->getValue());
|
||||
$this->assertEquals(0, $cookie->getExpires());
|
||||
$this->assertFalse($cookie->getSecure());
|
||||
$this->assertEquals('/', $cookie->getPath());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function can_override_cookie_settings_from_config()
|
||||
{
|
||||
$cookie = $this->factory([
|
||||
'cookie' => [
|
||||
'name' => 'australia',
|
||||
'secure' => true,
|
||||
'domain' => 'flarum.com',
|
||||
'samesite' => 'none'
|
||||
]
|
||||
])->make('test', 'australia');
|
||||
|
||||
$this->assertEquals('australia_test', $cookie->getName());
|
||||
$this->assertTrue($cookie->getSecure());
|
||||
$this->assertEquals('flarum.com', $cookie->getDomain());
|
||||
$this->assertEquals('SameSite=None', $cookie->getSameSite()->asString());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function can_expire_cookies()
|
||||
{
|
||||
$cookie = $this->factory()->expire('test');
|
||||
|
||||
$this->assertLessThan(Carbon::now()->timestamp, $cookie->getExpires());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user