<?php

use Bat\StringTool;
use PhpBeast\AuthorTestAggregator;
use PhpBeast\PrettyTestInterpreter;
require_once "bigbang.php";
//------------------------------------------------------------------------------/
// EXHAUSTING TEST DEMO
//------------------------------------------------------------------------------/
$agg = AuthorTestAggregator::create();
$a = ['hello68', 'hello', 'hello-78.79', '123'];
$b = [['hello', 68], ['hello', false], ['hello-78.', 79], ['', 123]];
$agg->addTestsByColumn($a, $b, function ($value, $expected, &$msg) {
    $res = StringTool::cutNumericalSuffix($value);
    return $expected === $res;
});
PrettyTestInterpreter::create()->execute($agg);
<?php

use Bat\StringTool;
use PhpBeast\AuthorTestAggregator;
use PhpBeast\PrettyTestInterpreter;
require_once "bigbang.php";
//------------------------------------------------------------------------------/
// EXHAUSTING TEST DEMO
//------------------------------------------------------------------------------/
$agg = AuthorTestAggregator::create();
$a = [['Hum, hello, did you hear me say hello?', 'hello', 0], ["Cet été, il faisait beau. Cet été c'était bien.", 'été', 0], ["Cet été, il faisait beau. Cet été c'était bien.", 'été', 4], ["Cet été, il faisait beau. Cet été c'était bien.", 'été', 5], ["Cet été, il faisait beau. Cet été c'était bien.", 'été', 0, 'iso-8859-1']];
$b = [[5, 32], [4, 30], [4, 30], [30], [4, 32]];
$agg->addTestsByColumn($a, $b, function ($value, $expected, &$msg) {
    $encoding = 'utf-8';
    if (array_key_exists(3, $value)) {
        $encoding = $value[3];
    }
    mb_internal_encoding($encoding);
    list($haystack, $needle, $offset) = $value;
    $res = StringTool::strPosAll($haystack, $needle, $offset);
    return $expected === $res;
});
PrettyTestInterpreter::create()->execute($agg);
<?php

use Bat\FileSystemTool;
use Bat\StringTool;
use PhpBeast\AuthorTestAggregator;
use PhpBeast\PrettyTestInterpreter;
require_once "bigbang.php";
//------------------------------------------------------------------------------/
//
//------------------------------------------------------------------------------/
$agg = AuthorTestAggregator::create();
$a = [['', 0, 0, ''], ['abcdefgh', 0, 0, ''], ['abcdefgh', 0, 1, ''], ['abcdefgh', 0, 1, 'ppp'], ['abcdefgh', 2, 1, 'ppp'], ['aéliope', 2, 1, 'ppp'], ['aéliope', 2, 4, 'ppp']];
$b = ['', 'abcdefgh', 'bcdefgh', 'pppbcdefgh', 'abpppdefgh', 'aépppiope', 'aépppe'];
$agg->addTestsByColumn($a, $b, function ($value, $expected, &$msg) {
    list($string, $start, $length, $replacement) = $value;
    $res = StringTool::replacePortion($string, $start, $length, $replacement);
    return $expected === $res;
});
PrettyTestInterpreter::create()->execute($agg);
<?php

use Bat\StringTool;
use PhpBeast\AuthorTestAggregator;
use PhpBeast\PrettyTestInterpreter;
require_once "bigbang.php";
$agg = AuthorTestAggregator::create();
$a = ['camelCase', 'thisIsNotCorrect', 'simpleXML', 'localDb2Remote', 'notFound404'];
$b = ['CAMEL_CASE', 'THIS_IS_NOT_CORRECT', 'SIMPLE_XML', 'LOCAL_DB_2_REMOTE', 'NOT_FOUND_404'];
$c = [456, null, true, false];
$agg->addTestsByColumn($a, $b, function ($value, $expected, &$msg) {
    $res = StringTool::camelCase2Constant($value);
    return $expected === $res;
});
$agg->addExceptionTests($c, function ($v) {
    StringTool::camelCase2Constant($v);
}, ['0-2' => 'InvalidArgumentException', '3' => ['msgSub' => 'argument']]);
PrettyTestInterpreter::create()->execute($agg);
Пример #5
0
 /**
  * @return mixed
  */
 public function getValue($line)
 {
     return StringTool::autoCast($line);
 }
<?php

use Bat\FileSystemTool;
use Bat\StringTool;
use PhpBeast\AuthorTestAggregator;
use PhpBeast\PrettyTestInterpreter;
require_once "bigbang.php";
$agg = AuthorTestAggregator::create();
$a = [[], ['required'], ['class' => 'doo'], ['class' => 'doo', 'required', "id" => "foo"], ['src' => '/cet-été/dummy']];
$b = ['', ' required', ' class="doo"', ' class="doo" required id="foo"', ' src="/cet-été/dummy"'];
$agg->addTestsByColumn($a, $b, function ($value, $expected, &$msg) {
    $res = StringTool::htmlAttributes($value);
    return $expected === $res;
});
PrettyTestInterpreter::create()->execute($agg);