Merge branch '5.2' into 5.x

* 5.2:
  [Notifier] Use abstract test cases in 5.2
  Rename parameter of @method configureContainer
  [DependencyInjection] Support PHP 8 builtin types in CheckTypeDeclarationsPass
  [DependencyInjection] Fix InvalidParameterTypeException for function parameters
  [Notifier] Cleanup changelog (5.2)
  [Notifier] Cleanup changelog (5.1)
  [VarDumper] fix mutating $GLOBALS while cloning it
This commit is contained in:
Nicolas Grekas 2021-01-07 15:55:28 +01:00
commit ed52a0d245
21 changed files with 408 additions and 185 deletions

View File

@ -29,7 +29,7 @@ use Symfony\Component\Routing\RouteCollectionBuilder;
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
* *
* @method void configureRoutes(RoutingConfigurator $routes) * @method void configureRoutes(RoutingConfigurator $routes)
* @method void configureContainer(ContainerConfigurator $c) * @method void configureContainer(ContainerConfigurator $container)
*/ */
trait MicroKernelTrait trait MicroKernelTrait
{ {

View File

@ -280,15 +280,26 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
return; return;
} }
if ('mixed' === $type) {
return;
}
if (is_a($class, $type, true)) { if (is_a($class, $type, true)) {
return; return;
} }
$checkFunction = sprintf('is_%s', $type); if ('false' === $type) {
if (false === $value) {
if (!$reflectionType->isBuiltin() || !$checkFunction($value)) { return;
throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? $class : get_debug_type($value), $parameter); }
} elseif ($reflectionType->isBuiltin()) {
$checkFunction = sprintf('is_%s', $type);
if ($checkFunction($value)) {
return;
}
} }
throw new InvalidParameterTypeException($this->currentId, \is_object($value) ? $class : get_debug_type($value), $parameter);
} }
private function getExpressionLanguage(): ExpressionLanguage private function getExpressionLanguage(): ExpressionLanguage

View File

@ -25,6 +25,11 @@ class InvalidParameterTypeException extends InvalidArgumentException
$acceptedType = $acceptedType instanceof \ReflectionNamedType ? $acceptedType->getName() : (string) $acceptedType; $acceptedType = $acceptedType instanceof \ReflectionNamedType ? $acceptedType->getName() : (string) $acceptedType;
$this->code = $type; $this->code = $type;
parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s::%s()" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $acceptedType, $type)); $function = $parameter->getDeclaringFunction();
$functionName = $function instanceof \ReflectionMethod
? sprintf('%s::%s', $function->getDeclaringClass()->getName(), $function->getName())
: $function->getName();
parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s()" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $functionName, $acceptedType, $type));
} }
} }

View File

@ -836,6 +836,22 @@ class CheckTypeDeclarationsPassTest extends TestCase
$this->addToAssertionCount(1); $this->addToAssertionCount(1);
} }
/**
* @requires PHP 8
*/
public function testUnionTypePassesWithFalse()
{
$container = new ContainerBuilder();
$container->register('union', UnionConstructor::class)
->setFactory([UnionConstructor::class, 'create'])
->setArguments([false]);
(new CheckTypeDeclarationsPass(true))->process($container);
$this->addToAssertionCount(1);
}
/** /**
* @requires PHP 8 * @requires PHP 8
*/ */
@ -851,8 +867,6 @@ class CheckTypeDeclarationsPassTest extends TestCase
$this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct()" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo" passed.'); $this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct()" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo" passed.');
(new CheckTypeDeclarationsPass(true))->process($container); (new CheckTypeDeclarationsPass(true))->process($container);
$this->addToAssertionCount(1);
} }
/** /**
@ -869,6 +883,57 @@ class CheckTypeDeclarationsPassTest extends TestCase
$this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct()" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "array" passed.'); $this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct()" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "array" passed.');
(new CheckTypeDeclarationsPass(true))->process($container); (new CheckTypeDeclarationsPass(true))->process($container);
}
/**
* @requires PHP 8
*/
public function testUnionTypeWithFalseFailsWithReference()
{
$container = new ContainerBuilder();
$container->register('waldo', Waldo::class);
$container->register('union', UnionConstructor::class)
->setFactory([UnionConstructor::class, 'create'])
->setArguments([new Reference('waldo')]);
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor::create()" accepts "array|false", "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo" passed.');
(new CheckTypeDeclarationsPass(true))->process($container);
}
/**
* @requires PHP 8
*/
public function testUnionTypeWithFalseFailsWithTrue()
{
$container = new ContainerBuilder();
$container->register('waldo', Waldo::class);
$container->register('union', UnionConstructor::class)
->setFactory([UnionConstructor::class, 'create'])
->setArguments([true]);
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor::create()" accepts "array|false", "boolean" passed.');
(new CheckTypeDeclarationsPass(true))->process($container);
}
/**
* @requires PHP 8
*/
public function testReferencePassesMixed()
{
$container = new ContainerBuilder();
$container->register('waldo', Waldo::class);
$container->register('union', UnionConstructor::class)
->setFactory([UnionConstructor::class, 'make'])
->setArguments([new Reference('waldo')]);
(new CheckTypeDeclarationsPass(true))->process($container);
$this->addToAssertionCount(1); $this->addToAssertionCount(1);
} }

View File

@ -0,0 +1,52 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Exception;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException;
final class InvalidParameterTypeExceptionTest extends TestCase
{
/**
* @dataProvider provideReflectionParameters
*/
public function testExceptionMessage(\ReflectionParameter $parameter, string $expectedMessage)
{
$exception = new InvalidParameterTypeException('my_service', 'int', $parameter);
self::assertSame($expectedMessage, $exception->getMessage());
}
public function provideReflectionParameters(): iterable
{
yield 'static method' => [
new \ReflectionParameter([MyClass::class, 'doSomething'], 0),
'Invalid definition for service "my_service": argument 1 of "Symfony\Component\DependencyInjection\Tests\Exception\MyClass::doSomething()" accepts "array", "int" passed.',
];
yield 'function' => [
new \ReflectionParameter(__NAMESPACE__.'\\myFunction', 0),
'Invalid definition for service "my_service": argument 1 of "Symfony\Component\DependencyInjection\Tests\Exception\myFunction()" accepts "array", "int" passed.',
];
}
}
class MyClass
{
public static function doSomething(array $arguments): void
{
}
}
function myFunction(array $arguments): void
{
}

View File

@ -7,4 +7,14 @@ class UnionConstructor
public function __construct(Foo|int $arg) public function __construct(Foo|int $arg)
{ {
} }
public static function create(array|false $arg): static
{
return new static(0);
}
public static function make(mixed $arg): static
{
return new static(0);
}
} }

View File

@ -14,7 +14,7 @@ where:
- `ACCESS_KEY` is your Google Chat access key - `ACCESS_KEY` is your Google Chat access key
- `ACCESS_TOKEN` is your Google Chat access token - `ACCESS_TOKEN` is your Google Chat access token
- `SPACE` is the Google Chat space - `SPACE` is the Google Chat space
- `THREAD_KEY` is the the Google Chat message thread to group messages into a single thread (optional) - `THREAD_KEY` is the Google Chat message thread to group messages into a single thread (optional)
Resources Resources
--------- ---------

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Notifier\Bridge\GoogleChat\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions; use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions;
class GoogleChatOptionsTest extends TestCase final class GoogleChatOptionsTest extends TestCase
{ {
public function testToArray() public function testToArray()
{ {

View File

@ -11,65 +11,46 @@
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Tests; namespace Symfony\Component\Notifier\Bridge\GoogleChat\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransportFactory; use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException; use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException; use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
use Symfony\Component\Notifier\Transport\Dsn;
final class GoogleChatTransportFactoryTest extends TestCase final class GoogleChatTransportFactoryTest extends TransportFactoryTestCase
{ {
public function testCreateWithDsn() /**
{ * @return GoogleChatTransportFactory
$factory = $this->createFactory(); */
public function createFactory(): TransportFactoryInterface
$transport = $factory->create(Dsn::fromString('googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY'));
$this->assertSame('googlechat://chat.googleapis.com/AAAAA_YYYYY', (string) $transport);
}
public function testCreateWithThreadKeyInDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg'));
$this->assertSame('googlechat://chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg', (string) $transport);
}
public function testCreateRequiresCredentials()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('googlechat://chat.googleapis.com/v1/spaces/AAAAA_YYYYY/messages'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('googlechat://host/path')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host/path')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://host/path'));
}
private function createFactory(): GoogleChatTransportFactory
{ {
return new GoogleChatTransportFactory(); return new GoogleChatTransportFactory();
} }
public function createProvider(): iterable
{
yield [
'googlechat://chat.googleapis.com/AAAAA_YYYYY',
'googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY',
];
yield [
'googlechat://chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg',
'googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg',
];
}
public function supportsProvider(): iterable
{
yield [true, 'googlechat://host/path'];
yield [false, 'somethingElse://host/path'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing credentials' => ['googlechat://chat.googleapis.com/v1/spaces/AAAAA_YYYYY/messages'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://host/path'];
}
} }

View File

@ -11,41 +11,37 @@
namespace Symfony\Component\Notifier\Bridge\Infobip\Tests; namespace Symfony\Component\Notifier\Bridge\Infobip\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Infobip\InfobipTransport; use Symfony\Component\Notifier\Bridge\Infobip\InfobipTransport;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
final class InfobipTransportTest extends TestCase final class InfobipTransportTest extends TransportTestCase
{ {
public function testToStringContainsProperties() /**
* @return InfobipTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{ {
$transport = $this->createTransport(); return (new InfobipTransport('authtoken', '0611223344', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
$this->assertSame('infobip://host.test?from=0611223344', (string) $transport);
} }
public function testSupportsMessageInterface() public function toStringProvider(): iterable
{ {
$transport = $this->createTransport(); yield ['infobip://host.test?from=0611223344', $this->createTransport()];
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
} }
public function testSendNonSmsMessageThrowsLogicException() public function supportedMessagesProvider(): iterable
{ {
$transport = $this->createTransport(); yield [new SmsMessage('0611223344', 'Hello!')];
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
} }
private function createTransport(): InfobipTransport public function unsupportedMessagesProvider(): iterable
{ {
return (new InfobipTransport('authtoken', '0611223344', $this->createMock(HttpClientInterface::class)))->setHost('host.test'); yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
} }
} }

View File

@ -2,55 +2,41 @@
namespace Symfony\Component\Notifier\Bridge\LinkedIn\Tests; namespace Symfony\Component\Notifier\Bridge\LinkedIn\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransportFactory; use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException; use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException; use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
use Symfony\Component\Notifier\Transport\Dsn;
final class LinkedInTransportFactoryTest extends TestCase final class LinkedInTransportFactoryTest extends TransportFactoryTestCase
{ {
public function testCreateWithDsn() /**
{ * @return LinkedInTransportFactory
$factory = $this->createFactory(); */
public function createFactory(): TransportFactoryInterface
$transport = $factory->create(Dsn::fromString('linkedin://accessToken:UserId@host.test'));
$this->assertSame('linkedin://host.test', (string) $transport);
}
public function testCreateWithOnlyAccessTokenOrUserIdThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('linkedin://AccessTokenOrUserId@default'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('linkedin://host/path')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host/path')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://accessToken:UserId@default'));
}
private function createFactory(): LinkedInTransportFactory
{ {
return new LinkedInTransportFactory(); return new LinkedInTransportFactory();
} }
public function createProvider(): iterable
{
yield [
'linkedin://host.test',
'linkedin://accessToken:UserId@host.test',
];
}
public function supportsProvider(): iterable
{
yield [true, 'linkedin://host'];
yield [false, 'somethingElse://host'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing account or user_id' => ['linkedin://AccessTokenOrUserId@default'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://accessToken:UserId@default'];
}
} }

View File

@ -0,0 +1,61 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Notifier\Bridge\Mobyt\Tests;
use Symfony\Component\Notifier\Bridge\Mobyt\MobytTransportFactory;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class MobytTransportFactoryTest extends TransportFactoryTestCase
{
/**
* @return MobytTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new MobytTransportFactory();
}
public function createProvider(): iterable
{
yield [
'mobyt://host.test?from=FROM&type_quality=LL',
'mobyt://accountSid:authToken@host.test?from=FROM',
];
yield [
'mobyt://host.test?from=FROM&type_quality=N',
'mobyt://accountSid:authToken@host.test?from=FROM&type_quality=N',
];
}
public function supportsProvider(): iterable
{
yield [true, 'mobyt://accountSid:authToken@host.test?from=FROM'];
yield [false, 'somethingElse://accountSid:authToken@host.test?from=FROM'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing token' => ['mobyt://host.test?from=FROM'];
yield 'missing option: from' => ['mobyt://accountSid:authToken@host'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://accountSid:authToken@host.test?from=FROM'];
yield ['somethingElse://accountSid:authToken@host.test']; // missing "from" option
}
}

View File

@ -0,0 +1,52 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Notifier\Bridge\Mobyt\Tests;
use Symfony\Component\Notifier\Bridge\Mobyt\MobytOptions;
use Symfony\Component\Notifier\Bridge\Mobyt\MobytTransport;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class MobytTransportTest extends TransportTestCase
{
/**
* @return MobytTransport
*/
public function createTransport(?HttpClientInterface $client = null, string $messageType = MobytOptions::MESSAGE_TYPE_QUALITY_LOW): TransportInterface
{
return (new MobytTransport('accountSid', 'authToken', 'from', $messageType, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
public function toStringProvider(): iterable
{
yield ['mobyt://host.test?from=from&type_quality=LL', $this->createTransport()];
yield ['mobyt://host.test?from=from&type_quality=N', $this->createTransport(null, MobytOptions::MESSAGE_TYPE_QUALITY_HIGH)];
}
public function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
}
public function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

@ -47,6 +47,10 @@ final class SlackTransport extends AbstractTransport
public function __toString(): string public function __toString(): string
{ {
if (null === $this->chatChannel) {
return sprintf('slack://%s', $this->getEndpoint());
}
return sprintf('slack://%s?channel=%s', $this->getEndpoint(), urlencode($this->chatChannel)); return sprintf('slack://%s?channel=%s', $this->getEndpoint(), urlencode($this->chatChannel));
} }

View File

@ -11,40 +11,37 @@
namespace Symfony\Component\Notifier\Bridge\Smsapi\Tests; namespace Symfony\Component\Notifier\Bridge\Smsapi\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Smsapi\SmsapiTransport; use Symfony\Component\Notifier\Bridge\Smsapi\SmsapiTransport;
use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage; use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
final class SmsapiTransportTest extends TestCase final class SmsapiTransportTest extends TransportTestCase
{ {
public function testToStringContainsProperties() /**
* @return SmsapiTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{ {
$transport = $this->createTransport(); return (new SmsapiTransport('testToken', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('test.host');
$this->assertSame('smsapi://test.host?from=testFrom', (string) $transport);
} }
public function testSupportsMessageInterface() public function toStringProvider(): iterable
{ {
$transport = $this->createTransport(); yield ['smsapi://test.host?from=testFrom', $this->createTransport()];
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
} }
public function testSendNonChatMessageThrows() public function supportedMessagesProvider(): iterable
{ {
$transport = $this->createTransport(); yield [new SmsMessage('0611223344', 'Hello!')];
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
} }
private function createTransport(): SmsapiTransport public function unsupportedMessagesProvider(): iterable
{ {
return (new SmsapiTransport('testToken', 'testFrom', $this->createMock(HttpClientInterface::class)))->setHost('test.host'); yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
} }
} }

View File

@ -50,7 +50,7 @@ final class TelegramTransportTest extends TransportTestCase
yield [$this->createMock(MessageInterface::class)]; yield [$this->createMock(MessageInterface::class)];
} }
public function testSendWithErrorResponseThrows() public function testSendWithErrorResponseThrowsTransportException()
{ {
$this->expectException(TransportException::class); $this->expectException(TransportException::class);
$this->expectExceptionMessageMatches('/testDescription.+testErrorCode/'); $this->expectExceptionMessageMatches('/testDescription.+testErrorCode/');

View File

@ -11,40 +11,37 @@
namespace Symfony\Component\Notifier\Bridge\Zulip\Tests; namespace Symfony\Component\Notifier\Bridge\Zulip\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransport; use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface; use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
final class ZulipTransportTest extends TestCase final class ZulipTransportTest extends TransportTestCase
{ {
public function testToStringContainsProperties() /**
* @return ZulipTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{ {
$transport = $this->createTransport(); return (new ZulipTransport('testEmail', 'testToken', 'testChannel', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('test.host');
$this->assertSame('zulip://test.host?channel=testChannel', (string) $transport);
} }
public function testSupportsChatMessage() public function toStringProvider(): iterable
{ {
$transport = $this->createTransport(); yield ['zulip://test.host?channel=testChannel', $this->createTransport()];
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
} }
public function testSendNonChatMessageThrows() public function supportedMessagesProvider(): iterable
{ {
$transport = $this->createTransport(); yield [new ChatMessage('Hello!')];
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
} }
private function createTransport(): ZulipTransport public function unsupportedMessagesProvider(): iterable
{ {
return (new ZulipTransport('testEmail', 'testToken', 'testChannel', $this->createMock(HttpClientInterface::class)))->setHost('test.host'); yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
} }
} }

View File

@ -12,7 +12,6 @@ CHANGELOG
----- -----
* [BC BREAK] The `TransportInterface::send()` and `AbstractTransport::doSend()` methods changed to return a `?SentMessage` instance instead of `void`. * [BC BREAK] The `TransportInterface::send()` and `AbstractTransport::doSend()` methods changed to return a `?SentMessage` instance instead of `void`.
* Added the Zulip notifier bridge
* The `EmailRecipientInterface` and `RecipientInterface` were introduced. * The `EmailRecipientInterface` and `RecipientInterface` were introduced.
* Added `email` and `phone` properties to `Recipient`. * Added `email` and `phone` properties to `Recipient`.
* [BC BREAK] Changed the type-hint of the `$recipient` argument in the `as*Message()` method * [BC BREAK] Changed the type-hint of the `$recipient` argument in the `as*Message()` method
@ -30,7 +29,6 @@ CHANGELOG
5.1.0 5.1.0
----- -----
* Added the Mattermost notifier bridge
* [BC BREAK] The `ChatMessage::fromNotification()` method's `$recipient` and `$transport` * [BC BREAK] The `ChatMessage::fromNotification()` method's `$recipient` and `$transport`
arguments were removed. arguments were removed.
* [BC BREAK] The `EmailMessage::fromNotification()` and `SmsMessage::fromNotification()` * [BC BREAK] The `EmailMessage::fromNotification()` and `SmsMessage::fromNotification()`

View File

@ -331,7 +331,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
} }
$cursor->hardRefTo = $refs[$r]; $cursor->hardRefTo = $refs[$r];
$cursor->hardRefHandle = $this->useRefHandles & $item->handle; $cursor->hardRefHandle = $this->useRefHandles & $item->handle;
$cursor->hardRefCount = $item->refCount; $cursor->hardRefCount = 0 < $item->handle ? $item->refCount : 0;
} }
$cursor->attr = $item->attr; $cursor->attr = $item->attr;
$type = $item->class ?: \gettype($item->value); $type = $item->class ?: \gettype($item->value);

View File

@ -143,13 +143,19 @@ class VarCloner extends AbstractCloner
if (Stub::ARRAY_ASSOC === $stub->class) { if (Stub::ARRAY_ASSOC === $stub->class) {
// Copies of $GLOBALS have very strange behavior, // Copies of $GLOBALS have very strange behavior,
// let's detect them with some black magic // let's detect them with some black magic
$a[$gid] = true; if (\PHP_VERSION_ID < 80100 && ($a[$gid] = true) && isset($v[$gid])) {
// Happens with copies of $GLOBALS
if (isset($v[$gid])) {
unset($v[$gid]); unset($v[$gid]);
$a = []; $a = [];
foreach ($v as $gk => &$gv) { foreach ($v as $gk => &$gv) {
if ($v === $gv) {
unset($v);
$v = new Stub();
$v->value = [$v->cut = \count($gv), Stub::TYPE_ARRAY => 0];
$v->handle = -1;
$gv = &$hardRefs[spl_object_id($v)];
$gv = $v;
}
$a[$gk] = &$gv; $a[$gk] = &$gv;
} }
unset($gv); unset($gv);

View File

@ -411,6 +411,7 @@ EOTXT
/** /**
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @requires PHP < 8.1
*/ */
public function testSpecialVars56() public function testSpecialVars56()
{ {
@ -425,11 +426,11 @@ array:3 [
] ]
] ]
1 => array:1 [ 1 => array:1 [
"GLOBALS" => &2 array:1 [ "GLOBALS" => & array:1 [ …1]
"GLOBALS" => &2 array:1 [&2] ]
] 2 => &3 array:1 [
"GLOBALS" => &3 array:1 [&3]
] ]
2 => &2 array:1 [&2]
] ]
EOTXT EOTXT
, ,
@ -440,6 +441,7 @@ EOTXT
/** /**
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @requires PHP < 8.1
*/ */
public function testGlobals() public function testGlobals()
{ {
@ -462,11 +464,11 @@ EOTXT
<<<'EOTXT' <<<'EOTXT'
array:2 [ array:2 [
1 => array:1 [ 1 => array:1 [
"GLOBALS" => &1 array:1 [ "GLOBALS" => & array:1 [ …1]
"GLOBALS" => &1 array:1 [&1] ]
] 2 => &2 array:1 [
"GLOBALS" => &2 array:1 [&2]
] ]
2 => &1 array:1 [&1]
] ]
EOTXT EOTXT
@ -556,6 +558,6 @@ EOTXT
return $var; return $var;
}; };
return [$var(), $GLOBALS, &$GLOBALS]; return eval('return [$var(), $GLOBALS, &$GLOBALS];');
} }
} }