Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from cocur/join
Add Join link, fixes #18
- Loading branch information
Showing
5 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Cocur\Chain\Link; | ||
|
||
/** | ||
* Implode. | ||
* | ||
* @author Florian Eckerstorfer | ||
* @copyright 2017 Florian Eckerstorfer | ||
*/ | ||
trait Join | ||
{ | ||
/** | ||
* Join array elements with a string | ||
* | ||
* @param string $glue | ||
* | ||
* @return string Returns a string containing a string representation of all the array elements in the same order, | ||
* with the glue string between each element. | ||
*/ | ||
public function join($glue = '') | ||
{ | ||
return implode($glue, $this->array); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Cocur\Chain\Link; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
|
||
/** | ||
* CountTest. | ||
* | ||
* @author Florian Eckerstorfer | ||
* @copyright 2015 Florian Eckerstorfer | ||
* @group unit | ||
*/ | ||
class JoinTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
* @covers Cocur\Chain\Link\Join::join() | ||
*/ | ||
public function joinReturnsStringWithoutGlue() | ||
{ | ||
/** @var \Cocur\Chain\Link\Join $mock */ | ||
$mock = $this->getMockForTrait('Cocur\Chain\Link\Join'); | ||
$mock->array = ['a', 'b', 'c']; | ||
|
||
$this->assertEquals('abc', $mock->join()); | ||
} | ||
} |