From 27311daeac39ec247ddfd86614f3a73cb6080eec Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Tue, 17 Dec 2013 21:24:11 +0200 Subject: [PATCH] introduce namespace PFF. version 0.2 --- composer.json | 2 +- src/{arraytools.php => array.php} | 13 ++++++- src/{collectiontools.php => collection.php} | 4 ++- src/dateformat.php | 4 +++ src/htmlbuilder.php | 2 +- src/mixins.php | 2 ++ src/regexp.php | 2 ++ src/{stringtools.php => str.php} | 4 ++- t/{ArrayTest.php => ArrTest.php} | 29 +++++++++------ t/CollectionTest.php | 8 ++--- t/FormatTest.php | 40 ++++++++++----------- t/HtmlBuilderTest.php | 4 +-- t/MixinsTest.php | 6 ++-- t/StrTest.php | 25 +++++++++++++ t/StringTest.php | 25 ------------- 15 files changed, 100 insertions(+), 70 deletions(-) rename src/{arraytools.php => array.php} (77%) rename src/{collectiontools.php => collection.php} (97%) rename src/{stringtools.php => str.php} (90%) rename t/{ArrayTest.php => ArrTest.php} (55%) create mode 100644 t/StrTest.php delete mode 100644 t/StringTest.php diff --git a/composer.json b/composer.json index 73108ec..b921b83 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ ], "extra": { "branch-alias": { - "dev-master": "0.1-dev" + "dev-master": "0.2-dev" } } } diff --git a/src/arraytools.php b/src/array.php similarity index 77% rename from src/arraytools.php rename to src/array.php index 3550f3c..e11671c 100644 --- a/src/arraytools.php +++ b/src/array.php @@ -1,6 +1,8 @@ 50, ); - $this->assertEquals(400, ArrayTools::get($arr, 'grapefruit')); - $this->assertEquals(null, ArrayTools::get($arr, 'orange')); - $this->assertEquals('no-oranges', ArrayTools::get($arr, 'orange', 'no-oranges')); + $this->assertEquals(400, \PFF\Arr::get($arr, 'grapefruit')); + $this->assertEquals(null, \PFF\Arr::get($arr, 'orange')); + $this->assertEquals('no-oranges', \PFF\Arr::get($arr, 'orange', 'no-oranges')); } public function testEnsureKeyExists() @@ -24,7 +24,7 @@ class ArrayToolsTest extends PHPUnit_Framework_TestCase ); $this->assertEquals(false, array_key_exists('orange', $arr)); - ArrayTools::ensureKeyExists($arr, 'orange'); + \PFF\Arr::ensureKeyExists($arr, 'orange'); $this->assertEquals(true, array_key_exists('orange', $arr)); } @@ -32,9 +32,9 @@ class ArrayToolsTest extends PHPUnit_Framework_TestCase { $arr = array('carrot' => array('orange')); - ArrayTools::pushToKey($arr, 'apple', 'green'); - ArrayTools::pushToKey($arr, 'carrot', 'long'); - ArrayTools::pushToKey($arr, 'apple', 'sweet'); + \PFF\Arr::pushToKey($arr, 'apple', 'green'); + \PFF\Arr::pushToKey($arr, 'carrot', 'long'); + \PFF\Arr::pushToKey($arr, 'apple', 'sweet'); $this->assertEquals(array('green', 'sweet'), $arr['apple']); $this->assertEquals(array('orange', 'long'), $arr['carrot']); @@ -48,15 +48,22 @@ class ArrayToolsTest extends PHPUnit_Framework_TestCase 'carrot' => 50, ); - $apple = ArrayTools::pop($arr, 'apple'); + $apple = \PFF\Arr::pop($arr, 'apple'); $this->assertEquals(false, array_key_exists('apple', $arr)); $this->assertEquals(100, $apple); - $apple = ArrayTools::pop($arr, 'apple'); + $apple = \PFF\Arr::pop($arr, 'apple'); $this->assertEquals(null, $apple); - $apple = ArrayTools::pop($arr, 'apple', 'what?'); + $apple = \PFF\Arr::pop($arr, 'apple', 'what?'); $this->assertEquals('what?', $apple); } + + public function testFlatten() + { + $arr = array('a', 'b', array(array(array('x'), 'y', 'z')), array(array('p'))); + $flat = \PFF\Arr::flatten($arr); + $this->assertEquals(array('a', 'b', 'x', 'y', 'z', 'p'), $flat); + } } diff --git a/t/CollectionTest.php b/t/CollectionTest.php index dcf952f..4005b03 100644 --- a/t/CollectionTest.php +++ b/t/CollectionTest.php @@ -1,6 +1,6 @@ assertEquals(3, count($columns)); $this->assertEquals(2, count($columns[0])); $this->assertEquals(1, count($columns[1])); @@ -25,7 +25,7 @@ class CollectionsTest extends PHPUnit_Framework_TestCase 'carrot', 'tomato', ); - $chunks = Collections::chunks($arr, 3); + $chunks = \PFF\Collection::chunks($arr, 3); $this->assertEquals(2, count($chunks)); $this->assertEquals(3, count($chunks[0])); $this->assertEquals(1, count($chunks[1])); @@ -39,7 +39,7 @@ class CollectionsTest extends PHPUnit_Framework_TestCase 'carrot', 'tomato', ); - $chunks = Collections::chunks($arr, 3, true); + $chunks = \PFF\Collection::chunks($arr, 3, true); $this->assertEquals(2, count($chunks)); $this->assertEquals(3, count($chunks[0])); $this->assertEquals(3, count($chunks[1])); diff --git a/t/FormatTest.php b/t/FormatTest.php index 2f6245f..a600516 100644 --- a/t/FormatTest.php +++ b/t/FormatTest.php @@ -1,36 +1,36 @@ assertEquals(DateFormat::DATE_DEFAULT, DateFormat::DATE_BIG_ENDIAN | DateFormat::DATE_HYPHENS); - $this->assertEquals(DateFormat::DATE_US, DateFormat::DATE_MIDDLE_ENDIAN | DateFormat::DATE_SLASHES); - $this->assertEquals(DateFormat::DATE_EUROPEAN, DateFormat::DATE_LITTLE_ENDIAN | DateFormat::DATE_DOTS); + $this->assertEquals(\PFF\DateFormat::DATE_DEFAULT, \PFF\DateFormat::DATE_BIG_ENDIAN | \PFF\DateFormat::DATE_HYPHENS); + $this->assertEquals(\PFF\DateFormat::DATE_US, \PFF\DateFormat::DATE_MIDDLE_ENDIAN | \PFF\DateFormat::DATE_SLASHES); + $this->assertEquals(\PFF\DateFormat::DATE_EUROPEAN, \PFF\DateFormat::DATE_LITTLE_ENDIAN | \PFF\DateFormat::DATE_DOTS); } public function testDateFlagsFromString() { - $this->assertEquals(DateFormat::DATE_DEFAULT, DateFormat::dateFlagsFromString('Default')); - $this->assertEquals(DateFormat::DATE_DEFAULT, DateFormat::dateFlagsFromString('Big-endian hyphEns')); - $this->assertEquals(DateFormat::DATE_EUROPEAN, DateFormat::dateFlagsFromString('European')); - $this->assertEquals(DateFormat::DATE_EUROPEAN, DateFormat::dateFlagsFromString('little-endian dots')); - $this->assertEquals(DateFormat::DATE_US, DateFormat::dateFlagsFromString('US')); - $this->assertEquals(DateFormat::DATE_US, DateFormat::dateFlagsFromString('Middle-Endian Slashes')); - $this->assertEquals(DateFormat::DATE_BIG_ENDIAN | DateFormat::DATE_SPACES, - DateFormat::dateFlagsFromString('big-endian spaces')); + $this->assertEquals(\PFF\DateFormat::DATE_DEFAULT, \PFF\DateFormat::dateFlagsFromString('Default')); + $this->assertEquals(\PFF\DateFormat::DATE_DEFAULT, \PFF\DateFormat::dateFlagsFromString('Big-endian hyphEns')); + $this->assertEquals(\PFF\DateFormat::DATE_EUROPEAN, \PFF\DateFormat::dateFlagsFromString('European')); + $this->assertEquals(\PFF\DateFormat::DATE_EUROPEAN, \PFF\DateFormat::dateFlagsFromString('little-endian dots')); + $this->assertEquals(\PFF\DateFormat::DATE_US, \PFF\DateFormat::dateFlagsFromString('US')); + $this->assertEquals(\PFF\DateFormat::DATE_US, \PFF\DateFormat::dateFlagsFromString('Middle-Endian Slashes')); + $this->assertEquals(\PFF\DateFormat::DATE_BIG_ENDIAN | \PFF\DateFormat::DATE_SPACES, + \PFF\DateFormat::dateFlagsFromString('big-endian spaces')); } public function testDatetimeFlagsFromString() { - $this->assertEquals(DateFormat::DATETIME_DEFAULT, DateFormat::datetimeFlagsFromString('Default')); - $this->assertEquals(DateFormat::DATETIME_DEFAULT, DateFormat::datetimeFlagsFromString('Big-endian hyphEns 24')); - $this->assertEquals(DateFormat::DATETIME_EUROPEAN, DateFormat::datetimeFlagsFromString('European')); - $this->assertEquals(DateFormat::DATETIME_EUROPEAN, DateFormat::datetimeFlagsFromString('little-endian dots 24')); - $this->assertEquals(DateFormat::DATETIME_US, DateFormat::datetimeFlagsFromString('US')); - $this->assertEquals(DateFormat::DATETIME_US, DateFormat::datetimeFlagsFromString('Middle-Endian Slashes 12-upper')); - $this->assertEquals(DateFormat::DATE_BIG_ENDIAN | DateFormat::DATE_SPACES | DateFormat::TIME_12HOURS_LOWER | DateFormat::TIME_SECONDS, - DateFormat::datetimeFlagsFromString("big-endian spaces \n 12-lower Seconds")); + $this->assertEquals(\PFF\DateFormat::DATETIME_DEFAULT, \PFF\DateFormat::datetimeFlagsFromString('Default')); + $this->assertEquals(\PFF\DateFormat::DATETIME_DEFAULT, \PFF\DateFormat::datetimeFlagsFromString('Big-endian hyphEns 24')); + $this->assertEquals(\PFF\DateFormat::DATETIME_EUROPEAN, \PFF\DateFormat::datetimeFlagsFromString('European')); + $this->assertEquals(\PFF\DateFormat::DATETIME_EUROPEAN, \PFF\DateFormat::datetimeFlagsFromString('little-endian dots 24')); + $this->assertEquals(\PFF\DateFormat::DATETIME_US, \PFF\DateFormat::datetimeFlagsFromString('US')); + $this->assertEquals(\PFF\DateFormat::DATETIME_US, \PFF\DateFormat::datetimeFlagsFromString('Middle-Endian Slashes 12-upper')); + $this->assertEquals(\PFF\DateFormat::DATE_BIG_ENDIAN | \PFF\DateFormat::DATE_SPACES | \PFF\DateFormat::TIME_12HOURS_LOWER | \PFF\DateFormat::TIME_SECONDS, + \PFF\DateFormat::datetimeFlagsFromString("big-endian spaces \n 12-lower Seconds")); } } diff --git a/t/HtmlBuilderTest.php b/t/HtmlBuilderTest.php index 3892193..bdef45d 100644 --- a/t/HtmlBuilderTest.php +++ b/t/HtmlBuilderTest.php @@ -4,9 +4,9 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase { public function testTag() { - $tag = HtmlBuilder\Tag::div(array('class' => 'container')) + $tag = \PFF\HtmlBuilder\Tag::div(array('class' => 'container')) ->append('Hello, "World"') - ->append(HtmlBuilder\Tag::a()->append('click ')->raw('me')); + ->append(\PFF\HtmlBuilder\Tag::a()->append('click ')->raw('me')); $this->assertEquals('
Hello, "World"click me
', (string)$tag); } diff --git a/t/MixinsTest.php b/t/MixinsTest.php index d634305..fb0970c 100644 --- a/t/MixinsTest.php +++ b/t/MixinsTest.php @@ -1,6 +1,6 @@ assertTrue(\PFF\Str::startsWith('abcdef', 'abc')); + $this->assertFalse(\PFF\Str::startsWith(' abcdef', 'abc')); + $this->assertFalse(\PFF\Str::startsWith('abc', 'abcdef')); + $this->assertTrue(\PFF\Str::startsWith('abc', 'abc')); + $this->assertTrue(\PFF\Str::startsWith('abc', '')); + $this->assertFalse(\PFF\Str::startsWith('abc', ' ')); + } + + public function testEndsWith() + { + $this->assertTrue(\PFF\Str::endsWith('abcdef', 'def')); + $this->assertFalse(\PFF\Str::endsWith('abcdef ', 'def')); + $this->assertFalse(\PFF\Str::endsWith('abc', 'abcdef')); + $this->assertTrue(\PFF\Str::endsWith('abc', 'abc')); + $this->assertTrue(\PFF\Str::endsWith('abc', '')); + $this->assertFalse(\PFF\Str::endsWith('abc', ' ')); + } +} + diff --git a/t/StringTest.php b/t/StringTest.php deleted file mode 100644 index e2c5eaf..0000000 --- a/t/StringTest.php +++ /dev/null @@ -1,25 +0,0 @@ -assertTrue(StringTools::startsWith('abcdef', 'abc')); - $this->assertFalse(StringTools::startsWith(' abcdef', 'abc')); - $this->assertFalse(StringTools::startsWith('abc', 'abcdef')); - $this->assertTrue(StringTools::startsWith('abc', 'abc')); - $this->assertTrue(StringTools::startsWith('abc', '')); - $this->assertFalse(StringTools::startsWith('abc', ' ')); - } - - public function testEndsWith() - { - $this->assertTrue(StringTools::endsWith('abcdef', 'def')); - $this->assertFalse(StringTools::endsWith('abcdef ', 'def')); - $this->assertFalse(StringTools::endsWith('abc', 'abcdef')); - $this->assertTrue(StringTools::endsWith('abc', 'abc')); - $this->assertTrue(StringTools::endsWith('abc', '')); - $this->assertFalse(StringTools::endsWith('abc', ' ')); - } -} - -- 2.49.0