Laravel components v8 (#2576)

- update actions ci
- include json for 4 spaces tab
- provide output int for process code exit
- adhere to parent type hint of builder
- mailer instance now needs a name, multiple can be instantiated
- getOriginal now uses mutators in the model
- Temporarily loosen MailableInterface requirements. This avoids an immediate BC break for classes in extensions that implement this interface.
- Temporarily provide (and autoload) old symfony translator interface
- make queue exception handler compatible with the contract of L8
- Update phpunit schema for newer version
- Update phpunit assert calls for newer version
This commit is contained in:
Daniël Klabbers 2021-03-05 15:43:35 +01:00 committed by GitHub
parent 725863a6e2
commit 84ded0ce50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 214 additions and 174 deletions

View File

@ -15,5 +15,5 @@ indent_size = 2
[*.{diff,md}]
trim_trailing_whitespace = false
[*.{php,xml}]
[*.{php,xml,json}]
indent_size = 4

View File

@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
php: [7.3, 7.4, '8.0']
service: ['mysql:5.7', mariadb]
prefix: ['', flarum_]
@ -21,12 +21,6 @@ jobs:
prefixStr: (prefix)
exclude:
- php: 7.2
service: 'mysql:5.7'
prefix: flarum_
- php: 7.2
service: mariadb
prefix: flarum_
- php: 7.3
service: 'mysql:5.7'
prefix: flarum_
@ -80,3 +74,5 @@ jobs:
- name: Run Composer tests
run: composer test
env:
COMPOSER_PROCESS_TIMEOUT: 600

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ composer.phar
node_modules
.DS_Store
Thumbs.db
tests/.phpunit.result.cache
/tests/integration/tmp
.vagrant
.idea/*

View File

@ -1,7 +1,10 @@
{
"name": "flarum/core",
"description": "Delightfully simple forum software.",
"keywords": ["forum", "discussion"],
"keywords": [
"forum",
"discussion"
],
"homepage": "https://flarum.org/",
"license": "MIT",
"authors": [
@ -17,27 +20,27 @@
"docs": "https://flarum.org/docs/"
},
"require": {
"php": ">=7.2",
"php": ">=7.3",
"axy/sourcemap": "^0.1.4",
"components/font-awesome": "^5.14.0",
"dflydev/fig-cookies": "^3.0.0",
"doctrine/dbal": "^2.7",
"franzl/whoops-middleware": "^2.0.0",
"illuminate/bus": "^6.0",
"illuminate/cache": "^6.0",
"illuminate/config": "^6.0",
"illuminate/container": "^6.0",
"illuminate/contracts": "^6.0",
"illuminate/database": "^6.0",
"illuminate/events": "^6.0",
"illuminate/filesystem": "^6.0",
"illuminate/hashing": "^6.0",
"illuminate/mail": "^6.0",
"illuminate/queue": "^6.0",
"illuminate/session": "^6.0",
"illuminate/support": "^6.0",
"illuminate/validation": "^6.0",
"illuminate/view": "^6.0",
"illuminate/bus": "^8.0",
"illuminate/cache": "^8.0",
"illuminate/config": "^8.0",
"illuminate/container": "^8.0",
"illuminate/contracts": "^8.0",
"illuminate/database": "^8.0",
"illuminate/events": "^8.0",
"illuminate/filesystem": "^8.0",
"illuminate/hashing": "^8.0",
"illuminate/mail": "^8.0",
"illuminate/queue": "^8.0",
"illuminate/session": "^8.0",
"illuminate/support": "^8.0",
"illuminate/validation": "^8.0",
"illuminate/view": "^8.0",
"intervention/image": "^2.5.0",
"laminas/laminas-diactoros": "^2.4.1",
"laminas/laminas-httphandlerrunner": "^1.2.0",
@ -54,25 +57,26 @@
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"s9e/text-formatter": "^2.3.6",
"symfony/config": "^4.3.4",
"symfony/console": "^4.3.4",
"symfony/event-dispatcher": "^4.3.4",
"symfony/config": "^5.2.2",
"symfony/console": "^5.2.2",
"symfony/event-dispatcher": "^5.2.2",
"symfony/mime": "^5.2.0",
"symfony/translation": "^4.3.4",
"symfony/yaml": "^4.3.4",
"symfony/translation": "^5.1.5",
"symfony/yaml": "^5.2.2",
"tobscure/json-api": "^0.3.0",
"wikimedia/less.php": "^3.0"
},
"require-dev": {
"mockery/mockery": "^1.3.3",
"phpunit/phpunit": "^8.0"
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"Flarum\\": "src/"
},
"files": [
"src/helpers.php"
"src/helpers.php",
"src/TranslatorInterface.php"
]
},
"autoload-dev": {

View File

@ -20,7 +20,7 @@ use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class SendConfirmationEmailController implements RequestHandlerInterface
{

View File

@ -16,7 +16,7 @@ use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class SendTestMailController implements RequestHandlerInterface
{

View File

@ -11,7 +11,7 @@ namespace Flarum\Api\Serializer;
use Flarum\Group\Group;
use InvalidArgumentException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class GroupSerializer extends AbstractSerializer
{

View File

@ -34,7 +34,7 @@ abstract class AbstractCommand extends Command
$this->input = $input;
$this->output = $output;
$this->fire();
return $this->fire() ?: 0;
}
/**

View File

@ -91,7 +91,7 @@ class UserState extends AbstractModel
* @param Builder $query
* @return Builder
*/
protected function setKeysForSaveQuery(Builder $query)
protected function setKeysForSaveQuery($query)
{
$query->where('discussion_id', $this->discussion_id)
->where('user_id', $this->user_id);

View File

@ -18,7 +18,7 @@ use Flarum\User\User;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class Index
{

View File

@ -32,7 +32,7 @@ use Flarum\Settings\Event\Saved;
use Flarum\Settings\Event\Saving;
use Flarum\Settings\SettingsRepositoryInterface;
use Laminas\Stratigility\MiddlewarePipe;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class ForumServiceProvider extends AbstractServiceProvider
{

View File

@ -12,7 +12,7 @@ namespace Flarum\Foundation;
use Illuminate\Support\Arr;
use Illuminate\Validation\Factory;
use Illuminate\Validation\ValidationException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
abstract class AbstractValidator
{

View File

@ -14,7 +14,7 @@ use Illuminate\Contracts\View\Factory as ViewFactory;
use Laminas\Diactoros\Response\HtmlResponse;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* A formatter for turning caught exceptions into "pretty" HTML error pages.

View File

@ -39,7 +39,7 @@ class Permission extends AbstractModel
* @param Builder $query
* @return Builder
*/
protected function setKeysForSaveQuery(Builder $query)
protected function setKeysForSaveQuery($query)
{
$query->where('group_id', $this->group_id)
->where('permission', $this->permission);

View File

@ -15,7 +15,8 @@ use Flarum\Foundation\Paths;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Translation\Translator as TranslatorContract;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Translation\TranslatorInterface as DeprecatedTranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class LocaleServiceProvider extends AbstractServiceProvider
{
@ -62,9 +63,11 @@ class LocaleServiceProvider extends AbstractServiceProvider
return $translator;
});
$this->container->alias('translator', Translator::class);
$this->container->alias('translator', TranslatorContract::class);
$this->container->alias('translator', TranslatorInterface::class);
$this->container->alias('translator', DeprecatedTranslatorInterface::class);
}
private function getDefaultLocale(): string

View File

@ -12,8 +12,9 @@ namespace Flarum\Locale;
use Illuminate\Contracts\Translation\Translator as TranslatorContract;
use Symfony\Component\Translation\MessageCatalogueInterface;
use Symfony\Component\Translation\Translator as BaseTranslator;
use Symfony\Component\Translation\TranslatorInterface; // Defined locally as BC layer
class Translator extends BaseTranslator implements TranslatorContract
class Translator extends BaseTranslator implements TranslatorContract, TranslatorInterface
{
const REFERENCE_REGEX = '/^=>\s*([a-z0-9_\-\.]+)$/i';
@ -84,4 +85,9 @@ class Translator extends BaseTranslator implements TranslatorContract
return $translation;
}
public function setLocale($locale)
{
parent::setLocale($locale);
}
}

View File

@ -63,6 +63,7 @@ class MailServiceProvider extends AbstractServiceProvider
$this->container->singleton('mailer', function ($container) {
$mailer = new Mailer(
'flarum',
$container['view'],
$container['swift.mailer'],
$container['events']

View File

@ -9,7 +9,7 @@
namespace Flarum\Notification;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
interface MailableInterface
{
@ -23,7 +23,11 @@ interface MailableInterface
/**
* Get the subject line for a notification email.
*
* @param TranslatorInterface $translator
*
* @return string
*/
public function getEmailSubject(TranslatorInterface $translator);
// Uncomment beta 17. Commented as temporary BC layer since Symfony changed
// the namespace of their translator interface
// public function getEmailSubject(TranslatorInterface $translator);
}

View File

@ -12,7 +12,7 @@ namespace Flarum\Notification;
use Flarum\User\User;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Mail\Message;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class NotificationMailer
{

View File

@ -12,6 +12,7 @@ namespace Flarum\Queue;
use Exception;
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandling;
use Psr\Log\LoggerInterface;
use Throwable;
class ExceptionHandler implements ExceptionHandling
{
@ -28,10 +29,10 @@ class ExceptionHandler implements ExceptionHandling
/**
* Report or log an exception.
*
* @param \Exception $e
* @param Throwable $e
* @return void
*/
public function report(Exception $e)
public function report(Throwable $e)
{
$this->logger->error((string) $e);
}
@ -40,10 +41,10 @@ class ExceptionHandler implements ExceptionHandling
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @param Throwable $e
* @return \Symfony\Component\HttpFoundation\Response
*/
public function render($request, Exception $e)
public function render($request, Throwable $e)
{
// TODO: Implement render() method.
}
@ -52,10 +53,10 @@ class ExceptionHandler implements ExceptionHandling
* Render an exception to the console.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Exception $e
* @param Throwable $e
* @return void
*/
public function renderForConsole($output, Exception $e)
public function renderForConsole($output, Throwable $e)
{
// TODO: Implement renderForConsole() method.
}
@ -63,10 +64,10 @@ class ExceptionHandler implements ExceptionHandling
/**
* Determine if the exception should be reported.
*
* @param \Exception $e
* @param Throwable $e
* @return bool
*/
public function shouldReport(Exception $e)
public function shouldReport(Throwable $e)
{
return true;
}

View File

@ -0,0 +1,20 @@
<?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 Symfony\Component\Translation;
/**
* @deprecated beta 16, remove beta 17.
* This is here to provide a graceful transition for classes typehinting the old interface.
* Temporarily, `Flarum\Locale\Translator` will implement this to avoid breaking that typehint.
* Before beta 17, this should be removed from autoload.
*/
interface TranslatorInterface
{
}

View File

@ -14,7 +14,7 @@ use Flarum\Mail\Job\SendRawEmailJob;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\Event\Registered;
use Illuminate\Contracts\Queue\Queue;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class AccountActivationMailer
{

View File

@ -49,7 +49,7 @@ class AvatarUploader
*/
protected function removeFileAfterSave(User $user)
{
$avatarPath = $user->getOriginal('avatar_url');
$avatarPath = $user->getRawOriginal('avatar_url');
$user->afterSave(function () use ($avatarPath) {
if ($this->uploadDir->has($avatarPath)) {

View File

@ -18,7 +18,7 @@ use Illuminate\Contracts\Queue\Queue;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class RequestPasswordResetHandler
{

View File

@ -14,7 +14,7 @@ use Flarum\Mail\Job\SendRawEmailJob;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\Event\EmailChangeRequested;
use Illuminate\Contracts\Queue\Queue;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class EmailConfirmationMailer
{

View File

@ -45,7 +45,7 @@ class WithApiKeyTest extends TestCase
$this->request('GET', '/api')
);
$data = json_decode($response->getBody(), true);
$data = json_decode($response->getBody()->getContents(), true);
$this->assertFalse($data['data']['attributes']['canViewUserList']);
}
@ -59,7 +59,7 @@ class WithApiKeyTest extends TestCase
->withAddedHeader('Authorization', 'Token mastertoken; userId=1')
);
$data = json_decode($response->getBody(), true);
$data = json_decode($response->getBody()->getContents(), true);
$this->assertTrue($data['data']['attributes']['canViewUserList']);
$this->assertArrayHasKey('adminUrl', $data['data']['attributes']);
@ -78,7 +78,7 @@ class WithApiKeyTest extends TestCase
->withAddedHeader('Authorization', 'Token personaltoken; userId=1')
);
$data = json_decode($response->getBody(), true);
$data = json_decode($response->getBody()->getContents(), true);
$this->assertTrue($data['data']['attributes']['canViewUserList']);
$this->assertArrayNotHasKey('adminUrl', $data['data']['attributes']);
@ -97,7 +97,7 @@ class WithApiKeyTest extends TestCase
->withAddedHeader('Authorization', 'Token personaltoken')
);
$data = json_decode($response->getBody(), true);
$data = json_decode($response->getBody()->getContents(), true);
$this->assertTrue($data['data']['attributes']['canViewUserList']);
$this->assertArrayNotHasKey('adminUrl', $data['data']['attributes']);

View File

@ -86,7 +86,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -105,7 +105,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -124,7 +124,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -143,7 +143,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1', '2'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['1', '2'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -162,7 +162,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -181,7 +181,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -200,7 +200,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['4'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['4'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -219,7 +219,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1', '2', '3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['1', '2', '3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -241,7 +241,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -263,7 +263,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1', '2'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['1', '2'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -282,7 +282,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -301,7 +301,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -320,7 +320,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -339,7 +339,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1', '2'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['1', '2'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -358,7 +358,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['2', '3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -377,7 +377,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['1'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -396,7 +396,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['4'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['4'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -415,7 +415,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1', '2', '3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['1', '2', '3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -437,7 +437,7 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['3'], Arr::pluck($data, 'id'), 'IDs do not match');
}
/**
@ -459,6 +459,6 @@ class ListTest extends TestCase
$data = json_decode($response->getBody()->getContents(), true)['data'];
// Order-independent comparison
$this->assertEquals(['1', '2'], Arr::pluck($data, 'id'), 'IDs do not match', 0.0, 10, true);
$this->assertEqualsCanonicalizing(['1', '2'], Arr::pluck($data, 'id'), 'IDs do not match');
}
}

View File

@ -75,7 +75,7 @@ class ListTest extends TestCase
}, $data['data']);
// Order-independent comparison
$this->assertEquals(['3'], $ids, 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['3'], $ids, 'IDs do not match');
}
/**
@ -97,7 +97,7 @@ class ListTest extends TestCase
}, $data['data']);
// Order-independent comparison
$this->assertEquals(['3'], $ids, 'IDs do not match', 0.0, 10, true);
$this->assertEquals(['3'], $ids, 'IDs do not match');
}
/**

View File

@ -68,7 +68,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertEquals('dataSerializationPrepCustomTitle', $payload['data']['attributes']['title']);
}
@ -89,7 +89,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(CustomPrepareDataSerializationInvokableClass::class, $payload['data']['attributes']['title']);
}
@ -115,7 +115,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('referenceTest', $payload['data']['relationships']);
}
@ -139,7 +139,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('referenceTest2', $payload['data']['relationships']);
}
@ -164,7 +164,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertEquals('dataSerializationPrepCustomTitle2', $payload['data']['attributes']['title']);
}
@ -193,7 +193,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertEquals('dataSerializationPrepCustomTitle4', $payload['data']['attributes']['title']);
}
@ -218,7 +218,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customSerializer2', $payload['data']['attributes']);
}
@ -247,7 +247,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customSerializer', $payload['data']['attributes']);
}
@ -263,7 +263,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayNotHasKey('customSerializer', $payload['data']['attributes']);
}
@ -284,7 +284,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customSerializer', $payload['data']['attributes']);
}
@ -310,7 +310,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customSerializer', $payload['data']['attributes']);
}
@ -333,7 +333,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayNotHasKey('customSerializer', $payload['data']['attributes']);
}
@ -349,7 +349,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayNotHasKey('customApiControllerRelation', $payload['data']['relationships']);
$this->assertArrayNotHasKey('customApiControllerRelation2', $payload['data']['relationships']);
@ -375,7 +375,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customApiControllerRelation', $payload['data']['relationships']);
}
@ -402,7 +402,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customApiControllerRelation2', $payload['data']['relationships']);
}
@ -418,7 +418,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('groups', $payload['data']['relationships']);
}
@ -439,7 +439,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayNotHasKey('groups', Arr::get($payload, 'data.relationships', []));
}
@ -481,7 +481,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertCount(3, $payload['data']);
}
@ -502,7 +502,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertCount(1, $payload['data']);
}
@ -525,7 +525,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertCount(1, $payload['data']);
}
@ -587,7 +587,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals([3, 1, 2], Arr::pluck($payload['data'], 'id'));
@ -647,7 +647,7 @@ class ApiControllerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals([2, 1, 3], Arr::pluck($payload['data'], 'id'));

View File

@ -62,7 +62,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayNotHasKey('customAttribute', $payload['data']['attributes']);
}
@ -89,7 +89,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customAttribute', $payload['data']['attributes']);
}
@ -112,7 +112,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customAttributeFromInvokable', $payload['data']['attributes']);
}
@ -139,7 +139,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customAttribute', $payload['data']['attributes']);
}
@ -172,7 +172,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customAttribute', $payload['data']['attributes']);
$this->assertEquals('newValue', $payload['data']['attributes']['customAttribute']);
@ -200,7 +200,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customSingleAttribute', $payload['data']['attributes']);
$this->assertArrayHasKey('customSingleAttribute_0', $payload['data']['attributes']);
@ -225,7 +225,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customSingleAttribute_1', $payload['data']['attributes']);
}
@ -250,7 +250,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customSingleAttribute_2', $payload['data']['attributes']);
}
@ -279,7 +279,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customSingleAttribute_3', $payload['data']['attributes']);
$this->assertEquals('newValue', $payload['data']['attributes']['customSingleAttribute_3']);
@ -312,7 +312,7 @@ class ApiSerializerTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('someCustomAttribute', $payload['data']['attributes']);
$this->assertEquals('newValue', $payload['data']['attributes']['someCustomAttribute']);

View File

@ -18,7 +18,7 @@ use Flarum\Tests\integration\TestCase;
use Flarum\User\User;
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
use Illuminate\Contracts\Events\Dispatcher;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class EventTest extends TestCase
{

View File

@ -60,8 +60,8 @@ class FilterTest extends TestCase
$this->prepDb();
$searchForAll = json_encode($this->filterDiscussions([], 5));
$this->assertContains('DISCUSSION 1', $searchForAll);
$this->assertContains('DISCUSSION 2', $searchForAll);
$this->assertStringContainsString('DISCUSSION 1', $searchForAll);
$this->assertStringContainsString('DISCUSSION 2', $searchForAll);
}
/**
@ -74,8 +74,8 @@ class FilterTest extends TestCase
$this->prepDb();
$withResultSearch = json_encode($this->filterDiscussions(['noResult' => 0], 5));
$this->assertContains('DISCUSSION 1', $withResultSearch);
$this->assertContains('DISCUSSION 2', $withResultSearch);
$this->assertStringContainsString('DISCUSSION 1', $withResultSearch);
$this->assertStringContainsString('DISCUSSION 2', $withResultSearch);
$this->assertEquals([], $this->filterDiscussions(['noResult' => 1], 5));
}

View File

@ -34,7 +34,7 @@ class MailTest extends TestCase
])
);
$fields = json_decode($response->getBody(), true)['data']['attributes']['fields'];
$fields = json_decode($response->getBody()->getContents(), true)['data']['attributes']['fields'];
// The custom driver does not exist
$this->assertArrayNotHasKey('custom', $fields);
@ -65,7 +65,7 @@ class MailTest extends TestCase
])
);
$fields = json_decode($response->getBody(), true)['data']['attributes']['fields'];
$fields = json_decode($response->getBody()->getContents(), true)['data']['attributes']['fields'];
$this->assertArrayHasKey('custom', $fields);
$this->assertEquals(['customSetting1' => ''], $fields['custom']);
@ -87,7 +87,7 @@ class MailTest extends TestCase
])
);
$requiredFields = json_decode($response->getBody(), true)['data']['attributes']['fields']['smtp'];
$requiredFields = json_decode($response->getBody()->getContents(), true)['data']['attributes']['fields']['smtp'];
$this->assertEquals(['customSetting1' => ''], $requiredFields);
}

View File

@ -50,7 +50,7 @@ class SettingsTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayNotHasKey('customPrefix.customSetting', $payload['data']['attributes']);
}
@ -73,7 +73,7 @@ class SettingsTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customPrefix.customSetting', $payload['data']['attributes']);
$this->assertEquals('customValue', $payload['data']['attributes']['customPrefix.customSetting']);
@ -99,7 +99,7 @@ class SettingsTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customPrefix.customSetting', $payload['data']['attributes']);
$this->assertEquals('customValueModified', $payload['data']['attributes']['customPrefix.customSetting']);
@ -123,7 +123,7 @@ class SettingsTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customPrefix.customSetting2', $payload['data']['attributes']);
$this->assertEquals('customValueModifiedByInvokable', $payload['data']['attributes']['customPrefix.customSetting2']);
@ -147,7 +147,7 @@ class SettingsTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customPrefix.noCustomSetting', $payload['data']['attributes']);
$this->assertEquals('customDefault', $payload['data']['attributes']['customPrefix.noCustomSetting']);
@ -173,7 +173,7 @@ class SettingsTest extends TestCase
])
);
$payload = json_decode($response->getBody(), true);
$payload = json_decode($response->getBody()->getContents(), true);
$this->assertArrayHasKey('customPrefix.noCustomSetting', $payload['data']['attributes']);
$this->assertEquals('customDefaultModified2', $payload['data']['attributes']['customPrefix.noCustomSetting']);

View File

@ -77,12 +77,12 @@ class SimpleFlarumSearchTest extends TestCase
$this->prepDb();
$searchForAll = json_encode($this->searchDiscussions('in text', 5));
$this->assertContains('DISCUSSION 1', $searchForAll);
$this->assertContains('DISCUSSION 2', $searchForAll);
$this->assertStringContainsString('DISCUSSION 1', $searchForAll);
$this->assertStringContainsString('DISCUSSION 2', $searchForAll);
$searchForSecond = json_encode($this->searchDiscussions('lightsail', 5));
$this->assertNotContains('DISCUSSION 1', $searchForSecond);
$this->assertContains('DISCUSSION 2', $searchForSecond);
$this->assertStringNotContainsString('DISCUSSION 1', $searchForSecond);
$this->assertStringContainsString('DISCUSSION 2', $searchForSecond);
}
/**
@ -105,8 +105,8 @@ class SimpleFlarumSearchTest extends TestCase
$this->prepDb();
$withResultSearch = json_encode($this->searchDiscussions('noResult:0', 5));
$this->assertContains('DISCUSSION 1', $withResultSearch);
$this->assertContains('DISCUSSION 2', $withResultSearch);
$this->assertStringContainsString('DISCUSSION 1', $withResultSearch);
$this->assertStringContainsString('DISCUSSION 2', $withResultSearch);
$this->assertEquals('[]', json_encode($this->searchDiscussions('noResult:1', 5)));
}

View File

@ -1,22 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Flarum Integration Tests">
<directory suffix="Test.php">./integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -1,25 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Flarum Unit Tests">
<directory suffix="Test.php">./unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener"></listener>
<listener class="\Mockery\Adapter\Phpunit\TestListener" />
</listeners>
</phpunit>

View File

@ -41,7 +41,7 @@ class WritablePathsTest extends TestCase
$problems = $writable->problems();
$this->assertCount(1, $problems);
$this->assertRegExp(
$this->assertMatchesRegularExpression(
"%^The .+/tests/fixtures/writable_paths/missing directory doesn't exist$%",
$problems[0]['message']
);
@ -59,7 +59,7 @@ class WritablePathsTest extends TestCase
$problems = $writable->problems();
$this->assertCount(1, $problems);
$this->assertRegExp(
$this->assertMatchesRegularExpression(
"%^The .+/tests/fixtures/writable_paths/missing directory doesn't exist$%",
$problems[0]['message']
);

View File

@ -56,7 +56,7 @@ class AvatarUploaderTest extends TestCase
}
$user->syncOriginal();
$this->assertEquals(null, $user->getOriginal('avatar_url'));
$this->assertEquals(null, $user->getRawOriginal('avatar_url'));
}
public function test_removing_url_avatar_removes_no_file()
@ -76,7 +76,7 @@ class AvatarUploaderTest extends TestCase
}
$user->syncOriginal();
$this->assertEquals(null, $user->getOriginal('avatar_url'));
$this->assertEquals(null, $user->getRawOriginal('avatar_url'));
}
public function test_changing_avatar_removes_file()
@ -97,6 +97,6 @@ class AvatarUploaderTest extends TestCase
}
$user->syncOriginal();
$this->assertNotEquals('ABCDEFGHabcdefgh.png', $user->getOriginal('avatar_url'));
$this->assertNotEquals('ABCDEFGHabcdefgh.png', $user->getRawOriginal('avatar_url'));
}
}