mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-24 17:15:36 +08:00
add data provider test
This commit is contained in:
@@ -56,7 +56,7 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Module\\": "src/Module",
|
"Module\\": "src/Module",
|
||||||
"Custom\\": "src/Custom",
|
"Custom\\": "src/Custom",
|
||||||
"ZM\\Tests\\": "tests"
|
"Tests\\": "tests"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bin": [
|
"bin": [
|
||||||
|
|||||||
67
tests/ZM/Utils/DataProviderTest.php
Normal file
67
tests/ZM/Utils/DataProviderTest.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\ZM\Utils;
|
||||||
|
|
||||||
|
use ZM\Utils\DataProvider;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class DataProviderTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetSourceRootDir(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(SOURCE_ROOT_DIR, DataProvider::getSourceRootDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetDataFolder(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(SOURCE_ROOT_DIR . '/zm_data/', DataProvider::getDataFolder());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetResourceFolder(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(SOURCE_ROOT_DIR . '/resources/', DataProvider::getResourceFolder());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanDirFiles(): void
|
||||||
|
{
|
||||||
|
$files = DataProvider::scanDirFiles(SOURCE_ROOT_DIR . '/src/Module');
|
||||||
|
$this->assertContains(SOURCE_ROOT_DIR . '/src/Module/Example/Hello.php', $files);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetFrameworkRootDir(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(FRAMEWORK_ROOT_DIR, DataProvider::getFrameworkRootDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetWorkingDir(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(SOURCE_ROOT_DIR, DataProvider::getWorkingDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSaveLoadJson(): void
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'a' => 1,
|
||||||
|
'b' => 2,
|
||||||
|
'c' => 3,
|
||||||
|
];
|
||||||
|
$file = 'test.json';
|
||||||
|
DataProvider::saveToJson($file, $data);
|
||||||
|
$this->assertEquals($data, DataProvider::loadFromJson($file));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetFrameworkLink(): void
|
||||||
|
{
|
||||||
|
$this->assertNotFalse(filter_var(DataProvider::getFrameworkLink(), FILTER_VALIDATE_URL));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsRelativePath(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(DataProvider::isRelativePath('./'));
|
||||||
|
$this->assertTrue(DataProvider::isRelativePath('../'));
|
||||||
|
$this->assertFalse(DataProvider::isRelativePath('/'));
|
||||||
|
$this->assertFalse(DataProvider::isRelativePath('test.php'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ZM\Tests\ZM\Utils;
|
namespace Tests\ZM\Utils;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use ZM\Annotation\CQ\CQCommand;
|
use ZM\Annotation\CQ\CQCommand;
|
||||||
@@ -147,6 +147,7 @@ class MessageUtilTest extends TestCase
|
|||||||
public function providerTestSplitCommand(): array
|
public function providerTestSplitCommand(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'empty' => ['', ['']],
|
||||||
'spaced' => ['hello world', ['hello', 'world']],
|
'spaced' => ['hello world', ['hello', 'world']],
|
||||||
'multiline' => ["hello\nworld", ['hello', 'world']],
|
'multiline' => ["hello\nworld", ['hello', 'world']],
|
||||||
'many spaces' => ['hello world', ['hello', 'world']],
|
'many spaces' => ['hello world', ['hello', 'world']],
|
||||||
|
|||||||
Reference in New Issue
Block a user