/iaLib/ia_examples/ia/Util/FormatIt_example.php
<?php
$ia_example = [
'title' => 'ia\Util\FormatIt', // fully qualified className
'summary' => '', // class summary
'full_example' => '', // full usage example, relative path from ia_examples, blank '' not shown.
'example_file' => 'code/ia/Util/FormatIt_example_code.php', // method by method example, blank '' not shown.
];
include( __DIR__ . '/../../template/ia_example_class.php');
/iaLib/ia_examples/code/ia/Util/FormatIt_example_code.php
use ia\Util\FormatIt;
use ia\DocumentIt\DocumentIt;
echo '<h3>Disclaimer: Auto generated file.
Please help us setting parameters to useful values and extending the examples.
</h3>';
try {
echo '<ul class="usage">';
///////// FormatIt::numberClean(null /* == */); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_numberClean'><b>FormatIt::numberClean(<span class="type"></span> \$s) <span>: </span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("ia\Util\FormatIt", "numberClean")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>FormatIt::numberClean(null /* == */);
-> </b><br><pre>
DOCUMENT_EXAMPLE;
/// run ///
print_r(
FormatIt::numberClean(null /* == */)
);
echo "</pre>";
echo '</ol>';
///////// FormatIt::number_format(null /* == */); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_number_format'><b>FormatIt::number_format(<span class="type"></span> \$number, <span class="type"></span> \$decimals <span class="default">= 0</span>, <span class="type"></span> \$dec_point <span class="default">= '.'</span>, <span class="type"></span> \$thousand_sep <span class="default">= ','</span>) <span>: </span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("ia\Util\FormatIt", "number_format")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>FormatIt::number_format(null /* == */);
-> </b><br><pre>
DOCUMENT_EXAMPLE;
/// run ///
print_r(
FormatIt::number_format(null /* == */)
);
echo "</pre>";
echo '</ol>';
///////// FormatIt::bytes2units(3); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_bytes2units'><b>FormatIt::bytes2units(<span class="type">int</span> \$bytes) <span>: string</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("ia\Util\FormatIt", "bytes2units")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>FormatIt::bytes2units(3); ->
DOCUMENT_EXAMPLE;
/// run ///
echo FormatIt::bytes2units(3);
echo '</ol>';
///////// FormatIt::units2bytes('palabra'); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_units2bytes'><b>FormatIt::units2bytes(<span class="type">string</span> \$num) <span>: string</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("ia\Util\FormatIt", "units2bytes")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>FormatIt::units2bytes('palabra'); ->
DOCUMENT_EXAMPLE;
/// run ///
echo FormatIt::units2bytes('palabra');
echo '</ol>';
///////// FormatIt::milliSecondsFormat(null /* =number= */); //////////////////////////////////////////////////
echo <<< FUNCTIONDEF
<li id='u_milliSecondsFormat'><b>FormatIt::milliSecondsFormat(<span class="type">number</span> \$t0) <span>: string</span></b>
FUNCTIONDEF;
echo "<pre class='docBlock'>".DocumentIt::methodDocBlockProtected("ia\Util\FormatIt", "milliSecondsFormat")."</pre>";
echo "<ol class='usage'>";
/// display ///
echo <<< DOCUMENT_EXAMPLE
<li>FormatIt::milliSecondsFormat(null /* =number= */); ->
DOCUMENT_EXAMPLE;
/// run ///
echo FormatIt::milliSecondsFormat(null /* =number= */);
echo '</ol>';
/* PerfilExample adds new methods here */
echo '</ul>';
} catch(Exception $exception) { echo "<pre class='errorBlock'>$exception</pre>"; }
phpunit test file template
<?php
use ia\Util\FormatIt;
use PHPUnit\Framework\TestCase;
class FormatItTest extends TestCase {
/**
* @dataProvider numberClean_Provider
*
*/
public function test_numberClean($s , $expected) {
$this->assertEquals($expected, FormatIt::numberClean($s) );
}
function numberClean_Provider() {
return [
'test 1' => [ '', '' ],
];
}
/**
* @dataProvider number_format_Provider
*
*/
public function test_number_format($number, $decimals, $dec_point, $thousand_sep , $expected) {
$this->assertEquals($expected, FormatIt::number_format($number, $decimals, $dec_point, $thousand_sep) );
}
function number_format_Provider() {
return [
'test 1' => [ '', '', '', '', '' ],
];
}
/**
* @dataProvider bytes2units_Provider
*
*/
public function test_bytes2units($bytes , $expected) {
$this->assertEquals($expected, FormatIt::bytes2units($bytes) );
}
function bytes2units_Provider() {
return [
'test 1' => [ '', '' ],
];
}
/**
* @dataProvider units2bytes_Provider
*
*/
public function test_units2bytes($num , $expected) {
$this->assertEquals($expected, FormatIt::units2bytes($num) );
}
function units2bytes_Provider() {
return [
'test 1' => [ '', '' ],
];
}
/**
* @dataProvider milliSecondsFormat_Provider
*
*/
public function test_milliSecondsFormat($t0 , $expected) {
$this->assertEquals($expected, FormatIt::milliSecondsFormat($t0) );
}
function milliSecondsFormat_Provider() {
return [
'test 1' => [ '', '' ],
];
}
}
ia Doc