Skip to content

[Tests] Streamline #52402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ public function testNonInteractiveEncodePasswordUsesFirstUserClass()

public function testThrowsExceptionOnNoConfiguredHashers()
{
$tester = new CommandTester(new UserPasswordHashCommand($this->getMockBuilder(PasswordHasherFactoryInterface::class)->getMock(), []));

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('There are no configured password hashers for the "security" extension.');

$tester = new CommandTester(new UserPasswordHashCommand($this->getMockBuilder(PasswordHasherFactoryInterface::class)->getMock(), []));
$tester->execute([
'password' => 'password',
], ['interactive' => false]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ public function testHash()

public function testHashAlgorithmDoesNotExist()
{
$this->expectException(\LogicException::class);
$hasher = new MessageDigestPasswordHasher('foobar');

$this->expectException(\LogicException::class);

$hasher->hash('password', '');
}

public function testHashLength()
{
$this->expectException(InvalidPasswordException::class);
$hasher = new MessageDigestPasswordHasher();

$this->expectException(InvalidPasswordException::class);

$hasher->hash(str_repeat('a', 5000), 'salt');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@ public function testGetNullNamedHasherForHasherAware()

public function testGetInvalidNamedHasherForHasherAware()
{
$this->expectException(\RuntimeException::class);
$factory = new PasswordHasherFactory([
HasherAwareUser::class => new MessageDigestPasswordHasher('sha1'),
'hasher_name' => new MessageDigestPasswordHasher('sha256'),
]);

$user = new HasherAwareUser();
$user->hasherName = 'invalid_hasher_name';

$this->expectException(\RuntimeException::class);

$factory->getPasswordHasher($user);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ public function testHash()

public function testHashAlgorithmDoesNotExist()
{
$this->expectException(\LogicException::class);
$hasher = new Pbkdf2PasswordHasher('foobar');

$this->expectException(\LogicException::class);

$hasher->hash('password', '');
}

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

$this->expectException(InvalidPasswordException::class);

$hasher->hash(str_repeat('a', 5000), 'salt');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function testNonArgonValidation()
public function testHashLength()
{
$this->expectException(InvalidPasswordException::class);
$hasher = new SodiumPasswordHasher();
$hasher->hash(str_repeat('a', 4097));

(new SodiumPasswordHasher())->hash(str_repeat('a', 4097));
}

public function testCheckPasswordLength()
Expand Down
54 changes: 37 additions & 17 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,13 @@ public function testSetInputWhileRunningThrowsAnException()
/**
* @dataProvider provideInvalidInputValues
*/
public function testInvalidInput($value)
public function testInvalidInput(array|object $value)
{
$process = $this->getProcess('foo');

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('"Symfony\Component\Process\Process::setInput" only accepts strings, Traversable objects or stream resources.');
$process = $this->getProcess('foo');

$process->setInput($value);
}

Expand All @@ -347,7 +349,7 @@ public static function provideInvalidInputValues()
/**
* @dataProvider provideInputValues
*/
public function testValidInput($expected, $value)
public function testValidInput(?string $expected, null|float|string $value)
{
$process = $this->getProcess('foo');
$process->setInput($value);
Expand Down Expand Up @@ -593,8 +595,10 @@ public function testSuccessfulMustRunHasCorrectExitCode()

public function testMustRunThrowsException()
{
$this->expectException(ProcessFailedException::class);
$process = $this->getProcess('exit 1');

$this->expectException(ProcessFailedException::class);

$process->mustRun();
}

Expand Down Expand Up @@ -972,9 +976,11 @@ public function testExitCodeIsAvailableAfterSignal()

public function testSignalProcessNotRunning()
{
$process = $this->getProcess('foo');

$this->expectException(LogicException::class);
$this->expectExceptionMessage('Cannot send signal on a non running process.');
$process = $this->getProcess('foo');

$process->signal(1); // SIGHUP
}

Expand Down Expand Up @@ -1062,20 +1068,24 @@ public function testDisableOutputDisablesTheOutput()

public function testDisableOutputWhileRunningThrowsException()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Disabling output while the process is running is not possible.');
$p = $this->getProcessForCode('sleep(39);');
$p->start();

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Disabling output while the process is running is not possible.');

$p->disableOutput();
}

public function testEnableOutputWhileRunningThrowsException()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Enabling output while the process is running is not possible.');
$p = $this->getProcessForCode('sleep(40);');
$p->disableOutput();
$p->start();

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Enabling output while the process is running is not possible.');

$p->enableOutput();
}

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

public function testDisableOutputWhileIdleTimeoutIsSet()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Output cannot be disabled while an idle timeout is set.');
$process = $this->getProcess('foo');
$process->setIdleTimeout(1);

$this->expectException(LogicException::class);
$this->expectExceptionMessage('Output cannot be disabled while an idle timeout is set.');

$process->disableOutput();
}

public function testSetIdleTimeoutWhileOutputIsDisabled()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('timeout cannot be set while the output is disabled.');
$process = $this->getProcess('foo');
$process->disableOutput();

$this->expectException(LogicException::class);
$this->expectExceptionMessage('timeout cannot be set while the output is disabled.');

$process->setIdleTimeout(1);
}

Expand All @@ -1119,11 +1133,13 @@ public function testSetNullIdleTimeoutWhileOutputIsDisabled()
*/
public function testGetOutputWhileDisabled($fetchMethod)
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Output has been disabled.');
$p = $this->getProcessForCode('sleep(41);');
$p->disableOutput();
$p->start();

$this->expectException(LogicException::class);
$this->expectExceptionMessage('Output has been disabled.');

$p->{$fetchMethod}();
}

Expand Down Expand Up @@ -1523,17 +1539,21 @@ public function testPreparedCommandWithQuoteInIt()

public function testPreparedCommandWithMissingValue()
{
$p = Process::fromShellCommandline('echo "${:abc}"');

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Command line is missing a value for parameter "abc": echo "${:abc}"');
$p = Process::fromShellCommandline('echo "${:abc}"');

$p->run(null, ['bcd' => 'BCD']);
}

public function testPreparedCommandWithNoValues()
{
$p = Process::fromShellCommandline('echo "${:abc}"');

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Command line is missing a value for parameter "abc": echo "${:abc}"');
$p = Process::fromShellCommandline('echo "${:abc}"');

$p->run(null, []);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ public function testGetValue($collection, $path, $value)

public function testGetValueFailsIfNoSuchIndex()
{
$this->expectException(NoSuchIndexException::class);
$this->propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
->enableExceptionOnInvalidIndex()
->getPropertyAccessor();

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

$this->expectException(NoSuchIndexException::class);

$this->propertyAccessor->getValue($object, '[lastName]');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections()

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

$this->expectException(NoSuchPropertyException::class);
$this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTestCase_CarNoAdderAndRemover_[^"]*"./');

$this->propertyAccessor->setValue($car, 'axes', $axesAfter);
}

Expand Down Expand Up @@ -195,9 +196,10 @@ public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists()

public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
{
$car = new PropertyAccessorCollectionTestCase_Car();

$this->expectException(NoSuchPropertyException::class);
$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\./');
$car = new PropertyAccessorCollectionTestCase_Car();

$this->propertyAccessor->setValue($car, 'axes', 'Not an array or Traversable');
}
Expand Down
Loading