8000 [Tests] Streamline · symfony/symfony@10b0f48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10b0f48

Browse files
committed
[Tests] Streamline
1 parent 0cd0c49 commit 10b0f48

File tree

114 files changed

+865
-586
lines changed
  • Loader
  • Normalizer
  • Stopwatch/Tests
  • Translation
  • Validator/Tests
  • Webhook/Tests/Client
  • Workflow/Tests
  • Yaml/Tests
  • Contracts
  • Some content is hidden

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

    114 files changed

    +865
    -586
    lines changed

    src/Symfony/Component/PasswordHasher/Tests/Command/UserPasswordHashCommandTest.php

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -277,10 +277,11 @@ public function testNonInteractiveEncodePasswordUsesFirstUserClass()
    277277

    278278
    public function testThrowsExceptionOnNoConfiguredHashers()
    279279
    {
    280+
    $tester = new CommandTester(new UserPasswordHashCommand($this->getMockBuilder(PasswordHasherFactoryInterface::class)->getMock(), []));
    281+
    280282
    $this->expectException(\RuntimeException::class);
    281283
    $this->expectExceptionMessage('There are no configured password hashers for the "security" extension.');
    282284

    283-
    $tester = new CommandTester(new UserPasswordHashCommand($this->getMockBuilder(PasswordHasherFactoryInterface::class)->getMock(), []));
    284285
    $tester->execute([
    285286
    'password' => 'password',
    286287
    ], ['interactive' => false]);

    src/Symfony/Component/PasswordHasher/Tests/Hasher/MessageDigestPasswordHasherTest.php

    Lines changed: 5 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -38,16 +38,19 @@ public function testHash()
    3838

    3939
    public function testHashAlgorithmDoesNotExist()
    4040
    {
    41-
    $this->expectException(\LogicException::class);
    4241
    $hasher = new MessageDigestPasswordHasher('foobar');
    42+
    43+
    $this->expectException(\LogicException::class);
    44+
    4345 $hasher->hash('password', '');
    4446
    }
    4547

    4648
    public function testHashLength()
    4749
    {
    48-
    $this->expectException(InvalidPasswordException::class);
    4950
    $hasher = new MessageDigestPasswordHasher();
    5051

    52+
    $this->expectException(InvalidPasswordException::class);
    53+
    5154
    $hasher->hash(str_repeat('a', 5000), 'salt');
    5255
    }
    5356

    src/Symfony/Component/PasswordHasher/Tests/Hasher/PasswordHasherFactoryTest.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -130,14 +130,16 @@ public function testGetNullNamedHasherForHasherAware()
    130130

    131131
    public function testGetInvalidNamedHasherForHasherAware()
    132132
    {
    133-
    $this->expectException(\RuntimeException::class);
    134133
    $factory = new PasswordHasherFactory([
    135134
    HasherAwareUser::class => new MessageDigestPasswordHasher('sha1'),
    136135
    'hasher_name' => new MessageDigestPasswordHasher('sha256'),
    137136
    ]);
    138137

    139138
    $user = new HasherAwareUser();
    140139
    $user->hasherName = 'invalid_hasher_name';
    140+
    141+
    $this->expectException(\RuntimeException::class);
    142+
    141143
    $factory->getPasswordHasher($user);
    142144
    }
    143145

    src/Symfony/Component/PasswordHasher/Tests/Hasher/Pbkdf2PasswordHasherTest.php

    Lines changed: 5 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -38,16 +38,19 @@ public function testHash()
    3838

    3939
    public function testHashAlgorithmDoesNotExist()
    4040
    {
    41-
    $this->expectException(\LogicException::class);
    4241
    $hasher = new Pbkdf2PasswordHasher('foobar');
    42+
    43+
    $this->expectException(\LogicException::class);
    44+
    4345
    $hasher->hash('password', '');
    4446
    }
    4547

    4648
    public function testHashLength()
    4749
    {
    48-
    $this->expectException(InvalidPasswordException::class);
    4950
    $hasher = new Pbkdf2PasswordHasher('foobar');
    5051

    52+
    $this->expectException(InvalidPasswordException::class);
    53+
    5154
    $hasher->hash(str_repeat('a', 5000), 'salt');
    5255
    }
    5356

    src/Symfony/Component/PasswordHasher/Tests/Hasher/SodiumPasswordHasherTest.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -52,8 +52,8 @@ public function testNonArgonValidation()
    5252
    public function testHashLength()
    5353
    {
    5454
    $this->expectException(InvalidPasswordException::class);
    55-
    $hasher = new SodiumPasswordHasher();
    56-
    $hasher->hash(str_repeat('a', 4097));
    55+
    56+
    (new SodiumPasswordHasher())->hash(str_repeat('a', 4097));
    5757
    }
    5858

    5959
    public function testCheckPasswordLength()

    src/Symfony/Component/Process/Tests/ProcessTest.php

    Lines changed: 37 additions & 17 deletions
    Original file line numberDiff line numberDiff line change
    @@ -328,11 +328,13 @@ public function testSetInputWhileRunningThrowsAnException()
    328328
    /**
    329329
    * @dataProvider provideInvalidInputValues
    330330
    */
    331-
    public function testInvalidInput($value)
    331+
    public function testInvalidInput(array|object $value)
    332332
    {
    333+
    $process = $this->getProcess('foo');
    334+
    333335
    $this->expectException(InvalidArgumentException::class);
    334336
    $this->expectExceptionMessage('"Symfony\Component\Process\Process::setInput" only accepts strings, Traversable objects or stream resources.');
    335-
    $process = $this->getProcess('foo');
    337+
    336338
    $process->setInput($value);
    337339
    }
    338340

    @@ -347,7 +349,7 @@ public static function provideInvalidInputValues()
    347349
    /**
    348350
    * @dataProvider provideInputValues
    349351
    */
    350-
    public function testValidInput($expected, $value)
    352+
    public function testValidInput(?string $expected, null|float|string $value)
    351353
    {
    352354
    $process = $this->getProcess('foo');
    353355
    $process->setInput($value);
    @@ -593,8 +595,10 @@ public function testSuccessfulMustRunHasCorrectExitCode()
    593595

    594596
    public function testMustRunThrowsException()
    595597
    {
    596-
    $this->expectException(ProcessFailedException::class);
    597598
    $process = $this->getProcess('exit 1');
    599+
    600+
    $this->expectException(ProcessFailedException::class);
    601+
    598602
    $process->mustRun();
    599603
    }
    600604

    @@ -972,9 +976,11 @@ public function testExitCodeIsAvailableAfterSignal()
    972976

    973977
    public function testSignalProcessNotRunning()
    974978
    {
    979+
    $process = $this->getProcess('foo');
    980+
    975981
    $this->expectException(LogicException::class);
    976982
    $this->expectExceptionMessage('Cannot send signal on a non running process.');
    977-
    $process = $this->getProcess('foo');
    983+
    978984
    $process->signal(1); // SIGHUP
    979985
    }
    980986

    @@ -1062,20 +1068,24 @@ public function testDisableOutputDisablesTheOutput()
    10621068

    10631069
    public function testDisableOutputWhileRunningThrowsException()
    10641070
    {
    1065-
    $this->expectException(RuntimeException::class);
    1066-
    $this->expectExceptionMessage('Disabling output while the process is running is not possible.');
    10671071
    $p = $this->getProcessForCode('sleep(39);');
    10681072
    $p->start();
    1073+
    1074+
    $this->expectException(RuntimeException::class);
    1075+
    $this->expectExceptionMessage('Disabling output while the process is running is not possible.');
    1076+
    10691077
    $p->disableOutput();
    10701078
    }
    10711079

    10721080
    public function testEnableOutputWhileRunningThrowsException()
    10731081
    {
    1074-
    $this->expectException(RuntimeException::class);
    1075-
    $this->expectExceptionMessage('Enabling output while the process is running is not possible.');
    10761082
    $p = $this->getProcessForCode('sleep(40);');
    10771083
    $p->disableOutput();
    10781084
    $p->start();
    1085+
    1086+
    $this->expectException(RuntimeException::class);
    1087+
    $this->expectExceptionMessage('Enabling output while the process is running is not possible.');
    1088+
    10791089
    $p->enableOutput();
    10801090
    }
    10811091

    @@ -1091,19 +1101,23 @@ public function testEnableOrDisableOutputAfterRunDoesNotThrowException()
    10911101

    10921102
    public function testDisableOutputWhileIdleTimeoutIsSet()
    10931103
    {
    1094-
    $this->expectException(LogicException::class);
    1095-
    $this->expectExceptionMessage('Output cannot be disabled while an idle timeout is set.');
    10961104
    $process = $this->getProcess('foo');
    10971105
    $process->setIdleTimeout(1);
    1106+
    1107+
    $this->expectException(LogicException::class);
    1108+
    $this->expectExceptionMessage('Output cannot be disabled while an idle timeout is set.');
    1109+
    10981110
    $process->disableOutput();
    10991111
    }
    11001112

    11011113
    public function testSetIdleTimeoutWhileOutputIsDisabled()
    11021114
    {
    1103-
    $this->expectException(LogicException::class);
    1104-
    $this->expectExceptionMessage('timeout cannot be set while the output is disabled.');
    11051115
    $process = $this->getProcess('foo');
    11061116
    $process->disableOutput();
    1117+
    1118+
    $this->expectException(LogicException::class);
    1119+
    $this->expectExceptionMessage('timeout cannot be set while the output is disabled.');
    1120+
    11071121
    $process->setIdleTimeout(1);
    11081122
    }
    11091123

    @@ -1119,11 +1133,13 @@ public function testSetNullIdleTimeoutWhileOutputIsDisabled()
    11191133
    */
    11201134
    public function testGetOutputWhileDisabled($fetchMethod)
    11211135
    {
    1122-
    $this->expectException(LogicException::class);
    1123-
    $this->expectExceptionMessage('Output has been disabled.');
    11241136
    $p = $this->getProcessForCode('sleep(41);');
    11251137
    $p->disableOutput();
    11261138
    $p->start();
    1139+
    1140+
    $this->expectException(LogicException::class);
    1141+
    $this->expectExceptionMessage('Output has been disabled.');
    1142+
    11271143
    $p->{$fetchMethod}();
    11281144
    }
    11291145

    @@ -1523,17 +1539,21 @@ public function testPreparedCommandWithQuoteInIt()
    15231539

    15241540
    public function testPreparedCommandWithMissingValue()
    15251541
    {
    1542+
    $p = Process::fromShellCommandline('echo "${:abc}"');
    1543+
    15261544
    $this->expectException(InvalidArgumentException::class);
    15271545
    $this->expectExceptionMessage('Command line is missing a value for parameter "abc": echo "${:abc}"');
    1528-
    $p = Process::fromShellCommandline('echo "${:abc}"');
    1546+
    15291547
    $p->run(null, ['bcd' => 'BCD']);
    15301548
    }
    15311549

    15321550
    public function testPreparedCommandWithNoValues()
    15331551
    {
    1552+
    $p = Process::fromShellCommandline('echo "${:abc}"');
    1553+
    15341554
    $this->expectException(InvalidArgumentException::class);
    15351555
    $this->expectExceptionMessage('Command line is missing a value for parameter "abc": echo "${:abc}"');
    1536-
    $p = Process::fromShellCommandline('echo "${:abc}"');
    1556+
    15371557
    $p->run(null, []);
    15381558
    }
    15391559

    src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayAccessTestCase.php

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -53,13 +53,14 @@ public function testGetValue($collection, $path, $value)
    5353

    5454
    public function testGetValueFailsIfNoSuchIndex()
    5555
    {
    56-
    $this->expectException(NoSuchIndexException::class);
    5756
    $this->propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
    5857
    ->enableExceptionOnInvalidIndex()
    5958
    ->getPropertyAccessor();
    6059

    6160
    $object = static::getContainer(['firstName' => 'Bernhard']);
    6261

    62+
    $this->expectException(NoSuchIndexException::class);
    63+
    6364
    $this->propertyAccessor->getValue($object, '[lastName]');
    6465
    }
    6566

    src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTestCase.php

    Lines changed: 5 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -156,8 +156,6 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections()
    156156

    157157
    public function testSetValueFailsIfNoAdderNorRemoverFound()
    158158
    {
    159-
    $this->expectException(NoSuchPropertyException::class);
    160-
    $this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTestCase_CarNoAdderAndRemover_[^"]*"./');
    161159
    $car = $this->createMock(__CLASS__.'_CarNoAdderAndRemover');
    162160
    $axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']);
    163161
    $axesAfter = $this->getContainer([0 => 'first', 1 => 'second', 2 => 'third']);
    @@ -166,6 +164,9 @@ public function testSetValueFailsIfNoAdderNorRemoverFound()
    166164
    ->method('getAxes')
    167165
    ->willReturn($axesBefore);
    168166

    167+
    $this->expectException(NoSuchPropertyException::class);
    168+
    $this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTestCase_CarNoAdderAndRemover_[^"]*"./');
    169+
    169170
    $this->propertyAccessor->setValue($car, 'axes', $axesAfter);
    170171
    }
    171172

    @@ -195,9 +196,10 @@ public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists()
    195196

    196197
    public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
    197198
    {
    199+
    $car = new PropertyAccessorCollectionTestCase_Car();
    200+
    198201
    $this->expectException(NoSuchPropertyException::class);
    199202
    $this->expectExceptionMessageMatches('/The property "axes" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\PropertyAccessorCollectionTestCase_Car" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\\Traversable\./');
    200-
    $car = new PropertyAccessorCollectionTestCase_Car();
    201203

    202204
    $this->propertyAccessor->setValue($car, 'axes', 'Not an array or Traversable');
    203205
    }

    0 commit comments

    Comments
     (0)
    0