Skip to content

Commit

Permalink
Added isArray function
Browse files Browse the repository at this point in the history
  • Loading branch information
assertchris committed Dec 15, 2014
1 parent dbb90ec commit ccadbfc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
25 changes: 18 additions & 7 deletions src/TypeFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ function isResource($variable)
return is_resource($variable);
}

/**
* @param mixed $variable
*
* @return bool
*/
function isArray($variable)
{
return is_array($variable);
}

/**
* @param mixed $variable
*
Expand All @@ -93,14 +103,15 @@ function isResource($variable)
function getType($variable)
{
$functions = [
"isNumber" => "number",
"isBoolean" => "boolean",
"isNull" => "null",
"isObject" => "object",
"isFunction" => "function",
"isNumber" => "number",
"isBoolean" => "boolean",
"isNull" => "null",
"isObject" => "object",
"isFunction" => "function",
"isExpression" => "expression",
"isString" => "string",
"isResource" => "resource"
"isString" => "string",
"isResource" => "resource",
"isArray" => "array"
];

$result = "unknown";
Expand Down
1 change: 0 additions & 1 deletion tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class Test extends PHPUnit_Framework_TestCase
{

}
43 changes: 27 additions & 16 deletions tests/TypeFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TypeFunctionTest extends Test
/**
* @test
*/
public function testIsNumber()
public function itIdentifiesNumbers()
{
$this->assertTrue(TypeFunctions\isNumber(0));
$this->assertTrue(TypeFunctions\isNumber(0.5));
Expand All @@ -23,7 +23,7 @@ public function testIsNumber()
/**
* @test
*/
public function testIsBoolean()
public function itIdentifiesBooleans()
{
$this->assertTrue(TypeFunctions\isBoolean(true));
$this->assertTrue(TypeFunctions\isBoolean(false));
Expand All @@ -37,7 +37,7 @@ public function testIsBoolean()
/**
* @test
*/
public function testIsNull()
public function itIdentifiesNulls()
{
$this->assertTrue(TypeFunctions\isNull(null));

Expand All @@ -49,7 +49,7 @@ public function testIsNull()
/**
* @test
*/
public function testIsObject()
public function itIdentifiesObjects()
{
$this->assertTrue(TypeFunctions\isObject($this));

Expand All @@ -63,7 +63,7 @@ public function testIsObject()
/**
* @test
*/
public function testIsFunction()
public function itIdentifiesFunctions()
{
$function = function () {
echo "hello";
Expand All @@ -78,7 +78,7 @@ public function testIsFunction()
/**
* @test
*/
public function testIsExpression()
public function itIdentifiesExpressions()
{
$this->assertTrue(TypeFunctions\isExpression("[a-z]"));

Expand All @@ -88,7 +88,7 @@ public function testIsExpression()
/**
* @test
*/
public function testIsString()
public function itIdentifiesStrings()
{
$this->assertTrue(TypeFunctions\isString("hello"));

Expand All @@ -98,7 +98,7 @@ public function testIsString()
/**
* @test
*/
public function testIsResource()
public function itIdentifiesResources()
{
$file = fopen(__FILE__, "r");

Expand All @@ -112,7 +112,17 @@ public function testIsResource()
/**
* @test
*/
public function testGetType()
public function itIdentifiesArrays()
{
$this->assertTrue(TypeFunctions\isArray(["foo", "bar"]));

$this->assertFalse(TypeFunctions\isArray("foo"));
}

/**
* @test
*/
public function itIdentifiesTypes()
{
$file = fopen(__FILE__, "r");

Expand All @@ -121,14 +131,15 @@ public function testGetType()
};

$types = [
"number" => 1.5,
"boolean" => true,
"null" => null,
"object" => $this,
"function" => $function,
"number" => 1.5,
"boolean" => true,
"null" => null,
"object" => $this,
"function" => $function,
"expression" => "[a-z]",
"string" => "hello",
"resource" => $file
"string" => "hello",
"resource" => $file,
"array" => ["foo", "bar"]
];

foreach ($types as $type => $variable) {
Expand Down

0 comments on commit ccadbfc

Please sign in to comment.