Skip to content

Commit

Permalink
Merge pull request UnDeAdYeTii#5 from pxgamer/feature/phpunit
Browse files Browse the repository at this point in the history
Feature/phpunit
  • Loading branch information
bradietilley authored Oct 17, 2017
2 parents acc054d + f953389 commit ede02ef
Show file tree
Hide file tree
Showing 14 changed files with 444 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/Arr/AppendTest.php
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');
}
}
31 changes: 31 additions & 0 deletions tests/Arr/AtTest.php
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');
}
}
33 changes: 33 additions & 0 deletions tests/Arr/FirstTest.php
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']);
}
}
33 changes: 33 additions & 0 deletions tests/Arr/GetTest.php
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');
}
}
31 changes: 31 additions & 0 deletions tests/Arr/IndexOfTest.php
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);
}
}
30 changes: 30 additions & 0 deletions tests/Arr/IndexesOfTest.php
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]);
}
}
31 changes: 31 additions & 0 deletions tests/Arr/KeysTest.php
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]);
}
}
34 changes: 34 additions & 0 deletions tests/Arr/LastTest.php
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']);
}
}
30 changes: 30 additions & 0 deletions tests/Arr/LengthTest.php
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);
}
}
31 changes: 31 additions & 0 deletions tests/Arr/PrependTest.php
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');
}
}
33 changes: 33 additions & 0 deletions tests/Arr/ShuffleTest.php
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);
}
}
Loading

0 comments on commit ede02ef

Please sign in to comment.