From 97b5aaf65f7134c9219d26083c7f442e5350c3a2 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 24 Jan 2017 16:56:52 +0000 Subject: [PATCH] Added Joins strategy and accompanying tests and documentation. Removed support for PHP 5.6. --- .travis.yml | 1 - composer.json | 2 +- src/Strategy/Join.php | 28 +++++++++++++++++++ test/Functional/DocumentationTest.php | 12 ++++++++ test/Integration/Mapper/Strategy/JoinTest.php | 20 +++++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/Strategy/Join.php create mode 100644 test/Integration/Mapper/Strategy/JoinTest.php diff --git a/.travis.yml b/.travis.yml index 2582b2c..2a3fb2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ sudo: false language: php php: - - 5.5 - 5.6 - 7.0 - 7.1 diff --git a/composer.json b/composer.json index 16e2a7e..30e6f6e 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ ], "license": "LGPL-3.0", "require": { - "php": ">=5.5", + "php": "^5.6|^7", "scriptfusion/array-walker": "^1", "eloquent/enumeration": "^5" }, diff --git a/src/Strategy/Join.php b/src/Strategy/Join.php new file mode 100644 index 0000000..228ad9e --- /dev/null +++ b/src/Strategy/Join.php @@ -0,0 +1,28 @@ +glue = "$glue"; + } + + public function __invoke($data, $context = null) + { + return implode($this->glue, parent::__invoke($data, $context)); + } +} diff --git a/test/Functional/DocumentationTest.php b/test/Functional/DocumentationTest.php index ec64f34..8d456c6 100644 --- a/test/Functional/DocumentationTest.php +++ b/test/Functional/DocumentationTest.php @@ -13,6 +13,7 @@ use ScriptFUSION\Mapper\Strategy\Filter; use ScriptFUSION\Mapper\Strategy\Flatten; use ScriptFUSION\Mapper\Strategy\IfExists; +use ScriptFUSION\Mapper\Strategy\Join; use ScriptFUSION\Mapper\Strategy\Merge; use ScriptFUSION\Mapper\Strategy\TakeFirst; use ScriptFUSION\Mapper\Strategy\ToList; @@ -228,6 +229,17 @@ public function testIfExists() self::assertFalse((new Mapper)->map($data, new IfExists(new Copy('bar'), true, false))); } + public function testJoin() + { + self::assertSame( + 'foo-bar', + (new Mapper)->map( + ['foo' => 'foo'], + new Join('-', new Copy('foo'), 'bar') + ) + ); + } + public function testMerge() { self::assertSame( diff --git a/test/Integration/Mapper/Strategy/JoinTest.php b/test/Integration/Mapper/Strategy/JoinTest.php new file mode 100644 index 0000000..d5e32e7 --- /dev/null +++ b/test/Integration/Mapper/Strategy/JoinTest.php @@ -0,0 +1,20 @@ +shouldReceive('__invoke')->andReturn('bar')->once()->getMock() + ))->setMapper(new Mapper); + + self::assertSame('foo-bar', $join([])); + } +}