updating unit tests

This commit is contained in:
Reza
2018-12-24 13:16:10 +11:00
parent e81f04c2d8
commit df08dcce0a
5 changed files with 221 additions and 202 deletions

4
.gitignore vendored
View File

@ -2,3 +2,7 @@
/lab/
composer.lock
.idea
**/temp/
**/temp.*
**/*.temp.*

21
phpunit.xml Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -61,8 +61,8 @@ or use Composer:
composer require salarmehr/ary
* The class (`Ary()`) requires PHP 5.4 or above.
* The helper function (`ary()`) requires PHP 5.6 or above.
* The `Ary()` requires PHP 5.4 or above.
* The `ary()` helper function requires PHP 5.6 or above.
Licence
=======

View File

@ -178,6 +178,7 @@ class Ary extends Collection
* Get all items except for those with the specified keys.
*
* @param mixed $keys
* @param bool $returnArray
* @return static
*/
public function except($keys, $returnArray = false)

View File

@ -17,11 +17,11 @@ class Test extends PHPUnit\Framework\TestCase
public function provider()
{
return array(
array(''),
array(['ali', 'reza', 'mohammad']),
array([1, 2, 3, 4]),
);
return [
[['']],
[['ali', 'reza', 'mohammad']],
[[1, 2, 3, 4]],
];
}
/**
@ -43,16 +43,16 @@ class Test extends PHPUnit\Framework\TestCase
public function various()
{
return array(
array('', ''),
array(null, null),
array(['ali', 'reza', 'mohammad'], ['ali', 'reza', 'mohammad']),
array(['name' => 'ali', 'lastname' => 'reza', 'age' => 30], ['name' => 'ali', 'lastname' => 'reza', 'age' => 30]),
array((object)['name' => 'ali', 'lastname' => 'reza', 'age' => 30], (object)['name' => 'ali', 'lastname' => 'reza', 'age' => 30]),
array(['ali', 'reza', 'mohammad'], ['ali', 'reza', 'mohammad']),
array([1, 2, 3, 4], [1, 2, 3, 4]),
array(['x'=>'y'], ['x'=>'y']),
);
return [
['', ''],
[null, null],
[['ali', 'reza', 'mohammad'], ['ali', 'reza', 'mohammad']],
[['name' => 'ali', 'lastname' => 'reza', 'age' => 30], ['name' => 'ali', 'lastname' => 'reza', 'age' => 30]],
[(object)['name' => 'ali', 'lastname' => 'reza', 'age' => 30], (object)['name' => 'ali', 'lastname' => 'reza', 'age' => 30]],
[['ali', 'reza', 'mohammad'], ['ali', 'reza', 'mohammad']],
[[1, 2, 3, 4], [1, 2, 3, 4]],
[['x' => 'y'], ['x' => 'y']],
];
}
@ -73,14 +73,15 @@ class Test extends PHPUnit\Framework\TestCase
/**
* @dataProvider Provider
* @dataProvider provider
*/
public function testCount($objects)
{
$ary = new Ary($objects);
$result = count($objects);
var_dump($objects);
$expected = count($objects);
$num = count($ary);
$this->assertEquals($result, $num);
$this->assertEquals($expected, $num);
}
/**
@ -89,7 +90,7 @@ class Test extends PHPUnit\Framework\TestCase
public function testGetArrayableItems($original, $expected)
{
$ary = new Ary($original);
$this->invokeMethod($ary, 'getArrayableItems', array($original));
$this->invokeMethod($ary, 'getArrayableItems', [$original]);
$this->assertEquals($expected, $original);
}
@ -99,8 +100,9 @@ class Test extends PHPUnit\Framework\TestCase
* @param array $parameters Array of parameters to pass into method.
*
* @return mixed Method return.
* @throws ReflectionException
*/
public function invokeMethod(&$ary, $getArrayableItems, array $parameters = array())
public function invokeMethod(&$ary, $getArrayableItems, array $parameters = [])
{
$reflection = new \ReflectionClass(get_class($ary));
$method = $reflection->getMethod($getArrayableItems);
@ -175,15 +177,10 @@ class Test extends PHPUnit\Framework\TestCase
$this->assertEquals(['foo' => 'x'], $c->except(['bar'])->all());
}
public function testOffsetExists()
{
$parameters = array(4,5,2,0,1,3);
$parameters = [4, 5, 2, 0, 1, 3];
$ary = new Ary($parameters);
for ($i = 0; $i <= count($ary); $i++) {
@ -192,16 +189,15 @@ class Test extends PHPUnit\Framework\TestCase
if ($i < count($ary)) {
$resultTrue = $ary->offsetExists($key[$i]);
$this->assertTrue($resultTrue);
}
else{
} else {
$resultFalse = $ary->offsetExists($key[$i]);
$this->assertFalse($resultFalse);
}
}
}
public function testToObject(){
public function testToObject()
{
$name1 = 'mehdi';
$height1 = 181;
@ -223,7 +219,4 @@ class Test extends PHPUnit\Framework\TestCase
$this->assertInternalType("object", $objected);
}
}