Skip to content

Commit cf0738e

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Notifier][SMSBiuras] Fix CS Fix SmsBiurasTransportTest::testTestMode [Notifier][SmsBiuras] Simplify test and data provider [Notifier] [SMSBiuras] `true`/`false` mismatch for `test_mode` option [HttpKernel] Fix message for unresovable arguments of invokable controllers ignore const expressions read by phpdocumentor [DependencyInjection] Process bindings in ServiceLocatorTagPass
2 parents dc17291 + 5df5aa0 commit cf0738e

File tree

7 files changed

+88
-3
lines changed

7 files changed

+88
-3
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ServiceLocatorTagPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
4040
return self::register($this->container, $value->getValues());
4141
}
4242

43+
if ($value instanceof Definition) {
44+
$value->setBindings(parent::processValue($value->getBindings()));
45+
}
46+
4347
if (!$value instanceof Definition || !$value->hasTag('container.service_locator')) {
4448
return parent::processValue($value, $isRoot);
4549
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ public function testDefinitionOrderIsTheSame()
214214

215215
static::assertSame(['service-2', 'service-1'], array_keys($factories));
216216
}
217+
218+
public function testBindingsAreProcessed()
219+
{
220+
$container = new ContainerBuilder();
221+
222+
$definition = $container->register('foo')
223+
->setBindings(['foo' => new ServiceLocatorArgument()]);
224+
225+
(new ServiceLocatorTagPass())->process($container);
226+
227+
$this->assertInstanceOf(Reference::class, $definition->getBindings()['foo']->getValues()[0]);
228+
}
217229
}
218230

219231
class Locator

src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/NotTaggedControllerValueResolver.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
6969
}
7070

7171
if (!$this->container->has($controller)) {
72-
$i = strrpos($controller, ':');
73-
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
72+
$controller = (false !== $i = strrpos($controller, ':'))
73+
? substr($controller, 0, $i).strtolower(substr($controller, $i))
74+
: $controller.'::__invoke';
7475
}
7576

7677
$what = sprintf('argument $%s of "%s()"', $argument->getName(), $controller);

src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ public function testControllerNameIsAnArray()
9898
$resolver->resolve($request, $argument);
9999
}
100100

101+
public function testInvokableController()
102+
{
103+
$this->expectException(RuntimeException::class);
104+
$this->expectExceptionMessage('Could not resolve argument $dummy of "App\Controller\Mine::__invoke()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?');
105+
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([]));
106+
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
107+
$request = $this->requestWithAttributes(['_controller' => 'App\Controller\Mine']);
108+
$this->assertTrue($resolver->supports($request, $argument));
109+
$resolver->resolve($request, $argument);
110+
}
111+
101112
private function requestWithAttributes(array $attributes)
102113
{
103114
$request = Request::create('/');

src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function doSend(MessageInterface $message): SentMessage
8585
'apikey' => $this->apiKey,
8686
'message' => $message->getSubject(),
8787
'from' => $this->from,
88-
'test' => $this->testMode ? 0 : 1,
88+
'test' => $this->testMode ? 1 : 0,
8989
'to' => $message->getPhone(),
9090
],
9191
]);

src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\SmsBiuras\Tests;
1313

14+
use Symfony\Component\HttpClient\MockHttpClient;
1415
use Symfony\Component\Notifier\Bridge\SmsBiuras\SmsBiurasTransport;
1516
use Symfony\Component\Notifier\Message\ChatMessage;
1617
use Symfony\Component\Notifier\Message\MessageInterface;
1718
use Symfony\Component\Notifier\Message\SmsMessage;
1819
use Symfony\Component\Notifier\Test\TransportTestCase;
1920
use Symfony\Contracts\HttpClient\HttpClientInterface;
21+
use Symfony\Contracts\HttpClient\ResponseInterface;
2022

2123
final class SmsBiurasTransportTest extends TransportTestCase
2224
{
@@ -40,4 +42,48 @@ public function unsupportedMessagesProvider(): iterable
4042
yield [new ChatMessage('Hello!')];
4143
yield [$this->createMock(MessageInterface::class)];
4244
}
45+
46+
/**
47+
* @dataProvider provideTestMode()
48+
*/
49+
public function testTestMode(int $expected, bool $testMode)
50+
{
51+
$message = new SmsMessage('+37012345678', 'Hello World!');
52+
53+
$response = $this->createMock(ResponseInterface::class);
54+
$response->expects($this->atLeast(1))
55+
->method('getStatusCode')
56+
->willReturn(200);
57+
$response->expects($this->atLeast(1))
58+
->method('getContent')
59+
->willReturn('OK: 519545');
60+
61+
$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $message, $expected): ResponseInterface {
62+
$this->assertSame('GET', $method);
63+
$this->assertSame(sprintf(
64+
'https://savitarna.smsbiuras.lt/api?uid=uid&apikey=api_key&message=%s&from=from&test=%s&to=%s',
65+
rawurlencode($message->getSubject()),
66+
$expected,
67+
rawurlencode($message->getPhone())
68+
), $url);
69+
$this->assertSame($expected, $options['query']['test']);
70+
71+
$this->assertSame(200, $response->getStatusCode());
72+
$this->assertSame('OK: 519545', $response->getContent());
73+
74+
return $response;
75+
});
76+
77+
$transport = new SmsBiurasTransport('uid', 'api_key', 'from', $testMode, $client);
78+
79+
$sentMessage = $transport->send($message);
80+
81+
$this->assertSame('519545', $sentMessage->getMessageId());
82+
}
83+
84+
public static function provideTestMode(): iterable
85+
{
86+
yield [1, true];
87+
yield [0, false];
88+
}
4389
}

src/Symfony/Component/PropertyInfo/Util/PhpDocTypeHelper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\PropertyInfo\Util;
1313

14+
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
1415
use phpDocumentor\Reflection\PseudoTypes\List_;
1516
use phpDocumentor\Reflection\Type as DocType;
1617
use phpDocumentor\Reflection\Types\Array_;
@@ -39,6 +40,11 @@ final class PhpDocTypeHelper
3940
*/
4041
public function getTypes(DocType $varType): array
4142
{
43+
if ($varType instanceof ConstExpression) {
44+
// It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment
45+
return [];
46+
}
47+
4248
$types = [];
4349
$nullable = false;
4450

@@ -64,6 +70,11 @@ public function getTypes(DocType $varType): array
6470
for ($typeIndex = 0; $varType->has($typeIndex); ++$typeIndex) {
6571
$type = $varType->get($typeIndex);
6672

73+
if ($type instanceof ConstExpression) {
74+
// It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment
75+
return [];
76+
}
77+
6778
// If null is present, all types are nullable
6879
if ($type instanceof Null_) {
6980
$nullable = true;

0 commit comments

Comments
 (0)