-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89ab731
commit 7c263de
Showing
3 changed files
with
81 additions
and
3 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
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,44 @@ | ||
<?php | ||
|
||
namespace Ddeboer\DataImport\Tests\Reader; | ||
|
||
use Ddeboer\DataImport\Reader\CountableIteratorReader; | ||
|
||
/** | ||
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com> | ||
*/ | ||
class CountableIteratorReaderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testCount() | ||
{ | ||
$iterator = new \ArrayIterator([ | ||
[ | ||
'id' => 1, | ||
'username' => 'john.doe', | ||
'name' => 'John Doe', | ||
], | ||
]); | ||
|
||
$reader = new CountableIteratorReader($iterator); | ||
|
||
// We need to rewind the iterator | ||
$reader->rewind(); | ||
|
||
$this->assertEquals(1, $reader->count()); | ||
} | ||
|
||
public function testIteratorCount() | ||
{ | ||
$reader = new CountableIteratorReader(new CountableIterator); | ||
|
||
// We need to rewind the iterator | ||
$reader->rewind(); | ||
|
||
$this->assertEquals(0, $reader->count()); | ||
} | ||
} | ||
|
||
class CountableIterator extends \EmptyIterator | ||
{ | ||
|
||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Ddeboer\DataImport\Tests\Reader; | ||
|
||
use Ddeboer\DataImport\Reader\IteratorReader; | ||
|
||
/** | ||
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com> | ||
*/ | ||
class IteratorReaderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testGetFields() | ||
{ | ||
$iterator = new \ArrayIterator([ | ||
[ | ||
'id' => 1, | ||
'username' => 'john.doe', | ||
'name' => 'John Doe', | ||
], | ||
]); | ||
|
||
$reader = new IteratorReader($iterator); | ||
|
||
// We need to rewind the iterator | ||
$reader->rewind(); | ||
|
||
$fields = $reader->getFields(); | ||
|
||
$this->assertInternalType('array', $fields); | ||
$this->assertEquals(['id', 'username', 'name'], $fields); | ||
} | ||
} |