composeer update

This commit is contained in:
2019-06-23 11:49:01 +00:00
parent fc2380d68c
commit e9efe70112
327 changed files with 5194 additions and 2278 deletions

View File

@@ -97,7 +97,9 @@ class JsonDescriptor extends Descriptor
*/
private function writeData(array $data, array $options)
{
$this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
$this->write(json_encode($data, $flags));
}
/**

View File

@@ -187,7 +187,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
$unsetCodes = [];
if (null === $this->handlesHrefGracefully) {
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') && !getenv('KONSOLE_VERSION');
}
if (null !== $this->foreground) {

View File

@@ -709,7 +709,7 @@ class ApplicationTest extends TestCase
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(['getNamespaces'])->getMock();
$application->expects($this->once())
->method('getNamespaces')
->will($this->returnValue(['foo:sublong', 'bar:sub']));
->willReturn(['foo:sublong', 'bar:sub']);
$this->assertEquals('foo:sublong', $application->findNamespace('f:sub'));
}
@@ -853,7 +853,7 @@ class ApplicationTest extends TestCase
$application->setAutoExit(false);
$application->expects($this->any())
->method('getTerminalWidth')
->will($this->returnValue(120));
->willReturn(120);
$application->register('foo')->setCode(function () {
throw new \InvalidArgumentException("\n\nline 1 with extra spaces \nline 2\n\nline 4\n");
});

View File

@@ -321,7 +321,7 @@ class CommandTest extends TestCase
$command = $this->getMockBuilder('TestCommand')->setMethods(['execute'])->getMock();
$command->expects($this->once())
->method('execute')
->will($this->returnValue('2.3'));
->willReturn('2.3');
$exitCode = $command->run(new StringInput(''), new NullOutput());
$this->assertSame(2, $exitCode, '->run() returns integer exit code (casts numeric to int)');
}

View File

@@ -21,7 +21,7 @@ abstract class AbstractQuestionHelperTest extends TestCase
$mock = $this->getMockBuilder(StreamableInputInterface::class)->getMock();
$mock->expects($this->any())
->method('isInteractive')
->will($this->returnValue($interactive));
->willReturn($interactive);
if ($stream) {
$mock->expects($this->any())

View File

@@ -114,7 +114,7 @@ class HelperSetTest extends TestCase
$mock_helper = $this->getMockBuilder('\Symfony\Component\Console\Helper\HelperInterface')->getMock();
$mock_helper->expects($this->any())
->method('getName')
->will($this->returnValue($name));
->willReturn($name);
if ($helperset) {
$mock_helper->expects($this->any())

View File

@@ -760,7 +760,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
$mock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$mock->expects($this->any())
->method('isInteractive')
->will($this->returnValue($interactive));
->willReturn($interactive);
return $mock;
}

View File

@@ -154,7 +154,7 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
$mock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
$mock->expects($this->any())
->method('isInteractive')
->will($this->returnValue($interactive));
->willReturn($interactive);
return $mock;
}

View File

@@ -166,7 +166,7 @@ class ConsoleLoggerTest extends TestCase
} else {
$dummy = $this->getMock('Symfony\Component\Console\Tests\Logger\DummyTest', ['__toString']);
}
$dummy->method('__toString')->will($this->returnValue('DUMMY'));
$dummy->method('__toString')->willReturn('DUMMY');
$this->getLogger()->warning($dummy);

View File

@@ -234,7 +234,7 @@ class ErrorHandlerTest extends TestCase
$logger
->expects($this->once())
->method('log')
->will($this->returnCallback($warnArgCheck))
->willReturnCallback($warnArgCheck)
;
$handler = ErrorHandler::register();
@@ -262,7 +262,7 @@ class ErrorHandlerTest extends TestCase
$logger
->expects($this->once())
->method('log')
->will($this->returnCallback($logArgCheck))
->willReturnCallback($logArgCheck)
;
$handler = ErrorHandler::register();
@@ -318,7 +318,7 @@ class ErrorHandlerTest extends TestCase
$logger
->expects($this->once())
->method('log')
->will($this->returnCallback($logArgCheck))
->willReturnCallback($logArgCheck)
;
$handler = new ErrorHandler();
@@ -346,7 +346,7 @@ class ErrorHandlerTest extends TestCase
$logger
->expects($this->exactly(2))
->method('log')
->will($this->returnCallback($logArgCheck))
->willReturnCallback($logArgCheck)
;
$handler->setDefaultLogger($logger, E_ERROR);
@@ -462,7 +462,7 @@ class ErrorHandlerTest extends TestCase
$logger
->expects($this->once())
->method('log')
->will($this->returnCallback($logArgCheck))
->willReturnCallback($logArgCheck)
;
$handler->setDefaultLogger($logger, E_PARSE);

View File

@@ -23,7 +23,7 @@ if (interface_exists(PsrEventDispatcherInterface::class)) {
* Dispatches an event to all registered listeners.
*
* For BC with Symfony 4, the $eventName argument is not declared explicitly on the
* signature of the method. Implementations that are not bound by this BC contraint
* signature of the method. Implementations that are not bound by this BC constraint
* MUST declare it explicitly, as allowed by PHP.
*
* @param object $event The event to pass to the event handlers/listeners
@@ -44,7 +44,7 @@ if (interface_exists(PsrEventDispatcherInterface::class)) {
* Dispatches an event to all registered listeners.
*
* For BC with Symfony 4, the $eventName argument is not declared explicitly on the
* signature of the method. Implementations that are not bound by this BC contraint
* signature of the method. Implementations that are not bound by this BC constraint
* MUST declare it explicitly, as allowed by PHP.
*
* @param object $event The event to pass to the event handlers/listeners

View File

@@ -43,7 +43,7 @@ class ImmutableEventDispatcherTest extends TestCase
$this->innerDispatcher->expects($this->once())
->method('dispatch')
->with($event, 'event')
->will($this->returnValue('result'));
->willReturn('result');
$this->assertSame('result', $this->dispatcher->dispatch($event, 'event'));
}
@@ -53,7 +53,7 @@ class ImmutableEventDispatcherTest extends TestCase
$this->innerDispatcher->expects($this->once())
->method('getListeners')
->with('event')
->will($this->returnValue('result'));
->willReturn('result');
$this->assertSame('result', $this->dispatcher->getListeners('event'));
}
@@ -63,7 +63,7 @@ class ImmutableEventDispatcherTest extends TestCase
$this->innerDispatcher->expects($this->once())
->method('hasListeners')
->with('event')
->will($this->returnValue('result'));
->willReturn('result');
$this->assertSame('result', $this->dispatcher->hasListeners('event'));
}

View File

@@ -148,6 +148,10 @@ class JsonResponse extends Response
throw $e;
}
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $this->encodingOptions)) {
return $this->setJson($data);
}
if (JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(json_last_error_msg());
}

View File

@@ -42,7 +42,7 @@ class RedirectResponse extends Response
throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
}
if (301 == $status && !\array_key_exists('cache-control', $headers)) {
if (301 == $status && !\array_key_exists('cache-control', array_change_key_case($headers, \CASE_LOWER))) {
$this->headers->remove('cache-control');
}
}

View File

@@ -91,6 +91,10 @@ class RedirectResponseTest extends TestCase
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
$this->assertTrue($response->headers->hasCacheControlDirective('max-age'));
$response = new RedirectResponse('foo.bar', 301, ['Cache-Control' => 'max-age=86400']);
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
$this->assertTrue($response->headers->hasCacheControlDirective('max-age'));
$response = new RedirectResponse('foo.bar', 302);
$this->assertTrue($response->headers->hasCacheControlDirective('no-cache'));
}

View File

@@ -62,7 +62,7 @@ class MemcachedSessionHandlerTest extends TestCase
$this->memcached
->expects($this->once())
->method('quit')
->will($this->returnValue(true))
->willReturn(true)
;
$this->assertTrue($this->storage->close());
@@ -85,7 +85,7 @@ class MemcachedSessionHandlerTest extends TestCase
->expects($this->once())
->method('set')
->with(self::PREFIX.'id', 'data', $this->equalTo(time() + self::TTL, 2))
->will($this->returnValue(true))
->willReturn(true)
;
$this->assertTrue($this->storage->write('id', 'data'));
@@ -97,7 +97,7 @@ class MemcachedSessionHandlerTest extends TestCase
->expects($this->once())
->method('delete')
->with(self::PREFIX.'id')
->will($this->returnValue(true))
->willReturn(true)
;
$this->assertTrue($this->storage->destroy('id'));

View File

@@ -38,11 +38,11 @@ class MigratingSessionHandlerTest extends TestCase
{
$this->currentHandler->expects($this->once())
->method('close')
->will($this->returnValue(true));
->willReturn(true);
$this->writeOnlyHandler->expects($this->once())
->method('close')
->will($this->returnValue(false));
->willReturn(false);
$result = $this->dualHandler->close();
@@ -56,12 +56,12 @@ class MigratingSessionHandlerTest extends TestCase
$this->currentHandler->expects($this->once())
->method('destroy')
->with($sessionId)
->will($this->returnValue(true));
->willReturn(true);
$this->writeOnlyHandler->expects($this->once())
->method('destroy')
->with($sessionId)
->will($this->returnValue(false));
->willReturn(false);
$result = $this->dualHandler->destroy($sessionId);
@@ -75,12 +75,12 @@ class MigratingSessionHandlerTest extends TestCase
$this->currentHandler->expects($this->once())
->method('gc')
->with($maxlifetime)
->will($this->returnValue(true));
->willReturn(true);
$this->writeOnlyHandler->expects($this->once())
->method('gc')
->with($maxlifetime)
->will($this->returnValue(false));
->willReturn(false);
$result = $this->dualHandler->gc($maxlifetime);
$this->assertTrue($result);
@@ -94,12 +94,12 @@ class MigratingSessionHandlerTest extends TestCase
$this->currentHandler->expects($this->once())
->method('open')
->with($savePath, $sessionName)
->will($this->returnValue(true));
->willReturn(true);
$this->writeOnlyHandler->expects($this->once())
->method('open')
->with($savePath, $sessionName)
->will($this->returnValue(false));
->willReturn(false);
$result = $this->dualHandler->open($savePath, $sessionName);
@@ -114,7 +114,7 @@ class MigratingSessionHandlerTest extends TestCase
$this->currentHandler->expects($this->once())
->method('read')
->with($sessionId)
->will($this->returnValue($readValue));
->willReturn($readValue);
$this->writeOnlyHandler->expects($this->never())
->method('read')
@@ -133,12 +133,12 @@ class MigratingSessionHandlerTest extends TestCase
$this->currentHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(true));
->willReturn(true);
$this->writeOnlyHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(false));
->willReturn(false);
$result = $this->dualHandler->write($sessionId, $data);
@@ -153,7 +153,7 @@ class MigratingSessionHandlerTest extends TestCase
$this->currentHandler->expects($this->once())
->method('read')
->with($sessionId)
->will($this->returnValue($readValue));
->willReturn($readValue);
$this->writeOnlyHandler->expects($this->never())
->method('read')
@@ -172,12 +172,12 @@ class MigratingSessionHandlerTest extends TestCase
$this->currentHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(true));
->willReturn(true);
$this->writeOnlyHandler->expects($this->once())
->method('write')
->with($sessionId, $data)
->will($this->returnValue(false));
->willReturn(false);
$result = $this->dualHandler->updateTimestamp($sessionId, $data);

View File

@@ -77,7 +77,7 @@ class MongoDbSessionHandlerTest extends TestCase
$this->mongo->expects($this->once())
->method('selectCollection')
->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection));
->willReturn($collection);
// defining the timeout before the actual method call
// allows to test for "greater than" values in the $criteria
@@ -85,7 +85,7 @@ class MongoDbSessionHandlerTest extends TestCase
$collection->expects($this->once())
->method('findOne')
->will($this->returnCallback(function ($criteria) use ($testTimeout) {
->willReturnCallback(function ($criteria) use ($testTimeout) {
$this->assertArrayHasKey($this->options['id_field'], $criteria);
$this->assertEquals($criteria[$this->options['id_field']], 'foo');
@@ -100,7 +100,7 @@ class MongoDbSessionHandlerTest extends TestCase
$this->options['expiry_field'] => new \MongoDB\BSON\UTCDateTime(),
$this->options['data_field'] => new \MongoDB\BSON\Binary('bar', \MongoDB\BSON\Binary::TYPE_OLD_BINARY),
];
}));
});
$this->assertEquals('bar', $this->storage->read('foo'));
}
@@ -112,11 +112,11 @@ class MongoDbSessionHandlerTest extends TestCase
$this->mongo->expects($this->once())
->method('selectCollection')
->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection));
->willReturn($collection);
$collection->expects($this->once())
->method('updateOne')
->will($this->returnCallback(function ($criteria, $updateData, $options) {
->willReturnCallback(function ($criteria, $updateData, $options) {
$this->assertEquals([$this->options['id_field'] => 'foo'], $criteria);
$this->assertEquals(['upsert' => true], $options);
@@ -127,7 +127,7 @@ class MongoDbSessionHandlerTest extends TestCase
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $data[$this->options['time_field']]);
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $data[$this->options['expiry_field']]);
$this->assertGreaterThanOrEqual($expectedExpiry, round((string) $data[$this->options['expiry_field']] / 1000));
}));
});
$this->assertTrue($this->storage->write('foo', 'bar'));
}
@@ -139,15 +139,15 @@ class MongoDbSessionHandlerTest extends TestCase
$this->mongo->expects($this->once())
->method('selectCollection')
->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection));
->willReturn($collection);
$data = [];
$collection->expects($this->exactly(2))
->method('updateOne')
->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) {
->willReturnCallback(function ($criteria, $updateData, $options) use (&$data) {
$data = $updateData;
}));
});
$this->storage->write('foo', 'bar');
$this->storage->write('foo', 'foobar');
@@ -162,7 +162,7 @@ class MongoDbSessionHandlerTest extends TestCase
$this->mongo->expects($this->once())
->method('selectCollection')
->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection));
->willReturn($collection);
$collection->expects($this->once())
->method('deleteOne')
@@ -178,14 +178,14 @@ class MongoDbSessionHandlerTest extends TestCase
$this->mongo->expects($this->once())
->method('selectCollection')
->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection));
->willReturn($collection);
$collection->expects($this->once())
->method('deleteMany')
->will($this->returnCallback(function ($criteria) {
->willReturnCallback(function ($criteria) {
$this->assertInstanceOf(\MongoDB\BSON\UTCDateTime::class, $criteria[$this->options['expiry_field']]['$lt']);
$this->assertGreaterThanOrEqual(time() - 1, round((string) $criteria[$this->options['expiry_field']]['$lt'] / 1000));
}));
});
$this->assertTrue($this->storage->gc(1));
}

View File

@@ -143,7 +143,7 @@ class PdoSessionHandlerTest extends TestCase
$stream = $this->createStream($content);
$pdo->prepareResult->expects($this->once())->method('fetchAll')
->will($this->returnValue([[$stream, 42, time()]]));
->willReturn([[$stream, 42, time()]]);
$storage = new PdoSessionHandler($pdo);
$result = $storage->read('foo');
@@ -170,14 +170,14 @@ class PdoSessionHandlerTest extends TestCase
$exception = null;
$selectStmt->expects($this->atLeast(2))->method('fetchAll')
->will($this->returnCallback(function () use (&$exception, $stream) {
->willReturnCallback(function () use (&$exception, $stream) {
return $exception ? [[$stream, 42, time()]] : [];
}));
});
$insertStmt->expects($this->once())->method('execute')
->will($this->returnCallback(function () use (&$exception) {
->willReturnCallback(function () use (&$exception) {
throw $exception = new \PDOException('', '23');
}));
});
$storage = new PdoSessionHandler($pdo);
$result = $storage->read('foo');

View File

@@ -50,7 +50,7 @@ class SessionHandlerProxyTest extends TestCase
{
$this->mock->expects($this->once())
->method('open')
->will($this->returnValue(true));
->willReturn(true);
$this->assertFalse($this->proxy->isActive());
$this->proxy->open('name', 'id');
@@ -61,7 +61,7 @@ class SessionHandlerProxyTest extends TestCase
{
$this->mock->expects($this->once())
->method('open')
->will($this->returnValue(false));
->willReturn(false);
$this->assertFalse($this->proxy->isActive());
$this->proxy->open('name', 'id');
@@ -72,7 +72,7 @@ class SessionHandlerProxyTest extends TestCase
{
$this->mock->expects($this->once())
->method('close')
->will($this->returnValue(true));
->willReturn(true);
$this->assertFalse($this->proxy->isActive());
$this->proxy->close();
@@ -83,7 +83,7 @@ class SessionHandlerProxyTest extends TestCase
{
$this->mock->expects($this->once())
->method('close')
->will($this->returnValue(false));
->willReturn(false);
$this->assertFalse($this->proxy->isActive());
$this->proxy->close();

View File

@@ -11,8 +11,191 @@
namespace Symfony\Component\HttpKernel;
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.3, use "%s" instead.', Client::class, HttpKernelBrowser::class), E_USER_DEPRECATED);
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\Request as DomRequest;
use Symfony\Component\BrowserKit\Response as DomResponse;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class Client extends HttpKernelBrowser
/**
* Client simulates a browser and makes requests to an HttpKernel instance.
*
* @deprecated since Symfony 4.3, use HttpKernelBrowser instead.
*/
class Client extends AbstractBrowser
{
protected $kernel;
private $catchExceptions = true;
/**
* @param HttpKernelInterface $kernel An HttpKernel instance
* @param array $server The server parameters (equivalent of $_SERVER)
* @param History $history A History instance to store the browser history
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
*/
public function __construct(HttpKernelInterface $kernel, array $server = [], History $history = null, CookieJar $cookieJar = null)
{
// These class properties must be set before calling the parent constructor, as it may depend on it.
$this->kernel = $kernel;
$this->followRedirects = false;
parent::__construct($server, $history, $cookieJar);
}
/**
* Sets whether to catch exceptions when the kernel is handling a request.
*
* @param bool $catchExceptions Whether to catch exceptions
*/
public function catchExceptions($catchExceptions)
{
$this->catchExceptions = $catchExceptions;
}
/**
* Makes a request.
*
* @return Response A Response instance
*/
protected function doRequest($request)
{
$response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $this->catchExceptions);
if ($this->kernel instanceof TerminableInterface) {
$this->kernel->terminate($request, $response);
}
return $response;
}
/**
* Returns the script to execute when the request must be insulated.
*
* @return string
*/
protected function getScript($request)
{
$kernel = var_export(serialize($this->kernel), true);
$request = var_export(serialize($request), true);
$errorReporting = error_reporting();
$requires = '';
foreach (get_declared_classes() as $class) {
if (0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$file = \dirname(\dirname($r->getFileName())).'/autoload.php';
if (file_exists($file)) {
$requires .= 'require_once '.var_export($file, true).";\n";
}
}
}
if (!$requires) {
throw new \RuntimeException('Composer autoloader not found.');
}
$code = <<<EOF
<?php
error_reporting($errorReporting);
$requires
\$kernel = unserialize($kernel);
\$request = unserialize($request);
EOF;
return $code.$this->getHandleScript();
}
protected function getHandleScript()
{
return <<<'EOF'
$response = $kernel->handle($request);
if ($kernel instanceof Symfony\Component\HttpKernel\TerminableInterface) {
$kernel->terminate($request, $response);
}
echo serialize($response);
EOF;
}
/**
* Converts the BrowserKit request to a HttpKernel request.
*
* @return Request A Request instance
*/
protected function filterRequest(DomRequest $request)
{
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
$httpRequest->files->set($key, $value);
}
return $httpRequest;
}
/**
* Filters an array of files.
*
* This method created test instances of UploadedFile so that the move()
* method can be called on those instances.
*
* If the size of a file is greater than the allowed size (from php.ini) then
* an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE.
*
* @see UploadedFile
*
* @return array An array with all uploaded files marked as already moved
*/
protected function filterFiles(array $files)
{
$filtered = [];
foreach ($files as $key => $value) {
if (\is_array($value)) {
$filtered[$key] = $this->filterFiles($value);
} elseif ($value instanceof UploadedFile) {
if ($value->isValid() && $value->getSize() > UploadedFile::getMaxFilesize()) {
$filtered[$key] = new UploadedFile(
'',
$value->getClientOriginalName(),
$value->getClientMimeType(),
UPLOAD_ERR_INI_SIZE,
true
);
} else {
$filtered[$key] = new UploadedFile(
$value->getPathname(),
$value->getClientOriginalName(),
$value->getClientMimeType(),
$value->getError(),
true
);
}
}
}
return $filtered;
}
/**
* Converts the HttpKernel response to a BrowserKit response.
*
* @return DomResponse A DomResponse instance
*/
protected function filterResponse($response)
{
// this is needed to support StreamedResponse
ob_start();
$response->sendContent();
$content = ob_get_clean();
return new DomResponse($content, $response->getStatusCode(), $response->headers->all());
}
}

View File

@@ -68,7 +68,7 @@ class FileLinkFormatter
*/
public function __sleep(): array
{
$this->getFileLinkFormat();
$this->fileLinkFormat = $this->getFileLinkFormat();
return ['fileLinkFormat'];
}
@@ -87,17 +87,19 @@ class FileLinkFormatter
private function getFileLinkFormat()
{
if ($this->fileLinkFormat) {
return $this->fileLinkFormat;
}
if ($this->requestStack && $this->baseDir && $this->urlFormat) {
$request = $this->requestStack->getMasterRequest();
if ($request instanceof Request && (!$this->urlFormat instanceof \Closure || $this->urlFormat = ($this->urlFormat)())) {
$this->fileLinkFormat = [
return [
$request->getSchemeAndHttpHost().$request->getBasePath().$this->urlFormat,
$this->baseDir.\DIRECTORY_SEPARATOR, '',
];
}
}
return $this->fileLinkFormat;
}
}

View File

@@ -19,7 +19,10 @@ use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\KernelEvents;
@@ -37,6 +40,7 @@ class DebugHandlersListener implements EventSubscriberInterface
private $scream;
private $fileLinkFormat;
private $scope;
private $charset;
private $firstCall = true;
private $hasTerminatedWithException;
@@ -49,7 +53,7 @@ class DebugHandlersListener implements EventSubscriberInterface
* @param string|FileLinkFormatter|null $fileLinkFormat The format for links to source files
* @param bool $scope Enables/disables scoping mode
*/
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = E_ALL, ?int $throwAt = E_ALL, bool $scream = true, $fileLinkFormat = null, bool $scope = true)
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = E_ALL, ?int $throwAt = E_ALL, bool $scream = true, $fileLinkFormat = null, bool $scope = true, string $charset = null)
{
$this->exceptionHandler = $exceptionHandler;
$this->logger = $logger;
@@ -58,6 +62,7 @@ class DebugHandlersListener implements EventSubscriberInterface
$this->scream = $scream;
$this->fileLinkFormat = $fileLinkFormat;
$this->scope = $scope;
$this->charset = $charset;
}
/**
@@ -144,6 +149,26 @@ class DebugHandlersListener implements EventSubscriberInterface
}
}
/**
* @internal
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$this->hasTerminatedWithException || !$event->isMasterRequest()) {
return;
}
$debug = $this->scream && $this->scope;
$controller = function (Request $request) use ($debug) {
$e = $request->attributes->get('exception');
$handler = new ExceptionHandler($debug, $this->charset, $this->fileLinkFormat);
return new Response($handler->getHtml($e), $e->getStatusCode(), $e->getHeaders());
};
(new ExceptionListener($controller, $this->logger, $debug))->onKernelException($event);
}
public static function getSubscribedEvents()
{
$events = [KernelEvents::REQUEST => ['configure', 2048]];
@@ -152,6 +177,8 @@ class DebugHandlersListener implements EventSubscriberInterface
$events[ConsoleEvents::COMMAND] = ['configure', 2048];
}
$events[KernelEvents::EXCEPTION] = ['onKernelException', -2048];
return $events;
}
}

View File

@@ -13,7 +13,6 @@ namespace Symfony\Component\HttpKernel\EventListener;
use Psr\Log\LoggerInterface;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -34,17 +33,12 @@ class ExceptionListener implements EventSubscriberInterface
protected $controller;
protected $logger;
protected $debug;
private $charset;
private $fileLinkFormat;
private $isTerminating = false;
public function __construct($controller, LoggerInterface $logger = null, $debug = false, string $charset = null, $fileLinkFormat = null)
public function __construct($controller, LoggerInterface $logger = null, $debug = false)
{
$this->controller = $controller;
$this->logger = $logger;
$this->debug = $debug;
$this->charset = $charset;
$this->fileLinkFormat = $fileLinkFormat;
}
public function logKernelException(GetResponseForExceptionEvent $event)
@@ -61,16 +55,9 @@ class ExceptionListener implements EventSubscriberInterface
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (null === $this->controller) {
if (!$event->isMasterRequest()) {
return;
}
if (!$this->isTerminating) {
$this->isTerminating = true;
return;
}
$this->isTerminating = false;
return;
}
$exception = $event->getException();
$request = $this->duplicateRequest($exception, $event->getRequest());
$eventDispatcher = \func_num_args() > 2 ? func_get_arg(2) : null;
@@ -107,11 +94,6 @@ class ExceptionListener implements EventSubscriberInterface
}
}
public function reset()
{
$this->isTerminating = false;
}
public static function getSubscribedEvents()
{
return [
@@ -150,12 +132,8 @@ class ExceptionListener implements EventSubscriberInterface
protected function duplicateRequest(\Exception $exception, Request $request)
{
$attributes = [
'exception' => $exception = FlattenException::create($exception),
'_controller' => $this->controller ?: function () use ($exception) {
$handler = new ExceptionHandler($this->debug, $this->charset, $this->fileLinkFormat);
return new Response($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders());
},
'_controller' => $this->controller,
'exception' => FlattenException::create($exception),
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
];
$request = $request->duplicate(null, null, $attributes);

View File

@@ -11,15 +11,6 @@
namespace Symfony\Component\HttpKernel;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\Request as DomRequest;
use Symfony\Component\BrowserKit\Response as DomResponse;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Client simulates a browser and makes requests to an HttpKernel instance.
*
@@ -28,177 +19,6 @@ use Symfony\Component\HttpFoundation\Response;
* @method Request getRequest() A Request instance
* @method Response getResponse() A Response instance
*/
class HttpKernelBrowser extends AbstractBrowser
class HttpKernelBrowser extends Client
{
protected $kernel;
private $catchExceptions = true;
/**
* @param HttpKernelInterface $kernel An HttpKernel instance
* @param array $server The server parameters (equivalent of $_SERVER)
* @param History $history A History instance to store the browser history
* @param CookieJar $cookieJar A CookieJar instance to store the cookies
*/
public function __construct(HttpKernelInterface $kernel, array $server = [], History $history = null, CookieJar $cookieJar = null)
{
// These class properties must be set before calling the parent constructor, as it may depend on it.
$this->kernel = $kernel;
$this->followRedirects = false;
parent::__construct($server, $history, $cookieJar);
}
/**
* Sets whether to catch exceptions when the kernel is handling a request.
*
* @param bool $catchExceptions Whether to catch exceptions
*/
public function catchExceptions($catchExceptions)
{
$this->catchExceptions = $catchExceptions;
}
/**
* Makes a request.
*
* @return Response A Response instance
*/
protected function doRequest($request)
{
$response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $this->catchExceptions);
if ($this->kernel instanceof TerminableInterface) {
$this->kernel->terminate($request, $response);
}
return $response;
}
/**
* Returns the script to execute when the request must be insulated.
*
* @return string
*/
protected function getScript($request)
{
$kernel = var_export(serialize($this->kernel), true);
$request = var_export(serialize($request), true);
$errorReporting = error_reporting();
$requires = '';
foreach (get_declared_classes() as $class) {
if (0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$file = \dirname(\dirname($r->getFileName())).'/autoload.php';
if (file_exists($file)) {
$requires .= 'require_once '.var_export($file, true).";\n";
}
}
}
if (!$requires) {
throw new \RuntimeException('Composer autoloader not found.');
}
$code = <<<EOF
<?php
error_reporting($errorReporting);
$requires
\$kernel = unserialize($kernel);
\$request = unserialize($request);
EOF;
return $code.$this->getHandleScript();
}
protected function getHandleScript()
{
return <<<'EOF'
$response = $kernel->handle($request);
if ($kernel instanceof Symfony\Component\HttpKernel\TerminableInterface) {
$kernel->terminate($request, $response);
}
echo serialize($response);
EOF;
}
/**
* Converts the BrowserKit request to a HttpKernel request.
*
* @return Request A Request instance
*/
protected function filterRequest(DomRequest $request)
{
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
$httpRequest->files->set($key, $value);
}
return $httpRequest;
}
/**
* Filters an array of files.
*
* This method created test instances of UploadedFile so that the move()
* method can be called on those instances.
*
* If the size of a file is greater than the allowed size (from php.ini) then
* an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE.
*
* @see UploadedFile
*
* @return array An array with all uploaded files marked as already moved
*/
protected function filterFiles(array $files)
{
$filtered = [];
foreach ($files as $key => $value) {
if (\is_array($value)) {
$filtered[$key] = $this->filterFiles($value);
} elseif ($value instanceof UploadedFile) {
if ($value->isValid() && $value->getSize() > UploadedFile::getMaxFilesize()) {
$filtered[$key] = new UploadedFile(
'',
$value->getClientOriginalName(),
$value->getClientMimeType(),
UPLOAD_ERR_INI_SIZE,
true
);
} else {
$filtered[$key] = new UploadedFile(
$value->getPathname(),
$value->getClientOriginalName(),
$value->getClientMimeType(),
$value->getError(),
true
);
}
}
}
return $filtered;
}
/**
* Converts the HttpKernel response to a BrowserKit response.
*
* @return DomResponse A DomResponse instance
*/
protected function filterResponse($response)
{
// this is needed to support StreamedResponse
ob_start();
$response->sendContent();
$content = ob_get_clean();
return new DomResponse($content, $response->getStatusCode(), $response->headers->all());
}
}

View File

@@ -73,11 +73,11 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
private $requestStackSize = 0;
private $resetServices = false;
const VERSION = '4.3.0';
const VERSION_ID = 40300;
const VERSION = '4.3.1';
const VERSION_ID = 40301;
const MAJOR_VERSION = 4;
const MINOR_VERSION = 3;
const RELEASE_VERSION = 0;
const RELEASE_VERSION = 1;
const EXTRA_VERSION = '';
const END_OF_MAINTENANCE = '01/2020';
@@ -494,7 +494,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
$fresh = true;
}
} catch (\Throwable $e) {
} catch (\Exception $e) {
} finally {
error_reporting($errorLevel);
}
@@ -563,7 +562,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
try {
$oldContainer = include $cache->getPath();
} catch (\Throwable $e) {
} catch (\Exception $e) {
} finally {
error_reporting($errorLevel);
}

View File

@@ -59,7 +59,7 @@ class CacheWarmerAggregateTest extends TestCase
$warmer
->expects($this->once())
->method('isOptional')
->will($this->returnValue(true));
->willReturn(true);
$warmer
->expects($this->never())
->method('warmUp');

View File

@@ -23,7 +23,7 @@ class FileLocatorTest extends TestCase
->expects($this->atLeastOnce())
->method('locateResource')
->with('@BundleName/some/path', null, true)
->will($this->returnValue('/bundle-name/some/path'));
->willReturn('/bundle-name/some/path');
$locator = new FileLocator($kernel);
$this->assertEquals('/bundle-name/some/path', $locator->locate('@BundleName/some/path'));

View File

@@ -27,11 +27,11 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->once())
->method('has')
->with('foo')
->will($this->returnValue(true));
->willReturn(true);
$container->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($service))
->willReturn($service)
;
$resolver = $this->createControllerResolver(null, $container);
@@ -52,11 +52,11 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->once())
->method('has')
->with('foo')
->will($this->returnValue(true));
->willReturn(true);
$container->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($service))
->willReturn($service)
;
$resolver = $this->createControllerResolver(null, $container);
@@ -77,12 +77,12 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->once())
->method('has')
->with('foo')
->will($this->returnValue(true))
->willReturn(true)
;
$container->expects($this->once())
->method('get')
->with('foo')
->will($this->returnValue($service))
->willReturn($service)
;
$resolver = $this->createControllerResolver(null, $container);
@@ -102,12 +102,12 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->once())
->method('has')
->with(InvokableControllerService::class)
->will($this->returnValue(true))
->willReturn(true)
;
$container->expects($this->once())
->method('get')
->with(InvokableControllerService::class)
->will($this->returnValue($service))
->willReturn($service)
;
$resolver = $this->createControllerResolver(null, $container);
@@ -131,13 +131,13 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->once())
->method('has')
->with(ControllerTestService::class)
->will($this->returnValue(false))
->willReturn(false)
;
$container->expects($this->atLeastOnce())
->method('getRemovedIds')
->with()
->will($this->returnValue([ControllerTestService::class => true]))
->willReturn([ControllerTestService::class => true])
;
$resolver = $this->createControllerResolver(null, $container);
@@ -159,13 +159,13 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->once())
->method('has')
->with('app.my_controller')
->will($this->returnValue(false))
->willReturn(false)
;
$container->expects($this->atLeastOnce())
->method('getRemovedIds')
->with()
->will($this->returnValue(['app.my_controller' => true]))
->willReturn(['app.my_controller' => true])
;
$resolver = $this->createControllerResolver(null, $container);

View File

@@ -27,8 +27,8 @@ class LoggerDataCollectorTest extends TestCase
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('countErrors')->will($this->returnValue('foo'));
$logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue([]));
$logger->expects($this->once())->method('countErrors')->willReturn('foo');
$logger->expects($this->exactly(2))->method('getLogs')->willReturn([]);
$c = new LoggerDataCollector($logger, __DIR__.'/');
$c->lateCollect();
@@ -56,7 +56,7 @@ class LoggerDataCollectorTest extends TestCase
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('countErrors')->with(null);
$logger->expects($this->exactly(2))->method('getLogs')->with(null)->will($this->returnValue([]));
$logger->expects($this->exactly(2))->method('getLogs')->with(null)->willReturn([]);
$c = new LoggerDataCollector($logger, __DIR__.'/', $stack);
@@ -77,7 +77,7 @@ class LoggerDataCollectorTest extends TestCase
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('countErrors')->with($subRequest);
$logger->expects($this->exactly(2))->method('getLogs')->with($subRequest)->will($this->returnValue([]));
$logger->expects($this->exactly(2))->method('getLogs')->with($subRequest)->willReturn([]);
$c = new LoggerDataCollector($logger, __DIR__.'/', $stack);
@@ -94,8 +94,8 @@ class LoggerDataCollectorTest extends TestCase
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
$logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue($logs));
$logger->expects($this->once())->method('countErrors')->willReturn($nb);
$logger->expects($this->exactly(2))->method('getLogs')->willReturn($logs);
$c = new LoggerDataCollector($logger);
$c->lateCollect();

View File

@@ -44,7 +44,7 @@ class TimeDataCollectorTest extends TestCase
$this->assertEquals(0, $c->getStartTime());
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
$kernel->expects($this->once())->method('getStartTime')->will($this->returnValue(123456));
$kernel->expects($this->once())->method('getStartTime')->willReturn(123456);
$c = new TimeDataCollector($kernel);
$request = new Request();

View File

@@ -50,7 +50,7 @@ class TraceableEventDispatcherTest extends TestCase
->getMock();
$stopwatch->expects($this->once())
->method('isStarted')
->will($this->returnValue(false));
->willReturn(false);
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch);
@@ -66,7 +66,7 @@ class TraceableEventDispatcherTest extends TestCase
->getMock();
$stopwatch->expects($this->once())
->method('isStarted')
->will($this->returnValue(true));
->willReturn(true);
$stopwatch->expects($this->once())
->method('stop');
$stopwatch->expects($this->once())
@@ -113,9 +113,9 @@ class TraceableEventDispatcherTest extends TestCase
protected function getHttpKernel($dispatcher, $controller)
{
$controllerResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();
$controllerResolver->expects($this->once())->method('getController')->will($this->returnValue($controller));
$controllerResolver->expects($this->once())->method('getController')->willReturn($controller);
$argumentResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface')->getMock();
$argumentResolver->expects($this->once())->method('getArguments')->will($this->returnValue([]));
$argumentResolver->expects($this->once())->method('getArguments')->willReturn([]);
return new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver);
}

View File

@@ -21,15 +21,15 @@ class LazyLoadingFragmentHandlerTest extends TestCase
public function testRender()
{
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
$renderer->expects($this->once())->method('getName')->will($this->returnValue('foo'));
$renderer->expects($this->any())->method('render')->will($this->returnValue(new Response()));
$renderer->expects($this->once())->method('getName')->willReturn('foo');
$renderer->expects($this->any())->method('render')->willReturn(new Response());
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
$requestStack->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/'));
$container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
$container->expects($this->once())->method('has')->with('foo')->willReturn(true);
$container->expects($this->once())->method('get')->will($this->returnValue($renderer));
$container->expects($this->once())->method('get')->willReturn($renderer);
$handler = new LazyLoadingFragmentHandler($container, $requestStack, false);

View File

@@ -78,7 +78,7 @@ class AddRequestFormatsListenerTest extends TestCase
$event->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
->willReturn($request);
return $event;
}

View File

@@ -94,7 +94,7 @@ class DebugHandlersListenerTest extends TestCase
$dispatcher = new EventDispatcher();
$listener = new DebugHandlersListener(null);
$app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
$app->expects($this->once())->method('getHelperSet')->will($this->returnValue(new HelperSet()));
$app->expects($this->once())->method('getHelperSet')->willReturn(new HelperSet());
$command = new Command(__FUNCTION__);
$command->setApplication($app);
$event = new ConsoleEvent($command, new ArgvInput(), new ConsoleOutput());
@@ -104,6 +104,7 @@ class DebugHandlersListenerTest extends TestCase
$xListeners = [
KernelEvents::REQUEST => [[$listener, 'configure']],
ConsoleEvents::COMMAND => [[$listener, 'configure']],
KernelEvents::EXCEPTION => [[$listener, 'onKernelException']],
];
$this->assertSame($xListeners, $dispatcher->getListeners());

View File

@@ -116,9 +116,9 @@ class ExceptionListenerTest extends TestCase
$listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock());
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
$kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) {
return new Response($request->getRequestFormat());
}));
});
$request = Request::create('/');
$request->setRequestFormat('xml');
@@ -134,9 +134,9 @@ class ExceptionListenerTest extends TestCase
{
$dispatcher = new EventDispatcher();
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
$kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) {
return new Response($request->getRequestFormat());
}));
});
$listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(), true);
@@ -155,25 +155,6 @@ class ExceptionListenerTest extends TestCase
$this->assertFalse($response->headers->has('content-security-policy'), 'CSP header has been removed');
$this->assertFalse($dispatcher->hasListeners(KernelEvents::RESPONSE), 'CSP removal listener has been removed');
}
public function testNullController()
{
$listener = new ExceptionListener(null);
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
$controller = $request->attributes->get('_controller');
return $controller();
}));
$request = Request::create('/');
$event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
$listener->onKernelException($event);
$this->assertNull($event->getResponse());
$listener->onKernelException($event);
$this->assertContains('Whoops, looks like something went wrong.', $event->getResponse()->getContent());
}
}
class TestLogger extends Logger implements DebugLoggerInterface

View File

@@ -73,7 +73,7 @@ class LocaleListenerTest extends TestCase
$context->expects($this->once())->method('setParameter')->with('_locale', 'es');
$router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(['getContext'])->disableOriginalConstructor()->getMock();
$router->expects($this->once())->method('getContext')->will($this->returnValue($context));
$router->expects($this->once())->method('getContext')->willReturn($context);
$request = Request::create('/');
@@ -89,12 +89,12 @@ class LocaleListenerTest extends TestCase
$context->expects($this->once())->method('setParameter')->with('_locale', 'es');
$router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(['getContext'])->disableOriginalConstructor()->getMock();
$router->expects($this->once())->method('getContext')->will($this->returnValue($context));
$router->expects($this->once())->method('getContext')->willReturn($context);
$parentRequest = Request::create('/');
$parentRequest->setLocale('es');
$this->requestStack->expects($this->once())->method('getParentRequest')->will($this->returnValue($parentRequest));
$this->requestStack->expects($this->once())->method('getParentRequest')->willReturn($parentRequest);
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FinishRequestEvent')->disableOriginalConstructor()->getMock();

View File

@@ -36,7 +36,7 @@ class ProfilerListenerTest extends TestCase
$profiler->expects($this->once())
->method('collect')
->will($this->returnValue($profile));
->willReturn($profile);
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();

View File

@@ -49,7 +49,7 @@ class RouterListenerTest extends TestCase
$context->setHttpsPort($defaultHttpsPort);
$urlMatcher->expects($this->any())
->method('getContext')
->will($this->returnValue($context));
->willReturn($context);
$listener = new RouterListener($urlMatcher, $this->requestStack);
$event = $this->createRequestEventForUri($uri);
@@ -97,7 +97,7 @@ class RouterListenerTest extends TestCase
$requestMatcher->expects($this->once())
->method('matchRequest')
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->will($this->returnValue([]));
->willReturn([]);
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext());
$listener->onKernelRequest($event);
@@ -113,7 +113,7 @@ class RouterListenerTest extends TestCase
$requestMatcher->expects($this->any())
->method('matchRequest')
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->will($this->returnValue([]));
->willReturn([]);
$context = new RequestContext();
@@ -138,7 +138,7 @@ class RouterListenerTest extends TestCase
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
$requestMatcher->expects($this->once())
->method('matchRequest')
->will($this->returnValue($parameter));
->willReturn($parameter);
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger->expects($this->once())

View File

@@ -46,7 +46,7 @@ class TestSessionListenerTest extends TestCase
$this->session = $this->getSession();
$this->listener->expects($this->any())
->method('getSession')
->will($this->returnValue($this->session));
->willReturn($this->session);
}
public function testShouldSaveMasterRequestSession()
@@ -183,28 +183,28 @@ class TestSessionListenerTest extends TestCase
{
$this->session->expects($this->once())
->method('isStarted')
->will($this->returnValue(true));
->willReturn(true);
}
private function sessionHasNotBeenStarted()
{
$this->session->expects($this->once())
->method('isStarted')
->will($this->returnValue(false));
->willReturn(false);
}
private function sessionIsEmpty()
{
$this->session->expects($this->once())
->method('isEmpty')
->will($this->returnValue(true));
->willReturn(true);
}
private function fixSessionId($sessionId)
{
$this->session->expects($this->any())
->method('getId')
->will($this->returnValue($sessionId));
->willReturn($sessionId);
}
private function getSession()
@@ -214,7 +214,7 @@ class TestSessionListenerTest extends TestCase
->getMock();
// set return value for getName()
$mock->expects($this->any())->method('getName')->will($this->returnValue('MOCKSESSID'));
$mock->expects($this->any())->method('getName')->willReturn('MOCKSESSID');
return $mock;
}

View File

@@ -117,6 +117,6 @@ class TranslatorListenerTest extends TestCase
$this->requestStack
->expects($this->any())
->method('getParentRequest')
->will($this->returnValue($request));
->willReturn($request);
}
}

View File

@@ -32,7 +32,7 @@ class FragmentHandlerTest extends TestCase
$this->requestStack
->expects($this->any())
->method('getCurrentRequest')
->will($this->returnValue(Request::create('/')))
->willReturn(Request::create('/'))
;
}
@@ -79,7 +79,7 @@ class FragmentHandlerTest extends TestCase
$renderer
->expects($this->any())
->method('getName')
->will($this->returnValue('foo'))
->willReturn('foo')
;
$e = $renderer
->expects($this->any())

View File

@@ -124,18 +124,18 @@ class InlineFragmentRendererTest extends TestCase
$controllerResolver
->expects($this->once())
->method('getController')
->will($this->returnValue(function () {
->willReturn(function () {
ob_start();
echo 'bar';
throw new \RuntimeException();
}))
})
;
$argumentResolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolverInterface')->getMock();
$argumentResolver
->expects($this->once())
->method('getArguments')
->will($this->returnValue([]))
->willReturn([])
;
$kernel = new HttpKernel(new EventDispatcher(), $controllerResolver, new RequestStack(), $argumentResolver);

View File

@@ -229,7 +229,7 @@ class EsiTest extends TestCase
$cache = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\HttpCache')->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock();
$cache->expects($this->any())
->method('getRequest')
->will($this->returnValue($request))
->willReturn($request)
;
if (\is_array($response)) {
$cache->expects($this->any())
@@ -239,7 +239,7 @@ class EsiTest extends TestCase
} else {
$cache->expects($this->any())
->method('handle')
->will($this->returnValue($response))
->willReturn($response)
;
}

View File

@@ -196,7 +196,7 @@ class SsiTest extends TestCase
$cache = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\HttpCache')->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock();
$cache->expects($this->any())
->method('getRequest')
->will($this->returnValue($request))
->willReturn($request)
;
if (\is_array($response)) {
$cache->expects($this->any())
@@ -206,7 +206,7 @@ class SsiTest extends TestCase
} else {
$cache->expects($this->any())
->method('handle')
->will($this->returnValue($response))
->willReturn($response)
;
}

View File

@@ -156,11 +156,11 @@ class HttpKernelBrowserTest extends TestCase
/* should be modified when the getClientSize will be removed */
$file->expects($this->any())
->method('getSize')
->will($this->returnValue(INF))
->willReturn(INF)
;
$file->expects($this->any())
->method('getClientSize')
->will($this->returnValue(INF))
->willReturn(INF)
;
$client->request('POST', '/', [], [$file]);

View File

@@ -351,13 +351,13 @@ class HttpKernelTest extends TestCase
$controllerResolver
->expects($this->any())
->method('getController')
->will($this->returnValue($controller));
->willReturn($controller);
$argumentResolver = $this->getMockBuilder(ArgumentResolverInterface::class)->getMock();
$argumentResolver
->expects($this->any())
->method('getArguments')
->will($this->returnValue($arguments));
->willReturn($arguments);
return new HttpKernel($eventDispatcher, $controllerResolver, $requestStack, $argumentResolver);
}

View File

@@ -123,7 +123,7 @@ class KernelTest extends TestCase
$kernel = $this->getKernel(['initializeBundles', 'initializeContainer', 'getBundles']);
$kernel->expects($this->once())
->method('getBundles')
->will($this->returnValue([$bundle]));
->willReturn([$bundle]);
$kernel->boot();
}
@@ -178,7 +178,7 @@ class KernelTest extends TestCase
$kernel = $this->getKernel(['getBundles']);
$kernel->expects($this->any())
->method('getBundles')
->will($this->returnValue([$bundle]));
->willReturn([$bundle]);
$kernel->boot();
$kernel->shutdown();
@@ -201,7 +201,7 @@ class KernelTest extends TestCase
$kernel = $this->getKernel(['getHttpKernel']);
$kernel->expects($this->once())
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
->willReturn($httpKernelMock);
$kernel->handle($request, $type, $catch);
}
@@ -219,7 +219,7 @@ class KernelTest extends TestCase
$kernel = $this->getKernel(['getHttpKernel', 'boot']);
$kernel->expects($this->once())
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
->willReturn($httpKernelMock);
$kernel->expects($this->once())
->method('boot');
@@ -381,7 +381,7 @@ EOF;
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))
->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))
;
$kernel->locateResource('@Bundle1Bundle/config/routing.xml');
@@ -393,7 +393,7 @@ EOF;
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))
->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))
;
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt'));
@@ -405,7 +405,7 @@ EOF;
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))
->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'))
;
$this->assertEquals(
@@ -420,7 +420,7 @@ EOF;
$kernel
->expects($this->once())
->method('getBundle')
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle')))
->willReturn($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))
;
$this->assertEquals(
@@ -435,7 +435,7 @@ EOF;
$kernel
->expects($this->exactly(2))
->method('getBundle')
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle')))
->willReturn($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle'))
;
$this->assertEquals(
@@ -451,7 +451,7 @@ EOF;
$kernel
->expects($this->exactly(2))
->method('getBundle')
->will($this->returnValue($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle')))
->willReturn($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle'))
;
$this->assertEquals(
@@ -514,7 +514,7 @@ EOF;
$kernel = $this->getKernel(['getHttpKernel']);
$kernel->expects($this->exactly(2))
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
->willReturn($httpKernelMock);
$kernel->boot();
$kernel->terminate(Request::create('/'), new Response());
@@ -640,19 +640,19 @@ EOF;
$bundle
->expects($this->any())
->method('getName')
->will($this->returnValue(null === $bundleName ? \get_class($bundle) : $bundleName))
->willReturn(null === $bundleName ? \get_class($bundle) : $bundleName)
;
$bundle
->expects($this->any())
->method('getPath')
->will($this->returnValue($dir))
->willReturn($dir)
;
$bundle
->expects($this->any())
->method('getParent')
->will($this->returnValue($parent))
->willReturn($parent)
;
return $bundle;
@@ -678,7 +678,7 @@ EOF;
;
$kernel->expects($this->any())
->method('registerBundles')
->will($this->returnValue($bundles))
->willReturn($bundles)
;
$p = new \ReflectionProperty($kernel, 'rootDir');
$p->setAccessible(true);

View File

@@ -149,7 +149,7 @@ class LoggerTest extends TestCase
}
$dummy->expects($this->atLeastOnce())
->method('__toString')
->will($this->returnValue('DUMMY'));
->willReturn('DUMMY');
$this->logger->warning($dummy);

View File

@@ -28,17 +28,12 @@ final class MessageConverter
/**
* @throws RuntimeException when unable to convert the message to an email
*/
public static function toEmail(RawMessage $message): Email
public static function toEmail(Message $message): Email
{
if ($message instanceof Email) {
return $message;
}
if (RawMessage::class === \get_class($message)) {
// FIXME: parse the raw message to create the envelope?
throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as it is not supported yet.', RawMessage::class));
}
// try to convert to a "simple" Email instance
$body = $message->getBody();
if ($body instanceof TextPart) {

View File

@@ -27,7 +27,7 @@ class ProcessFailedExceptionTest extends TestCase
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(['isSuccessful'])->setConstructorArgs([['php']])->getMock();
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(true));
->willReturn(true);
if (method_exists($this, 'expectException')) {
$this->expectException(\InvalidArgumentException::class);
@@ -55,31 +55,31 @@ class ProcessFailedExceptionTest extends TestCase
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(['isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'])->setConstructorArgs([[$cmd]])->getMock();
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(false));
->willReturn(false);
$process->expects($this->once())
->method('getOutput')
->will($this->returnValue($output));
->willReturn($output);
$process->expects($this->once())
->method('getErrorOutput')
->will($this->returnValue($errorOutput));
->willReturn($errorOutput);
$process->expects($this->once())
->method('getExitCode')
->will($this->returnValue($exitCode));
->willReturn($exitCode);
$process->expects($this->once())
->method('getExitCodeText')
->will($this->returnValue($exitText));
->willReturn($exitText);
$process->expects($this->once())
->method('isOutputDisabled')
->will($this->returnValue(false));
->willReturn(false);
$process->expects($this->once())
->method('getWorkingDirectory')
->will($this->returnValue($workingDirectory));
->willReturn($workingDirectory);
$exception = new ProcessFailedException($process);
@@ -103,7 +103,7 @@ class ProcessFailedExceptionTest extends TestCase
$process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(['isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'])->setConstructorArgs([[$cmd]])->getMock();
$process->expects($this->once())
->method('isSuccessful')
->will($this->returnValue(false));
->willReturn(false);
$process->expects($this->never())
->method('getOutput');
@@ -113,19 +113,19 @@ class ProcessFailedExceptionTest extends TestCase
$process->expects($this->once())
->method('getExitCode')
->will($this->returnValue($exitCode));
->willReturn($exitCode);
$process->expects($this->once())
->method('getExitCodeText')
->will($this->returnValue($exitText));
->willReturn($exitText);
$process->expects($this->once())
->method('isOutputDisabled')
->will($this->returnValue(true));
->willReturn(true);
$process->expects($this->once())
->method('getWorkingDirectory')
->will($this->returnValue($workingDirectory));
->willReturn($workingDirectory);
$exception = new ProcessFailedException($process);

View File

@@ -8,8 +8,9 @@ CHANGELOG
* added `CompiledUrlGenerator` and `CompiledUrlGeneratorDumper`
* deprecated `PhpGeneratorDumper` and `PhpMatcherDumper`
* deprecated `generator_base_class`, `generator_cache_class`, `matcher_base_class` and `matcher_cache_class` router options
* deprecated implementing `Serializable` for `Route` and `CompiledRoute`; if you serialize them, please
ensure your unserialization logic can recover from a failure related to an updated serialization format
* `Serializable` implementing methods for `Route` and `CompiledRoute` are marked as `@internal` and `@final`.
Instead of overwriting them, use `__serialize` and `__unserialize` as extension points which are forward compatible
with the new serialization methods in PHP 7.4.
* exposed `utf8` Route option, defaults "locale" and "format" in configuration loaders and configurators
* added support for invokable route loader services

View File

@@ -64,7 +64,8 @@ class CompiledRoute implements \Serializable
}
/**
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
* @internal since Symfony 4.3
* @final since Symfony 4.3
*/
public function serialize()
{
@@ -84,7 +85,8 @@ class CompiledRoute implements \Serializable
}
/**
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
* @internal since Symfony 4.3
* @final since Symfony 4.3
*/
public function unserialize($serialized)
{

View File

@@ -78,7 +78,8 @@ class Route implements \Serializable
}
/**
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
* @internal since Symfony 4.3
* @final since Symfony 4.3
*/
public function serialize()
{
@@ -104,7 +105,8 @@ class Route implements \Serializable
}
/**
* @internal since Symfony 4.3, will be removed in Symfony 5 as the class won't implement Serializable anymore
* @internal since Symfony 4.3
* @final since Symfony 4.3
*/
public function unserialize($serialized)
{

View File

@@ -233,12 +233,12 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
$reader
->expects($this->exactly(1))
->method('getClassAnnotations')
->will($this->returnValue([new RouteAnnotation($classRouteData1), new RouteAnnotation($classRouteData2)]))
->willReturn([new RouteAnnotation($classRouteData1), new RouteAnnotation($classRouteData2)])
;
$reader
->expects($this->once())
->method('getMethodAnnotations')
->will($this->returnValue([]))
->willReturn([])
;
$loader = new class($reader) extends AnnotationClassLoader {
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
@@ -319,7 +319,7 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
$reader
->expects($this->once())
->method('getMethodAnnotations')
->will($this->returnValue([new RouteAnnotation($methodRouteData)]))
->willReturn([new RouteAnnotation($methodRouteData)])
;
$loader = new class($reader) extends AnnotationClassLoader {

View File

@@ -34,13 +34,13 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
$this->reader
->expects($this->any())
->method('getMethodAnnotations')
->will($this->returnValue([]))
->willReturn([])
;
$this->reader
->expects($this->any())
->method('getClassAnnotations')
->will($this->returnValue([]))
->willReturn([])
;
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
@@ -58,13 +58,13 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
$this->reader
->expects($this->any())
->method('getMethodAnnotations')
->will($this->returnValue([]))
->willReturn([])
;
$this->reader
->expects($this->any())
->method('getClassAnnotations')
->will($this->returnValue([]))
->willReturn([])
;
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
@@ -93,7 +93,7 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
$this->reader
->expects($this->any())
->method('getMethodAnnotations')
->will($this->returnValue([]))
->willReturn([])
;
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');

View File

@@ -56,7 +56,7 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
$route = new Route(['path' => '/path/to/{id}']);
$this->reader->expects($this->once())->method('getClassAnnotation');
$this->reader->expects($this->once())->method('getMethodAnnotations')
->will($this->returnValue([$route]));
->willReturn([$route]);
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
}

View File

@@ -118,7 +118,7 @@ class ObjectRouteLoaderTest extends TestCase
->getMock();
$service->expects($this->once())
->method('loadRoutes')
->will($this->returnValue('NOT_A_COLLECTION'));
->willReturn('NOT_A_COLLECTION');
$loader = new ObjectRouteLoaderForTest();
$loader->loaderMap = ['my_service' => $service];

View File

@@ -23,7 +23,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$coll->add('foo', new Route('/foo/'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->will($this->returnValue([]));
$matcher->expects($this->once())->method('redirect')->willReturn([]);
$matcher->match('/foo');
}
@@ -33,7 +33,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$coll->add('foo', new Route('/foo'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->will($this->returnValue([]));
$matcher->expects($this->once())->method('redirect')->willReturn([]);
$matcher->match('/foo/');
}
@@ -61,7 +61,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
->expects($this->once())
->method('redirect')
->with('/foo', 'foo', 'ftp')
->will($this->returnValue(['_route' => 'foo']))
->willReturn(['_route' => 'foo'])
;
$matcher->match('/foo');
}
@@ -88,7 +88,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
->expects($this->once())
->method('redirect')
->with('/foo/baz', 'foo', 'https')
->will($this->returnValue(['redirect' => 'value']))
->willReturn(['redirect' => 'value'])
;
$this->assertEquals(['_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'], $matcher->match('/foo/baz'));
}
@@ -103,7 +103,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
->expects($this->once())
->method('redirect')
->with('/', 'foo', 'https')
->will($this->returnValue(['redirect' => 'value']));
->willReturn(['redirect' => 'value']);
$this->assertEquals(['_route' => 'foo', 'redirect' => 'value'], $matcher->match('/'));
}
@@ -117,7 +117,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
->expects($this->once())
->method('redirect')
->with('/foo/baz/', 'foo', null)
->will($this->returnValue(['redirect' => 'value']))
->willReturn(['redirect' => 'value'])
;
$this->assertEquals(['_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'], $matcher->match('/foo/baz'));
}
@@ -148,7 +148,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$coll->add('bar', new Route('/{name}'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo')->will($this->returnValue(['_route' => 'foo']));
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo')->willReturn(['_route' => 'foo']);
$this->assertSame(['_route' => 'foo'], $matcher->match('/foo'));
$coll = new RouteCollection();
@@ -156,7 +156,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$coll->add('bar', new Route('/{name}/'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo')->will($this->returnValue(['_route' => 'foo']));
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo')->willReturn(['_route' => 'foo']);
$this->assertSame(['_route' => 'foo'], $matcher->match('/foo/'));
}
@@ -166,7 +166,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$coll->add('foo', (new Route('/foo/'))->setSchemes(['https']));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo', 'https')->will($this->returnValue([]));
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo', 'https')->willReturn([]);
$matcher->match('/foo');
}

View File

@@ -28,7 +28,7 @@ class RouteCollectionBuilderTest extends TestCase
$resolver->expects($this->once())
->method('resolve')
->with('admin_routing.yml', 'yaml')
->will($this->returnValue($resolvedLoader));
->willReturn($resolvedLoader);
$originalRoute = new Route('/foo/path');
$expectedCollection = new RouteCollection();
@@ -39,12 +39,12 @@ class RouteCollectionBuilderTest extends TestCase
->expects($this->once())
->method('load')
->with('admin_routing.yml', 'yaml')
->will($this->returnValue($expectedCollection));
->willReturn($expectedCollection);
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader->expects($this->any())
->method('getResolver')
->will($this->returnValue($resolver));
->willReturn($resolver);
// import the file!
$routes = new RouteCollectionBuilder($loader);
@@ -107,11 +107,11 @@ class RouteCollectionBuilderTest extends TestCase
// make this loader able to do the import - keeps mocking simple
$loader->expects($this->any())
->method('supports')
->will($this->returnValue(true));
->willReturn(true);
$loader
->expects($this->once())
->method('load')
->will($this->returnValue($importedCollection));
->willReturn($importedCollection);
$routes = new RouteCollectionBuilder($loader);
@@ -296,11 +296,11 @@ class RouteCollectionBuilderTest extends TestCase
// make this loader able to do the import - keeps mocking simple
$loader->expects($this->any())
->method('supports')
->will($this->returnValue(true));
->willReturn(true);
$loader
->expects($this->any())
->method('load')
->will($this->returnValue($importedCollection));
->willReturn($importedCollection);
// import this from the /admin route builder
$adminRoutes->import('admin.yml', '/imported');
@@ -347,11 +347,11 @@ class RouteCollectionBuilderTest extends TestCase
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader->expects($this->any())
->method('supports')
->will($this->returnValue(true));
->willReturn(true);
$loader
->expects($this->any())
->method('load')
->will($this->returnValue([$firstCollection, $secondCollection]));
->willReturn([$firstCollection, $secondCollection]);
$routeCollectionBuilder = new RouteCollectionBuilder($loader);
$routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');

View File

@@ -88,7 +88,7 @@ class RouterTest extends TestCase
$this->loader->expects($this->once())
->method('load')->with('routing.yml', 'ResourceType')
->will($this->returnValue($routeCollection));
->willReturn($routeCollection);
$this->assertSame($routeCollection, $this->router->getRouteCollection());
}
@@ -99,7 +99,7 @@ class RouterTest extends TestCase
$this->loader->expects($this->once())
->method('load')->with('routing.yml', null)
->will($this->returnValue(new RouteCollection()));
->willReturn(new RouteCollection());
$this->assertInstanceOf('Symfony\\Component\\Routing\\Matcher\\UrlMatcher', $this->router->getMatcher());
}
@@ -110,7 +110,7 @@ class RouterTest extends TestCase
$this->loader->expects($this->once())
->method('load')->with('routing.yml', null)
->will($this->returnValue(new RouteCollection()));
->willReturn(new RouteCollection());
$this->assertInstanceOf('Symfony\\Component\\Routing\\Generator\\UrlGenerator', $this->router->getGenerator());
}

View File

@@ -16,10 +16,10 @@
}
],
"require": {
"php": "^7.1.3"
"php": "^7.1.3",
"psr/container": "^1.0"
},
"suggest": {
"psr/container": "",
"symfony/service-implementation": ""
},
"autoload": {

View File

@@ -91,7 +91,7 @@ EOF;
}
} else {
$leftNumber = '-Inf' === $matches['left'] ? -INF : (float) $matches['left'];
$rightNumber = \is_numeric($matches['right']) ? (float) $matches['right'] : INF;
$rightNumber = is_numeric($matches['right']) ? (float) $matches['right'] : INF;
if (('[' === $matches['left_delimiter'] ? $number >= $leftNumber : $number > $leftNumber)
&& (']' === $matches['right_delimiter'] ? $number <= $rightNumber : $number < $rightNumber)
@@ -117,7 +117,7 @@ EOF;
$message = sprintf('Unable to choose a translation for "%s" with locale "%s" for value "%d". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $id, $locale, $number);
if (\class_exists(InvalidArgumentException::class)) {
if (class_exists(InvalidArgumentException::class)) {
throw new InvalidArgumentException($message);
}

View File

@@ -124,7 +124,9 @@ EOF
$normalizedLocale = preg_quote(str_replace('-', '_', $targetLanguage), '/');
// strict file names require translation files to be named '____.locale.xlf'
// otherwise, both '____.locale.xlf' and 'locale.____.xlf' are allowed
$expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.%s\.xlf/', $normalizedLocale) : sprintf('/^(.*\.%s\.xlf|%s\..*\.xlf)/', $normalizedLocale, $normalizedLocale);
// also, the regexp matching must be case-insensitive, as defined for 'target-language' values
// http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#target-language
$expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.(?i:%s)\.xlf/', $normalizedLocale) : sprintf('/^(.*\.(?i:%s)\.xlf|(?i:%s)\..*\.xlf)/', $normalizedLocale, $normalizedLocale);
if (0 === preg_match($expectedFilenamePattern, basename($file))) {
$errors[] = [

View File

@@ -36,12 +36,9 @@ class TranslationDataCollector extends DataCollector implements LateDataCollecto
{
$messages = $this->sanitizeCollectedMessages($this->translator->getCollectedMessages());
$this->data = $this->computeCount($messages);
$this->data += $this->computeCount($messages);
$this->data['messages'] = $messages;
$this->data['locale'] = $this->translator->getLocale();
$this->data['fallback_locales'] = $this->translator->getFallbackLocales();
$this->data = $this->cloneVar($this->data);
}
@@ -50,6 +47,8 @@ class TranslationDataCollector extends DataCollector implements LateDataCollecto
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data['locale'] = $this->translator->getLocale();
$this->data['fallback_locales'] = $this->translator->getFallbackLocales();
}
/**

View File

@@ -94,6 +94,17 @@ class XliffLintCommandTest extends TestCase
$this->assertContains('There is a mismatch between the language included in the file name ("messages.en.xlf") and the "es" value used in the "target-language" attribute of the file.', trim($tester->getDisplay()));
}
public function testLintTargetLanguageIsCaseInsensitive()
{
$tester = $this->createCommandTester();
$filename = $this->createFile('note', 'zh-cn', 'messages.zh_CN.xlf');
$tester->execute(['filename' => $filename], ['decorated' => false]);
$this->assertEquals(0, $tester->getStatusCode());
$this->assertContains('[OK] All 1 XLIFF files contain valid syntax.', trim($tester->getDisplay()));
}
/**
* @expectedException \RuntimeException
*/

View File

@@ -27,7 +27,7 @@ class TranslationDataCollectorTest extends TestCase
public function testCollectEmptyMessages()
{
$translator = $this->getTranslator();
$translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue([]));
$translator->expects($this->any())->method('getCollectedMessages')->willReturn([]);
$dataCollector = new TranslationDataCollector($translator);
$dataCollector->lateCollect();
@@ -125,7 +125,7 @@ class TranslationDataCollectorTest extends TestCase
];
$translator = $this->getTranslator();
$translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue($collectedMessages));
$translator->expects($this->any())->method('getCollectedMessages')->willReturn($collectedMessages);
$dataCollector = new TranslationDataCollector($translator);
$dataCollector->lateCollect();

View File

@@ -103,10 +103,10 @@ class MessageCatalogueTest extends TestCase
public function testAddCatalogue()
{
$r = $this->getMockBuilder('Symfony\Component\Config\Resource\ResourceInterface')->getMock();
$r->expects($this->any())->method('__toString')->will($this->returnValue('r'));
$r->expects($this->any())->method('__toString')->willReturn('r');
$r1 = $this->getMockBuilder('Symfony\Component\Config\Resource\ResourceInterface')->getMock();
$r1->expects($this->any())->method('__toString')->will($this->returnValue('r1'));
$r1->expects($this->any())->method('__toString')->willReturn('r1');
$catalogue = new MessageCatalogue('en', ['domain1' => ['foo' => 'foo']]);
$catalogue->addResource($r);
@@ -127,13 +127,13 @@ class MessageCatalogueTest extends TestCase
public function testAddFallbackCatalogue()
{
$r = $this->getMockBuilder('Symfony\Component\Config\Resource\ResourceInterface')->getMock();
$r->expects($this->any())->method('__toString')->will($this->returnValue('r'));
$r->expects($this->any())->method('__toString')->willReturn('r');
$r1 = $this->getMockBuilder('Symfony\Component\Config\Resource\ResourceInterface')->getMock();
$r1->expects($this->any())->method('__toString')->will($this->returnValue('r1'));
$r1->expects($this->any())->method('__toString')->willReturn('r1');
$r2 = $this->getMockBuilder('Symfony\Component\Config\Resource\ResourceInterface')->getMock();
$r2->expects($this->any())->method('__toString')->will($this->returnValue('r2'));
$r2->expects($this->any())->method('__toString')->willReturn('r2');
$catalogue = new MessageCatalogue('fr_FR', ['domain1' => ['foo' => 'foo'], 'domain2' => ['bar' => 'bar']]);
$catalogue->addResource($r);
@@ -192,11 +192,11 @@ class MessageCatalogueTest extends TestCase
{
$catalogue = new MessageCatalogue('en');
$r = $this->getMockBuilder('Symfony\Component\Config\Resource\ResourceInterface')->getMock();
$r->expects($this->any())->method('__toString')->will($this->returnValue('r'));
$r->expects($this->any())->method('__toString')->willReturn('r');
$catalogue->addResource($r);
$catalogue->addResource($r);
$r1 = $this->getMockBuilder('Symfony\Component\Config\Resource\ResourceInterface')->getMock();
$r1->expects($this->any())->method('__toString')->will($this->returnValue('r1'));
$r1->expects($this->any())->method('__toString')->willReturn('r1');
$catalogue->addResource($r1);
$this->assertEquals([$r, $r1], $catalogue->getResources());

View File

@@ -104,7 +104,7 @@ class TranslatorCacheTest extends TestCase
$loader
->expects($this->exactly(2))
->method('load')
->will($this->returnValue($catalogue))
->willReturn($catalogue)
;
// 1st pass
@@ -249,11 +249,11 @@ class TranslatorCacheTest extends TestCase
{
$resource = $this->getMockBuilder('Symfony\Component\Config\Resource\SelfCheckingResourceInterface')->getMock();
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
$resource->method('isFresh')->will($this->returnValue(false));
$resource->method('isFresh')->willReturn(false);
$loader
->expects($this->exactly(2))
->method('load')
->will($this->returnValue($this->getCatalogue('fr', [], [$resource])));
->willReturn($this->getCatalogue('fr', [], [$resource]));
// prime the cache
$translator = new Translator('fr', null, $this->tmpDir, true);

View File

@@ -84,6 +84,7 @@ abstract class AbstractCloner implements ClonerInterface
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'],
'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'],
'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'],
'Symfony\Component\VarDumper\Cloner\AbstractCloner' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
'Symfony\Component\Debug\Exception\SilencedErrorContext' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'],
'ProxyManager\Proxy\ProxyInterface' => ['Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'],
@@ -188,10 +189,7 @@ abstract class AbstractCloner implements ClonerInterface
public function addCasters(array $casters)
{
foreach ($casters as $type => $callback) {
$closure = &$this->casters[$type][];
$closure = $callback instanceof \Closure ? $callback : static function (...$args) use ($callback, &$closure) {
return ($closure = \Closure::fromCallable($callback))(...$args);
};
$this->casters[$type][] = $callback;
}
}

View File

@@ -435,7 +435,7 @@ class CliDumper extends AbstractDumper
}
if (null === $this->handlesHrefGracefully) {
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') && !getenv('KONSOLE_VERSION');
}
if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {

View File

@@ -240,6 +240,12 @@ EOTXT;
$expectedTimeType = $var->getTimeType();
$expectedDateType = $var->getDateType();
$expectedTimeZone = $var->getTimeZone();
$expectedTimeZoneDisplayName = $expectedTimeZone->getDisplayName();
$expectedTimeZoneID = $expectedTimeZone->getID();
$expectedTimeZoneRawOffset = $expectedTimeZone->getRawOffset();
$expectedTimeZoneDSTSavings = $expectedTimeZone->useDaylightTime() ? "\n dst_savings: ".$expectedTimeZone->getDSTSavings() : '';
$expectedCalendarObject = $var->getCalendarObject();
$expectedCalendarObjectType = $expectedCalendarObject->getType();
$expectedCalendarObjectFirstDayOfWeek = $expectedCalendarObject->getFirstDayOfWeek();
@@ -254,13 +260,7 @@ EOTXT;
$expectedCalendarObjectTimeZoneDisplayName = $expectedCalendarObjectTimeZone->getDisplayName();
$expectedCalendarObjectTimeZoneID = $expectedCalendarObjectTimeZone->getID();
$expectedCalendarObjectTimeZoneRawOffset = $expectedCalendarObjectTimeZone->getRawOffset();
$expectedCalendarObjectTimeZoneDSTSavings = $expectedCalendarObjectTimeZone->getDSTSavings();
$expectedTimeZone = $var->getTimeZone();
$expectedTimeZoneDisplayName = $expectedTimeZone->getDisplayName();
$expectedTimeZoneID = $expectedTimeZone->getID();
$expectedTimeZoneRawOffset = $expectedTimeZone->getRawOffset();
$expectedTimeZoneDSTSavings = $expectedTimeZone->getDSTSavings();
$expectedCalendarObjectTimeZoneDSTSavings = $expectedTimeZone->useDaylightTime() ? "\n dst_savings: ".$expectedCalendarObjectTimeZone->getDSTSavings() : '';
$expected = <<<EOTXT
IntlDateFormatter {
@@ -282,15 +282,13 @@ IntlDateFormatter {
time_zone: IntlTimeZone {
display_name: "$expectedCalendarObjectTimeZoneDisplayName"
id: "$expectedCalendarObjectTimeZoneID"
raw_offset: $expectedCalendarObjectTimeZoneRawOffset
dst_savings: $expectedCalendarObjectTimeZoneDSTSavings
raw_offset: $expectedCalendarObjectTimeZoneRawOffset$expectedCalendarObjectTimeZoneDSTSavings
}
}
time_zone: IntlTimeZone {
display_name: "$expectedTimeZoneDisplayName"
id: "$expectedTimeZoneID"
raw_offset: $expectedTimeZoneRawOffset
dst_savings: $expectedTimeZoneDSTSavings
raw_offset: $expectedTimeZoneRawOffset$expectedTimeZoneDSTSavings
}
}
EOTXT;