8000 minor #36709 Fix tests (nicolas-grekas) · symfony/symfony@e024db7 · GitHub
[go: up one dir, main page]

Skip to content

Commit e024db7

Browse files
minor #36709 Fix tests (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- Fix tests | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 623e266 Fix tests
2 parents 02d9597 + 623e266 commit e024db7

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php

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

1212
namespace Symfony\Bridge\Twig\Tests\Extension;
1313

14+
use Symfony\Component\Form\Extension\Core< 8000 /span>\DataTransformer\PercentToLocalizedStringTransformer;
1415
use Symfony\Component\Form\Extension\Core\Type\PercentType;
1516
use Symfony\Component\Form\FormError;
1617
use Symfony\Component\Form\Tests\AbstractLayoutTest;
@@ -2211,7 +2212,7 @@ public function testPasswordWithMaxLength()
22112212

22122213
public function testPercent()
22132214
{
2214-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1);
2215+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1, ['rounding_mode' => PercentToLocalizedStringTransformer::ROUND_CEILING]);
22152216

22162217
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
22172218
'/div
@@ -2233,7 +2234,7 @@ public function testPercent()
22332234

22342235
public function testPercentNoSymbol()
22352236
{
2236-
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false]);
2237+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false, 'rounding_mode' => PercentToLocalizedStringTransformer::ROUND_CEILING]);
22372238
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
22382239
'/input
22392240
[@id="my&id"]
@@ -2247,7 +2248,7 @@ public function testPercentNoSymbol()
22472248

22482249
public function testPercentCustomSymbol()
22492250
{
2250-
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '']);
2251+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '', 'rounding_mode' => PercentToLocalizedStringTransformer::ROUND_CEILING]);
22512252
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
22522253
'/div
22532254
[@class="input-group"]

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4LayoutTest.php

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

1212
namespace Symfony\Bridge\Twig\Tests\Extension;
1313

14+
use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer;
1415
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
1516
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
1617
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@@ -1168,7 +1169,7 @@ public function testMoney()
11681169

11691170
public function testPercent()
11701171
{
1171-
$form = $this->factory->createNamed('name', PercentType::class, 0.1);
1172+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['rounding_mode' => PercentToLocalizedStringTransformer::ROUND_CEILING]);
11721173

11731174
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
11741175
'/div
@@ -1194,7 +1195,7 @@ public function testPercent()
11941195

11951196
public function testPercentNoSymbol()
11961197
{
1197-
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false]);
1198+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false, 'rounding_mode' => PercentToLocalizedStringTransformer::ROUND_CEILING]);
11981199
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
11991200
'/input
12001201
[@id="my&id"]
@@ -1208,7 +1209,7 @@ public function testPercentNoSymbol()
12081209

12091210
public function testPercentCustomSymbol()
12101211
{
1211-
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '']);
1212+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '', 'rounding_mode' => PercentToLocalizedStringTransformer::ROUND_CEILING]);
12121213
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
12131214
'/div
12141215
[@class="input-group"]

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

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

1414
use PHPUnit\Framework\SkippedTestError;
15+
use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer;
1516
use Symfony\Component\Form\Extension\Core\Type\PercentType;
1617
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
1718
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
@@ -1923,7 +1924,7 @@ public function testPasswordWithMaxLength()
19231924

19241925
public function testPercent()
19251926
{
1926-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1);
1927+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1, ['rounding_mode' => PercentToLocalizedStringTransformer::ROUND_CEILING]);
19271928

19281929
$this->assertWidgetMatchesXpath($form->createView(), [],
19291930
'/input
@@ -1939,7 +1940,7 @@ public function testPercentNoSymbol()
19391940
{
19401941
$this->requiresFeatureSet(403);
19411942

1942-
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false]);
1943+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false, 'rounding_mode' => PercentToLocalizedStringTransformer::ROUND_CEILING]);
19431944
$this->assertWidgetMatchesXpath($form->createView(), [],
19441945
'/input
19451946
[@type="text"]
@@ -1954,7 +1955,7 @@ public function testPercentCustomSymbol()
19541955
{
19551956
$this->requiresFeatureSet(403);
19561957

1957-
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '']);
1958+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '', 'rounding_mode' => PercentToLocalizedStringTransformer::ROUND_CEILING]);
19581959
$this->assertWidgetMatchesXpath($form->createView(), [],
19591960
'/input
19601961
[@type="text"]

src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Lock\Tests\Store;
1313

1414
use MongoDB\Client;
15+
use MongoDB\Driver\Exception\ConnectionTimeoutException;
1516
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1617
use Symfony\Component\Lock\Exception\NotSupportedException;
1718
use Symfony\Component\Lock\Key;
@@ -30,7 +31,11 @@ class MongoDbStoreTest extends AbstractStoreTest
3031
public static function setupBeforeClass(): void
3132
{
3233
$client = self::getMongoClient();
33-
$client->listDatabases();
34+
try {
35+
$client->listDatabases();
36+
} catch (ConnectionTimeoutException $e) {
37+
self::markTestSkipped('MongoDB server not found.');
38+
}
3439
}
3540

3641
private static function getMongoClient(): Client

src/Symfony/Component/String/ByteString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public function __construct(string $string = '')
4545
public static function fromRandom(int $length = 16, string $alphabet = null): self
4646
{
4747
if ($length <= 0) {
48-
throw new InvalidArgumentException(sprintf('Expected positive length value, got "%d".', $length));
48+
throw new InvalidArgumentException(sprintf('A strictly positive length is expected, "%d" given.', $length));
4949
}
5050

5151
$alphabet = $alphabet ?? self::ALPHABET_ALPHANUMERIC;
5252
$alphabetSize = \strlen($alphabet);
5353
$bits = (int) ceil(log($alphabetSize, 2.0));
5454
if ($bits <= 0 || $bits > 56) {
55-
throw new InvalidArgumentException('Expected $alphabet\'s length to be in [2^1, 2^56].');
55+
throw new InvalidArgumentException('The length of the alphabet must in the [2^1, 2^56] range.');
5656
}
5757

5858
$ret = '';

src/Symfony/Component/String/Tests/ByteStringTest.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Component\String\Tests;
1313

1414
use Symfony\Component\String\AbstractString;
15-
use function Symfony\Component\String\b;
1615
use Symfony\Component\String\ByteString;
16+
use Symfony\Component\String\Exception\InvalidArgumentException;
1717

1818
class ByteStringTest extends AbstractAsciiTestCase
1919
{
@@ -22,43 +22,46 @@ protected static function createFromString(string $string): AbstractString
2222
return new ByteString($string);
2323
}
2424

25-
public function testFromRandom(): void
25+
public function testFromRandom()
2626
{
2727
$random = ByteString::fromRandom(32);
2828

2929
self::assertSame(32, $random->length());
3030
foreach ($random->chunk() as $char) {
31-
self::assertNotNull(b('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')->indexOf($char));
31+
self::assertNotNull((new ByteString('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'))->indexOf($char));
3232
}
3333
}
3434

35-
public function testFromRandomWithSpecificChars(): void
35+
public function testFromRandomWithSpecificChars()
3636
{
3737
$random = ByteString::fromRandom(32, 'abc');
3838

3939
self::assertSame(32, $random->length());
4040
foreach ($random->chunk() as $char) {
41-
self::assertNotNull(b('abc')->indexOf($char));
41+
self::assertNotNull((new ByteString('abc'))->indexOf($char));
4242
}
4343
}
4444

45-
public function testFromRandomEarlyReturnForZeroLength(): void
45+
public function testFromRandoWithZeroLength()
4646
{
47+
$this->expectException(InvalidArgumentException::class);
48+
$this->expectExceptionMessage('A strictly positive length is expected, "0" given.');
49+
4750
self::assertSame('', ByteString::fromRandom(0));
4851
}
4952

50-
public function testFromRandomThrowsForNegativeLength(): void
53+
public function testFromRandomThrowsForNegativeLength()
5154
{
52-
$this->expectException(\RuntimeException::class);
53-
$this->expectExceptionMessage('Expected positive length value, got -1');
55+
$this->expectException(InvalidArgumentException::class);
56+
$this->expectExceptionMessage('A strictly positive length is expected, "-1" given.');
5457

5558
ByteString::fromRandom(-1);
5659
}
5760

58-
public function testFromRandomAlphabetMin(): void
61+
public function testFromRandomAlphabetMin()
5962
{
60-
$this->expectException(\RuntimeException::class);
61-
$this->expectExceptionMessage('Expected $alphabet\'s length to be in [2^1, 2^56]');
63+
$this->expectException(InvalidArgumentException::class);
64+
$this->expectExceptionMessage('The length of the alphabet must in the [2^1, 2^56] range.');
6265

6366
ByteString::fromRandom(32, 'a');
6467
}

0 commit comments

Comments
 (0)
0