forked from UnDeAdYeTii/libraries
-
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.
Merge pull request UnDeAdYeTii#5 from pxgamer/feature/phpunit
Feature/phpunit
- Loading branch information
Showing
14 changed files
with
444 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,31 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class AppendTest | ||
*/ | ||
class AppendTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'bananas' | ||
]; | ||
|
||
/** | ||
* Test whether it appends the specified value to the array | ||
*/ | ||
public function testCanAppendValueToArray() | ||
{ | ||
$array = new Arr($this->testData); | ||
$array->append('pears'); | ||
|
||
$this->assertArrayHasKey(1, $array->toArray()); | ||
$this->assertTrue($array->toArray()[1] === 'pears'); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class AtTest | ||
*/ | ||
class AtTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'right' => 'apples', | ||
'wrong' => 'oranges', | ||
'wrongAsWell' => 'apples', | ||
]; | ||
|
||
/** | ||
* Test whether it returns the value for the specified key | ||
*/ | ||
public function testCanGetValueAtSpecifiedKey() | ||
{ | ||
$array = new Arr($this->testData); | ||
$this->assertTrue($array->at('right') === 'apples'); | ||
$this->assertFalse($array->at('wrong') === 'apples'); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class FirstTest | ||
*/ | ||
class FirstTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'apples', | ||
'oranges', | ||
'apples', | ||
]; | ||
|
||
/** | ||
* Test whether it shifts the first element off the array and returns this | ||
*/ | ||
public function testCanGetFirstArrayElement() | ||
{ | ||
$array = new Arr($this->testData); | ||
$result = $array->first(); | ||
|
||
$this->assertTrue($result === ['apples']); | ||
$this->assertTrue($array->toArray() === ['oranges', 'apples']); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class GetTest | ||
*/ | ||
class GetTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'bananas' => [ | ||
'oranges' => [ | ||
'apples' => 'pears' | ||
] | ||
] | ||
]; | ||
|
||
/** | ||
* Test whether it returns the value for the specified key | ||
*/ | ||
public function testCanGetValueAtSpecifiedKey() | ||
{ | ||
$array = new Arr($this->testData); | ||
$this->assertArrayHasKey('apples', $array->get('bananas.oranges')); | ||
$this->assertTrue($array->get('bananas.oranges.apples') === 'pears'); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
use YeTii\General\Num; | ||
|
||
/** | ||
* Class IndexOfTest | ||
*/ | ||
class IndexOfTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'apples', | ||
'pears', | ||
'oranges' | ||
]; | ||
|
||
/** | ||
* Test whether it returns the key for the specified value | ||
*/ | ||
public function testCanGetIndexOfNeedleInArray() | ||
{ | ||
$array = new Arr($this->testData); | ||
$this->assertTrue($array->indexOf('pears') === 1); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class IndexesOfTest | ||
*/ | ||
class IndexesOfTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'apples', | ||
'oranges', | ||
'apples', | ||
]; | ||
|
||
/** | ||
* Test whether it returns the keys for the specified value | ||
*/ | ||
public function testCanGetIndexesOfNeedleInArray() | ||
{ | ||
$array = new Arr($this->testData); | ||
$this->assertTrue($array->indexesOf('apples') === [0, 2]); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class KeysTest | ||
*/ | ||
class KeysTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'apples', | ||
'oranges', | ||
'apples', | ||
]; | ||
|
||
/** | ||
* Test whether it returns an array of the keys | ||
*/ | ||
public function testCanGetKeysForArray() | ||
{ | ||
$array = new Arr($this->testData); | ||
$result = $array->keys(); | ||
$this->assertTrue($result === [0, 1, 2]); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class LastTest | ||
*/ | ||
class LastTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'apples', | ||
'bananas', | ||
'apples', | ||
'oranges', | ||
]; | ||
|
||
/** | ||
* Test whether it pops the last element off the array and returns this | ||
*/ | ||
public function testCanGetLastArrayElement() | ||
{ | ||
$array = new Arr($this->testData); | ||
$result = $array->last(); | ||
|
||
$this->assertTrue($result === ['oranges']); | ||
$this->assertTrue($array->toArray() === ['apples', 'bananas', 'apples']); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class LengthTest | ||
*/ | ||
class LengthTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'apples', | ||
'oranges', | ||
'apples', | ||
]; | ||
|
||
/** | ||
* Test whether it returns the length of the array | ||
*/ | ||
public function testCanGetLengthOfArray() | ||
{ | ||
$array = new Arr($this->testData); | ||
$this->assertTrue($array->length() === 3); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class PrependTest | ||
*/ | ||
class PrependTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'bananas' | ||
]; | ||
|
||
/** | ||
* Test whether it prepends the specified value to the array | ||
*/ | ||
public function testCanPrependValueToArray() | ||
{ | ||
$array = new Arr($this->testData); | ||
$array->prepend('pears'); | ||
|
||
$this->assertArrayHasKey(0, $array->toArray()); | ||
$this->assertTrue($array->toArray()[0] === 'pears'); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Yetii\Tests\Arr; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use YeTii\General\Arr; | ||
|
||
/** | ||
* Class ShuffleTest | ||
*/ | ||
class ShuffleTest extends TestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
public $testData = [ | ||
'apples', | ||
'oranges', | ||
'apples', | ||
]; | ||
|
||
/** | ||
* Test whether it returns a shuffled array | ||
*/ | ||
public function testCanShuffleTheArray() | ||
{ | ||
$array = new Arr($this->testData); | ||
$result = $array->shuffle(); | ||
$this->assertInstanceOf(Arr::class, $result); | ||
$this->assertInternalType('array', $result->toArray()); | ||
$this->assertFalse($result === $this->testData); | ||
} | ||
} |
Oops, something went wrong.