This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more tests for scalar-list-types
- Loading branch information
Showing
6 changed files
with
232 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
namespace Hansel23\GenericLists\Tests\Unit; | ||
|
||
use Hansel23\GenericLists\ArrayList; | ||
use Hansel23\GenericLists\Tests\Unit\Fixtures\Stringable; | ||
|
||
class ArrayListTest extends \Codeception\TestCase\Test | ||
{ | ||
public function InvalidItemProvider() | ||
{ | ||
return [ | ||
[ 1, 1.0, true, false, new \stdClass(), new Stringable(), 'string' ], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider InvalidItemProvider | ||
* | ||
* @expectedException \Hansel23\GenericLists\Exceptions\InvalidTypeException | ||
*/ | ||
public function testIfInvalidItemsThrowsException( $item ) | ||
{ | ||
$stringList = new ArrayList(); | ||
$stringList->add( $item ); | ||
} | ||
|
||
public function ValidItemProvider() | ||
{ | ||
return [ | ||
[ [ 'true' ], [ [ '1' ] ], [ '1.0', '2.0', '3.0' ], [ ['false'], ['true'] ] ], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider ValidItemProvider | ||
*/ | ||
public function testAddingValidItems( $item ) | ||
{ | ||
$stringList = new ArrayList(); | ||
$stringList->add( $item ); | ||
|
||
$this->assertNotEquals( -1, $stringList->indexOf( $item ) ); | ||
} | ||
|
||
public function ValidStringArrayProvider() | ||
{ | ||
return [ | ||
[ [ ['here', 'is', 'a', 'testarray' ], [ '1', 2.0, 3 ] ], [ ['I like some'], ['more tests'] ] ], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider ValidStringArrayProvider | ||
*/ | ||
public function testCreatingStringListFromArray( array $subArrays ) | ||
{ | ||
$stringList = ArrayList::fromArray( $subArrays ); | ||
|
||
$this->assertEquals( count( $subArrays ), $stringList->count() ); | ||
$this->assertEquals( $subArrays, $stringList->toArray() ); | ||
} | ||
|
||
public function InvalidArrayProvider() | ||
{ | ||
return [ | ||
[ [ 1, false ], [ 'string', 'one more string', true ], [ [ ] ] ], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider InvalidArrayProvider | ||
* @expectedException \Hansel23\GenericLists\Exceptions\InvalidTypeException | ||
*/ | ||
public function testIfCreatingFromInvalidArrayThrowsException( array $invalidArray ) | ||
{ | ||
ArrayList::fromArray( $invalidArray ); | ||
} | ||
} |
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
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