Skip to content

Commit 0a96d33

Browse files
Merge branch '5.4' into 6.4
* 5.4: add German translations for the Week constraint messages sync Week constraint messages translations [Validator] Add `D` regex modifier in relevant validators [Validator] Add French translation for the `Week` constraint reject malformed URLs with a meaningful exception [Mime] Add tests on constraints
2 parents d5f7171 + 40b8e95 commit 0a96d33

File tree

83 files changed

+1325
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1325
-41
lines changed

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ private static function jsonEncode(mixed $value, ?int $flags = null, int $maxDep
557557
*/
558558
private static function resolveUrl(array $url, ?array $base, array $queryDefaults = []): array
559559
{
560+
$givenUrl = $url;
561+
560562
if (null !== $base && '' === ($base['scheme'] ?? '').($base['authority'] ?? '')) {
561563
throw new InvalidArgumentException(sprintf('Invalid "base_uri" option: host or scheme is missing in "%s".', implode('', $base)));
562564
}
@@ -610,6 +612,10 @@ private static function resolveUrl(array $url, ?array $base, array $queryDefault
610612
$url['query'] = null;
611613
}
612614

615+
if (null !== $url['scheme'] && null === $url['authority']) {
616+
throw new InvalidArgumentException(\sprintf('Invalid URL: host is missing in "%s".', implode('', $givenUrl)));
617+
}
618+
613619
return $url;
614620
}
615621

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpClient\Tests;
1313

1414
use Symfony\Component\HttpClient\Exception\ClientException;
15+
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
1516
use Symfony\Component\HttpClient\Exception\TransportException;
1617
use Symfony\Component\HttpClient\Internal\ClientState;
1718
use Symfony\Component\HttpClient\Response\StreamWrapper;
@@ -451,6 +452,16 @@ public function testNullBody()
451452
$this->expectNotToPerformAssertions();
452453
}
453454

455+
public function testMisspelledScheme()
456+
{
457+
$httpClient = $this->getHttpClient(__FUNCTION__);
458+
459+
$this->expectException(InvalidArgumentException::class);
460+
$this->expectExceptionMessage('Invalid URL: host is missing in "http:/localhost:8057/".');
461+
462+
$httpClient->request('GET', 'http:/localhost:8057/');
463+
}
464+
454465
/**
455466
* @dataProvider getRedirectWithAuthTests
456467
*/

src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ public function testResolveUrl(string $base, string $url, string $expected)
175175
public static function provideResolveUrl(): array
176176
{
177177
return [
178-
[self::RFC3986_BASE, 'http:h', 'http:h'],
179178
[self::RFC3986_BASE, 'g', 'http://a/b/c/g'],
180179
[self::RFC3986_BASE, './g', 'http://a/b/c/g'],
181180
[self::RFC3986_BASE, 'g/', 'http://a/b/c/g/'],
@@ -229,7 +228,6 @@ public static function provideResolveUrl(): array
229228
['http://u:p@a/b/c/d;p?q', '.', 'http://u:p@a/b/c/'],
230229
// path ending with slash or no slash at all
231230
['http://a/b/c/d/', 'e', 'http://a/b/c/d/e'],
232-
['http:no-slash', 'e', 'http:e'],
233231
// falsey relative parts
234232
[self::RFC3986_BASE, '//0', 'http://0/'],
235233
[self::RFC3986_BASE, '0', 'http://a/b/c/0'],

src/Symfony/Component/Mime/Tests/AddressTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public function testCreate()
4343
$this->assertEquals($a, Address::create('fabien@symfony.com'));
4444
}
4545

46+
public function testCreateWithInvalidFormat()
47+
{
48+
$this->expectException(InvalidArgumentException::class);
49+
$this->expectExceptionMessage('Could not parse "<fabien@symfony" to a "Symfony\Component\Mime\Address" instance.');
50+
51+
Address::create('<fabien@symfony');
52+
}
53+
4654
/**
4755
* @dataProvider fromStringProvider
4856
*/

src/Symfony/Component/Mime/Tests/Encoder/IdnAddressEncoderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Mime\Encoder;
12+
namespace Symfony\Component\Mime\Tests\Encoder;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mime\Encoder\IdnAddressEncoder;
1516

1617
class IdnAddressEncoderTest extends TestCase
1718
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mime\Tests\Encoder;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mime\Encoder\QpContentEncoder;
16+
17+
class QpContentEncoderTest extends TestCase
18+
{
19+
public function testReplaceLastChar()
20+
{
21+
$encoder = new QpContentEncoder();
22+
23+
$this->assertSame('message=09', $encoder->encodeString('message'.chr(0x09)));
24+
$this->assertSame('message=20', $encoder->encodeString('message'.chr(0x20)));
25+
}
26+
}

src/Symfony/Component/Mime/Tests/MessageTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ public function testGenerateMessageIdThrowsWhenHasFromButNoAddresses()
134134
$message->generateMessageId();
135135
}
136136

137+
public function testGenerateMessageIdThrowsWhenNeitherFromNorSenderIsPresent()
138+
{
139+
$message = new Message();
140+
141+
$this->expectException(LogicException::class);
142+
$this->expectExceptionMessage('An email must have a "From" or a "Sender" header.');
143+
144+
$message->generateMessageId();
145+
}
146+
137147
public function testToString()
138148
{
139149
$message = new Message();

src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,12 @@ public function testBoundaryContentTypeHeader()
243243
$headers[0]
244244
);
245245
}
246+
247+
public function testConstructThrowsOnUnexpectedFieldType()
248+
{
249+
$this->expectException(InvalidArgumentException::class);
250+
$this->expectExceptionMessage('A form field value can only be a string, an array, or an instance of TextPart ("stdClass" given).');
251+
252+
new FormDataPart(['foo' => new \stdClass()]);
253+
}
246254
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mime\Tests\Test\Constraint;
13+
14+
use PHPUnit\Framework\ExpectationFailedException;
15+
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\Mime\Email;
17+
use Symfony\Component\Mime\Header\Headers;
18+
use Symfony\Component\Mime\Test\Constraint\EmailAddressContains;
19+
20+
class EmailAddressContainsTest extends TestCase
21+
{
22+
public function testToString()
23+
{
24+
$constraint = new EmailAddressContains('headerName', 'expectedValue');
25+
26+
$this->assertSame('contains address "headerName" with value "expectedValue"', $constraint->toString());
27+
}
28+
29+
public function testFailureDescription()
30+
{
31+
$mailboxHeader = 'text@example.com';
32+
$headers = new Headers();
33+
$headers->addMailboxHeader($mailboxHeader, 'actualValue@example.com');
34+
35+
$this->expectException(ExpectationFailedException::class);
36+
$this->expectExceptionMessage('Failed asserting that the Email contains address "text@example.com" with value "expectedValue@example.com" (value is actualValue@example.com).');
37+
38+
(new EmailAddressContains($mailboxHeader, 'expectedValue@example.com'))->evaluate(new Email($headers));
39+
}
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mime\Tests\Test\Constraint;
13+
14+
use PHPUnit\Framework\ExpectationFailedException;
15+
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\Mime\Email;
17+
use Symfony\Component\Mime\Test\Constraint\EmailAttachmentCount;
18+
19+
class EmailAttachmentCountTest extends TestCase
20+
{
21+
public function testToString()
22+
{
23+
$constraint = new EmailAttachmentCount(1);
24+
25+
$this->assertSame('has sent "1" attachment(s)', $constraint->toString());
26+
}
27+
28+
public function testFailureDescription()
29+
{
30+
$email = new Email();
31+
$email->attach('attachment content', 'attachment.txt');
32+
33+
$this->expectException(ExpectationFailedException::class);
34+
$this->expectExceptionMessage('Failed asserting that the Email has sent "2" attachment(s).');
35+
36+
(new EmailAttachmentCount(2))->evaluate($email);
37+
}
38+
}

0 commit comments

Comments
 (0)