add dataProvider to test buildFileName and fix related errors
This commit is contained in:
parent
20f962b26d
commit
6d3158a5c7
2 changed files with 43 additions and 11 deletions
|
|
@ -27,6 +27,7 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
class SettingsTest extends TestCase
|
||||
{
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
$cfg = new Settings();
|
||||
|
|
@ -100,17 +101,48 @@ class SettingsTest extends TestCase
|
|||
$this->assertEquals(42, $cfg->answer);
|
||||
}
|
||||
|
||||
public function testBuildFileName()
|
||||
/**
|
||||
* @depends testConstruct
|
||||
* @dataProvider fileNameData
|
||||
*/
|
||||
public function testBuildFileName(string $prefix, $type, string $site, string $expected, Settings $cfg)
|
||||
{
|
||||
$path = './config/';
|
||||
$prefix = '';
|
||||
$postfix = 'conf.php';
|
||||
$type = '';
|
||||
$defaultName = "$path$prefix$type$postfix";
|
||||
|
||||
$cfg = new Settings();
|
||||
|
||||
$this->assertEquals($defaultName, $cfg->buildFileName());
|
||||
$cfg->appPath('./');
|
||||
if ($prefix !== '') $cfg->prefix($prefix);
|
||||
if ($site !== '')
|
||||
{
|
||||
$cfg->prefix();
|
||||
$cfg->site($site);
|
||||
}
|
||||
|
||||
$this->assertEquals($path.$expected, $cfg->buildFileName($type));
|
||||
}
|
||||
|
||||
public function fileNameData()
|
||||
{
|
||||
return [
|
||||
// prefix, type, 'site', 'expected'
|
||||
['', '', '', 'conf.php' ],
|
||||
['', 'default', '', 'default.conf.php' ],
|
||||
['', 'testing', '', 'testing.conf.php' ],
|
||||
['MyPrefix', '', '', 'MyPrefix.conf.php' ],
|
||||
['MyPrefix', 'default', '', 'MyPrefix.default.conf.php' ],
|
||||
['MyPrefix', 'testing', '', 'MyPrefix.testing.conf.php' ],
|
||||
['_', '', '', '_.conf.php' ],
|
||||
['_', 'default', '', '_.default.conf.php' ],
|
||||
['_', 'testing', '', '_.testing.conf.php' ],
|
||||
['1', '', '', '1.conf.php' ],
|
||||
['1', 'default', '', '1.default.conf.php' ],
|
||||
['1', 'testing', '', '1.testing.conf.php' ],
|
||||
['other', '', '', 'other.conf.php' ],
|
||||
['other', 'default', '', 'other.default.conf.php' ],
|
||||
['other', 'testing', '', 'other.testing.conf.php' ],
|
||||
|
||||
['', 0x01, '13', '13/conf.php' ],
|
||||
['', 0x01, 'a_site', 'a_site/conf.php' ],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue