Skip to content
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

PHP 8 support #2507

Merged
merged 29 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
120bb38
php 8 again
luceos Dec 22, 2020
8cc2ac5
8.0 is shortened to 8
luceos Dec 22, 2020
e030daa
update dependencies to allow php 8, figcookies needs replacement
luceos Dec 22, 2020
a7313ec
implement different psr cookie implemnetation
luceos Dec 22, 2020
98bd590
update laminas for php 8
luceos Dec 22, 2020
6feefe7
dropping php 7.2 for now
luceos Dec 22, 2020
43f486b
drop franz whoops middleware
luceos Dec 22, 2020
d51bdc1
update phpunit and mockery
luceos Dec 22, 2020
79ae622
tests completed successfully
luceos Dec 22, 2020
916c241
allow lower laminas diactoros
luceos Dec 22, 2020
5ee879e
allow all laminas to use 7.2
luceos Dec 22, 2020
4d29a49
mockery to allow 7.2
luceos Dec 22, 2020
caba038
add franz/whoops-middleware
luceos Jan 4, 2021
d736b84
Merge branch 'master' into dk/php-8
luceos Jan 13, 2021
264b9a7
local tests green, lets see what gh actions has to say
luceos Jan 13, 2021
9ccf93b
Apply fixes from StyleCI
luceos Jan 13, 2021
700198b
Update composer.json
luceos Jan 15, 2021
d19b9f7
Merge branch 'master' into dk/php-8
luceos Jan 26, 2021
fd9c3c5
fix issue with logging out not unsetting cookie
luceos Jan 26, 2021
2743085
added unit tests for cookie factory
luceos Jan 26, 2021
fe66732
Apply fixes from StyleCI
luceos Jan 26, 2021
ab3d2bb
restore dflydev/fig-cookies
luceos Jan 26, 2021
aedf057
clean up cookie factory
luceos Jan 26, 2021
051f284
wrong restore on http request builder
luceos Jan 26, 2021
92aaeef
add test to verify expiry works
luceos Jan 26, 2021
7d35c79
deduplicate version constraints
luceos Jan 26, 2021
f6cc4fc
allow nullable cookie values again
luceos Jan 26, 2021
6cad3b2
reinstate inheritdoc
luceos Jan 26, 2021
d09b77e
capitalisation in inheritdoc
luceos Jan 26, 2021
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
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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_]

Expand All @@ -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:
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions src/Http/CookieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct(Config $config)
* @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);
askvortsov1 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -108,7 +108,7 @@ public function make($name, $value = null, $maxAge = null)
* @param string $name
* @return \Dflydev\FigCookies\SetCookie
*/
public function expire($name)
public function expire(string $name): SetCookie
{
return $this->make($name)->expire();
}
Expand All @@ -119,7 +119,7 @@ public function expire($name)
* @param string $name
* @return string
*/
public function getName($name)
public function getName(string $name): string
{
return $this->prefix.'_'.$name;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/api/users/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function users_can_see_their_private_information()

// 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());
}

/**
Expand All @@ -61,6 +61,6 @@ public function users_can_not_see_other_users_private_information()

// 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());
}
}
2 changes: 1 addition & 1 deletion tests/integration/extenders/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function custom_relationship_exists_and_can_return_instances_if_added()
$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()));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Foundation/ContainerUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class ContainerUtilTest extends TestCase
private $container;

/**
* @inheritDoc
* @inheritdoc
*/
protected function setUp()
protected function setUp(): void
luceos marked this conversation as resolved.
Show resolved Hide resolved
{
parent::setUp();

Expand Down
65 changes: 65 additions & 0 deletions tests/unit/Http/CookieFactoryTest.php
Original file line number Diff line number Diff line change
@@ -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()
luceos marked this conversation as resolved.
Show resolved Hide resolved
{
$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());
}
}