Skip to content

Commit

Permalink
Change structure of namespace and filename.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hy369 committed Aug 26, 2017
1 parent 8a34af1 commit cef8eba
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 76 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ composer require hylin/miniutils

## Usage

### Str
### MuString

### Arr
### MuArray

2 changes: 1 addition & 1 deletion src/MiniUtils/Arr.php → src/MiniUtils/MuArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @since 1.0
* @author Hylin Yin <hylin@iphp8.com>
*/
class Arr
class MuArray
{
/**
* Apply a user function to every member of an array key.
Expand Down
2 changes: 1 addition & 1 deletion src/MiniUtils/Str.php → src/MiniUtils/MuString.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @since 1.0
* @author Hylin Yin <hylin@iphp8.com>
*/
class Str
class MuString
{
/**
* Converts UTF-8 to unicode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@

namespace MiniUtils\Tests;

use MiniUtils\Arr;
use MiniUtils\MuArray;
use PHPUnit\Framework\TestCase;

class ArrTest extends TestCase
class MuArrayTest extends TestCase
{
public function testKeyMap()
{
$array = ['foo', 'bar'];
Arr::keyMap($array, function ($val, $key) {
MuArray::keyMap($array, function ($val, $key) {
return $val . $key;
});
$this->assertEquals($array, ['foo0' => 'foo', 'bar1' => 'bar']);

$array = ['foo', 'bar'];
Arr::keyMap($array, function (&$val, $key) {
MuArray::keyMap($array, function (&$val, $key) {
$val = $val . 'bar';
return $key;
});
Expand Down
68 changes: 68 additions & 0 deletions src/Tests/MiniUtils/MuStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* This file is part of the Lixue package.
*
* (c) www.lixueweb.com
*
* @since 1.0
* @author Hylin Yin <hylin@lixueweb.com>
*/

namespace MiniUtils\Tests;

use MiniUtils\MuString;
use PHPUnit\Framework\TestCase;

class StrTest extends TestCase
{
public function testUtf8ToUnicode()
{
$this->assertEquals('t', MuString::utf8ToUnicode('t'));
$this->assertEquals((string)dechex(ord('t')), MuString::utf8ToUnicode('t', '', '', false));
$this->assertEquals('\u4e00', MuString::utf8ToUnicode('一'));
$this->assertEquals('\x{4e00}', MuString::utf8ToUnicode('一', '\x{', '}'));
$this->assertEquals('\u9fa5', MuString::utf8ToUnicode('龥'));
$this->assertEquals('a\u4e003\u9fa5*', MuString::utf8ToUnicode('a一3龥*'));
}

public function testUnicodeToUtf8()
{
$this->assertEquals('一', MuString::unicodeToUtf8('\u4e00'));
$this->assertEquals('1', MuString::unicodeToUtf8('1'));
$this->assertEquals('~', MuString::unicodeToUtf8('\u7e'));
$this->assertEquals('1一', MuString::unicodeToUtf8('1\u4e00'));
$this->assertEquals('1一', MuString::unicodeToUtf8('1\x{4e00}', '\x{', '}'));
$this->assertEquals('生', MuString::unicodeToUtf8('&#29983;', '&#', ';'));
}

public function testReplaceSuffix()
{
$this->assertEquals('hylin.doc', MuString::replaceSuffix('hylin.txt', '.doc'));
$this->assertEquals('hylin.doc', MuString::replaceSuffix('hylin', '.doc'));
$this->assertEquals('hylin.yin.doc', MuString::replaceSuffix('hylin.yin.txt', '.doc'));
$this->assertEquals('hylin.doc.doc', MuString::replaceSuffix('hylin.doc.txt', '.doc'));
}

/**
* @param $string
* @param $withDot
* @param $expected
*
* @dataProvider getSuffixProvider
*/
public function testGetSuffix($string, $withDot, $expected)
{
$this->assertEquals($expected, MuString::getSuffix($string, $withDot));
}

public function getSuffixProvider()
{
return [
['foo.bar', false, 'bar'],
['foo.bar', true, '.bar'],
['foo', false, ''],
['foo', true, ''],
['foo.bar.foobar', true, '.foobar'],
];
}
}
68 changes: 0 additions & 68 deletions src/Tests/MiniUtils/StrTest.php

This file was deleted.

0 comments on commit cef8eba

Please sign in to comment.