Skip to content

Commit

Permalink
feat(tests): Add new test file for SudoPassword
Browse files Browse the repository at this point in the history
- Add HasSudoPasswordTest.php for testing set and get methods of SudoPassword.
- Add test for checking the type of escapedSudoPassword.
  • Loading branch information
guanguans committed Jul 14, 2023
1 parent 55def24 commit 7bab1d4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
],
StaticClosureRector::class => [
__DIR__.'/tests/Concerns/WithRunableTest.php',
__DIR__.'/tests/Concerns/HasSudoPasswordTest.php',
],
StrictArrayParamDimFetchRector::class => [
__DIR__.'/src/Concerns/WithDumpable.php',
Expand Down
42 changes: 42 additions & 0 deletions tests/Concerns/HasSudoPasswordTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/**
* This file is part of the guanguans/soar-php.
*
* (c) guanguans <[email protected]>
*
* This source file is subject to the MIT license that is bundled.
*/

namespace Guanguans\Tests\Concerns;

use Guanguans\SoarPHP\Soar;
use Guanguans\Tests\TestCase;

/**
* @internal
*
* @small
*/
class HasSudoPasswordTest extends TestCase
{
public function testSetSudoPassword(): void
{
$soar = Soar::create();
$soar->setSudoPassword($sudoPassword = 'foo');

$this->assertSame($sudoPassword, $soar->getSudoPassword());
}

public function testGetEscapedSudoPassword(): void
{
$soar = Soar::create();
$escapedSudoPassword = (function (Soar $soar): string {
return $soar->getEscapedSudoPassword();
})->call($soar, $soar);

$this->assertIsString($escapedSudoPassword);
}
}
25 changes: 23 additions & 2 deletions tests/Concerns/WithRunableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class WithRunableTest extends TestCase
{
public function testInvalidArgumentExceptionForExec(): void
public function testInvalidArgumentExceptionForRun(): void
{
$soar = Soar::create();
$optionsOfError = true;
Expand All @@ -35,7 +35,7 @@ public function testInvalidArgumentExceptionForExec(): void
$soar->run($optionsOfError);
}

public function testProcessFailedExceptionForExec(): void
public function testProcessFailedExceptionForRun(): void
{
$soar = Soar::create();
$optionsOfError = 'optionsOfError';
Expand All @@ -45,6 +45,27 @@ public function testProcessFailedExceptionForExec(): void
$soar->setOnlySyntaxCheck(true)->setQuery($optionsOfError)->run();
}

public function testMisuseOfShellBuiltinsProcessFailedExceptionForRun(): void
{
$soar = new class() extends Soar {
protected function shouldApplySudoPassword(): bool
{
return true;
}
};
$fatalErrorMessages = [
'sudo',
'password',
];

$this->expectException(ProcessFailedException::class);
foreach ($fatalErrorMessages as $fatalErrorMessage) {
// $this->expectExceptionMessage($fatalErrorMessage);
}

$soar->setSudoPassword('foo')->setQuery('select bar;')->run();
}

/**
* @noinspection ForgottenDebugOutputInspection
* @noinspection DebugFunctionUsageInspection
Expand Down

0 comments on commit 7bab1d4

Please sign in to comment.