PHP Development တွင် strat_split တွင် stringsplit သည် strings များကို array များထဲသို့ခွဲရန်အသုံးပြုသောအလွန်အသုံးများသော string function တစ်ခုဖြစ်သည်။ Array Electric သည်မူလ string တစ်ခုစီပါရှိသည်။ ပုံမှန်အားဖြင့်ကျွန်ုပ်တို့သည်၎င်း၏ code အတွက်ယူနစ်စစ်ဆေးမှုများပြုလုပ်လိုသည်။ ဤဆောင်းပါးသည် PHP တွင် str'split function အတွက်ယူနစ်စစ်ဆေးမှုများကိုမည်သို့ရေးရမည်ကိုမိတ်ဆက်ပေးပြီးဘုံစမ်းသပ်မှုအခြေအနေအချို့ကိုပြသသည်။
ပထမ ဦး စွာ str'split function ၏အခြေခံအသုံးပြုမှုကိုလျင်မြန်စွာပြန်လည်သုံးသပ်ကြပါစို့။ stract_split function သည် string ကိုသတ်မှတ်ထားသောအရှည်ရှိအလျားများသို့ခွဲ ထား. ခင်းကျင်းမှုကိုပြန်ပို့သည်။ အခြေခံ syntax သည်အောက်ပါအတိုင်းဖြစ်သည် -
array str_split ( string $string [, int $length = 1 ] )
$ string : အုပ်စုခွဲခံရဖို့ input string ကို။
$ အရှည် (optional): အလားတူတစ်ခုချင်းစီ၏အရှည်, ပုံမှန် 1 မှ 1 ။
$string = "HelloWorld";
$split = str_split($string, 2);
print_r($split);
ထုတ်လုပ်မှု -
Array
(
[0] => He
[1] => ll
[2] => oW
[3] => or
[4] => ld
)
ဤဥပမာတွင် string_split သည် string ကို "Helloworld" ကိုဇာတ်ကောင်နှစ် ဦး ပါ 0 င်သည်။
ယူနစ်စမ်းသပ်မှုများကိုရေးရန် PHP အတွက်စံယူနစ်အတွက် PHPunit ကိုပထမ ဦး ဆုံးထည့်သွင်းရန်လိုအပ်သည်။ phpopunit ကိုတေးရေးဆရာမှတဆင့် install လုပ်နိုင်သည်။
composer require --dev phpunit/phpunit
တပ်ဆင်ပြီးသည်နှင့်ကျွန်ုပ်တို့သည် Phpunit ကိုကျွန်ုပ်တို့၏ယူနစ်စစ်ဆေးမှုများပြုလုပ်ရန် command line မှတဆင့် run နိုင်သည်။
ထို့နောက်ကျွန်ုပ်တို့သည် strow_Split function ၏အပြုအမူကိုစမ်းသပ်ရန် Phpunit Test Class ကိုရေးပါမည်။ ရိုးရိုးရှင်းရှင်းအနေဖြင့်ကျွန်ုပ်တို့သည်အခြေခံစာမေးပွဲအတန်းကိုဖန်တီးပြီးဘုံစမ်းသပ်မှုအခြေအနေများအတွက်စမ်းသပ်မှုနည်းလမ်းများရေးပါမည်။
ပထမ ဦး စွာစမ်းသပ်ဖိုင် strsplittest.php ကို ဖန်တီးပါ။
<?php
use PHPUnit\Framework\TestCase;
class StrSplitTest extends TestCase
{
// စမ်းသပ်မှု str_split အခြေခံလုပ်ဆောင်ချက်များကို
public function testBasicFunctionality()
{
$result = str_split("HelloWorld", 2);
$expected = ['He', 'll', 'oW', 'or', 'ld'];
$this->assertEquals($expected, $result);
}
// စမ်းသပ်မှု传递空字符串时的返回值
public function testEmptyString()
{
$result = str_split("", 2);
$this->assertEquals([], $result);
}
// စမ်းသပ်မှု传递单字符字符串时的返回值
public function testSingleCharacterString()
{
$result = str_split("A");
$this->assertEquals(['A'], $result);
}
// စမ်းသပ်မှု使用默认长度 1 အခြေအနေ
public function testDefaultLength()
{
$result = str_split("Hello");
$expected = ['H', 'e', 'l', 'l', 'o'];
$this->assertEquals($expected, $result);
}
// စမ်းသပ်မှု长度大于字符串长度时的行为
public function testLengthGreaterThanString()
{
$result = str_split("Hi", 10);
$this->assertEquals(['Hi'], $result);
}
// စမ်းသပ်မှု没有传递长度参数时,ပုံမှန်အပြုအမူကိုသုံးပါ
public function testWithoutLength()
{
$result = str_split("abcdef");
$this->assertEquals(['a', 'b', 'c', 'd', 'e', 'f'], $result);
}
}
TestbasicFUnctionity : စံ strings ၏ splitting စစ်ဆေးပါ။
TestemptyString - အချည်းနှီးသော string တစ်ခု၏ဖြစ်ရပ်ကိုစမ်းသပ်ရန်အတွက်အချည်းနှီးသောခင်းကျင်းမှုကိုပြန်ပို့သင့်သည်။
TestSingLecharacterString - ဇာတ်ကောင်တစ်မျိုးတည်းဖြင့် string ကိုစမ်းသပ်သည်။
testdefaultlllength - အရှည်မထောက်ပံ့သောအခါ string ကို default length 1 ကိုခွဲခြားရန်ဖြစ်စေစမ်းပါ။
testlimageReaterthanstring : split length သည် string အရှည်ထက် သာ. ကြီးသောအခါပြည့်စုံသော string ကိုသာပြန်လာသင့်သည်ကိုစစ်ဆေးပါ။
TestWithoutength - အရှည်မကုန်တော့သည့်အခါ default အရှည် 1 အရခွဲခြားရန်မအောင်မြင်ပါ။
အထက်ပါစာမေးပွဲအတန်းပြီးဆုံးပြီးနောက် Phpunit ကို အသုံးပြု. ယူနစ်စစ်ဆေးမှုများကိုအသုံးပြုရန်သင်အသုံးပြုနိုင်သည်။ Terminal ကိုဖွင့်ပါ, စီမံကိန်းလမ်းညွှန်ကိုရိုက်ထည့်ပြီးအောက်ပါ command ကို Execute လုပ်ပါ။
./vendor/bin/phpunit StrSplitTest.php
အရာအားလုံးအဆင်ပြေမယ်ဆိုရင်စစ်ဆေးမှုအားလုံးကုန်သွားပြီဆိုတာကိုအောက်ပါစမ်းသပ်မှုရလဒ်ကိုတွေ့ရလိမ့်မယ်။
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
......
Time: 00:00.029, Memory: 6.00 MB
OK (6 tests, 6 assertions)
ယူနစ်စမ်းသပ်မှုများရေးသားခြင်းအားဖြင့်ကျွန်ုပ်တို့သည်ကိစ္စရပ်အားလုံးတွင် str'split function ကိုစနစ်တကျအလုပ်လုပ်ရန်သေချာစေနိုင်သည်။ ယူနစ်စစ်ဆေးခြင်းသည်ကျွန်ုပ်တို့အားအလားအလာရှိသောပြ problems နာများကိုရှာဖွေတွေ့ရှိရန်သာမကကုဒ် refactoring အတွက်အာမခံချက်များပေးထားသည်။ PHP ရှိ str'split functions များအတွက်ယူနစ်စစ်ဆေးမှုများကိုမည်သို့ရေးရမည်ကိုနားလည်ရန်မျှော်လင့်ပါသည်။