-
Notifications
You must be signed in to change notification settings - Fork 1
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 #30 from pitchart/feature/length
Adds support for length
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
|
||
namespace Pitchart\Transformer\Reducer\Termination; | ||
|
||
|
||
use Pitchart\Transformer\Termination; | ||
|
||
class Length implements Termination | ||
{ | ||
public function init() | ||
{ | ||
return 0; | ||
} | ||
|
||
public function step($result, $current) | ||
{ | ||
return ++$result; | ||
} | ||
|
||
public function complete($result) | ||
{ | ||
return $result; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace Pitchart\Transformer\Tests\Reducer\Termination; | ||
|
||
use Pitchart\Transformer\Reducer; | ||
use Pitchart\Transformer\Reducer\Termination\Length; | ||
use PHPUnit\Framework\TestCase; | ||
use Pitchart\Transformer\Termination; | ||
use function Pitchart\Transformer\transform; | ||
|
||
class LengthTest extends TestCase | ||
{ | ||
public function test_is_a_reducer() | ||
{ | ||
$length = new Length; | ||
self::assertInstanceOf(Reducer::class, $length); | ||
} | ||
|
||
public function test_is_a_termination() | ||
{ | ||
$length = new Length; | ||
self::assertInstanceOf(Termination::class, $length); | ||
} | ||
|
||
public function test_is_zero_if_collection_is_empty() | ||
{ | ||
$length = transform([])->length(); | ||
|
||
$this->assertEquals(0, $length); | ||
} | ||
|
||
public function test_returns_collection_size_for_not_empty_collections() | ||
{ | ||
$length = transform([1, 2, 3, 4])->length(); | ||
|
||
$this->assertEquals(4, $length); | ||
} | ||
} |