2021-04-24 16:39:56 -07:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Tests\Unit\Helpers;
|
2021-04-24 16:39:56 -07:00
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Tests\TestCase;
|
2024-08-09 08:23:03 +02:00
|
|
|
use App\Traits\EnvironmentWriterTrait;
|
2025-01-30 16:39:17 -05:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
2021-04-24 16:39:56 -07:00
|
|
|
|
|
|
|
|
class EnvironmentWriterTraitTest extends TestCase
|
|
|
|
|
{
|
2025-01-30 16:39:17 -05:00
|
|
|
#[DataProvider('variableDataProvider')]
|
2024-03-19 21:12:27 -04:00
|
|
|
public function testVariableIsEscapedProperly($input, $expected): void
|
2021-04-24 16:39:56 -07:00
|
|
|
{
|
|
|
|
|
$output = (new FooClass())->escapeEnvironmentValue($input);
|
|
|
|
|
|
|
|
|
|
$this->assertSame($expected, $output);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 12:30:16 -07:00
|
|
|
public static function variableDataProvider(): array
|
2021-04-24 16:39:56 -07:00
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
['foo', 'foo'],
|
|
|
|
|
['abc123', 'abc123'],
|
|
|
|
|
['val"ue', '"val\"ue"'],
|
2024-10-08 23:46:06 +02:00
|
|
|
['val\'ue', '"val\'ue"'],
|
2021-04-24 16:39:56 -07:00
|
|
|
['my test value', '"my test value"'],
|
|
|
|
|
['mysql_p@assword', '"mysql_p@assword"'],
|
|
|
|
|
['mysql_p#assword', '"mysql_p#assword"'],
|
|
|
|
|
['mysql p@$$word', '"mysql p@$$word"'],
|
|
|
|
|
['mysql p%word', '"mysql p%word"'],
|
|
|
|
|
['mysql p#word', '"mysql p#word"'],
|
|
|
|
|
['abc_@#test', '"abc_@#test"'],
|
|
|
|
|
['test 123 $$$', '"test 123 $$$"'],
|
|
|
|
|
['#password%', '"#password%"'],
|
|
|
|
|
['$pass ', '"$pass "'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class FooClass
|
|
|
|
|
{
|
|
|
|
|
use EnvironmentWriterTrait;
|
|
|
|
|
}
|