Skip to content

Commit

Permalink
Merge pull request #5 from s3b4stian/analysis-XVOA5O
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
s3b4stian authored Jun 7, 2017
2 parents d1edabc + fa0ef67 commit 1039625
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 89 deletions.
6 changes: 3 additions & 3 deletions src/TypedObjectArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class TypedObjectArray extends ArrayObject
*/
public function __construct(string $type, array $array = [])
{
if (!class_exists($type)){
throw new InvalidArgumentException('Type passed to '.__CLASS__.' must be an existing class');
if (!class_exists($type)) {
throw new InvalidArgumentException('Type passed to '.__CLASS__.' must be an existing class');
}

//check elements of passed array
//I will find another method
foreach ($array as $element) {
Expand Down
157 changes: 87 additions & 70 deletions tests/TypedArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
use PHPUnit\Framework\TestCase;

/**
* Typed Array Test
* Typed Array Test.
*/
class TypedArrayTest extends TestCase
{
/**
* Provide allowed types.
*
*
* @return array
*/
function allowedTypeProvider()
public function allowedTypeProvider()
{
return [
['array'],
Expand All @@ -34,7 +34,7 @@ function allowedTypeProvider()
['string'],
];
}

/**
* Test new instance.
*
Expand All @@ -44,7 +44,7 @@ public function testCreateInstance($type)
{
$this->assertInstanceOf(TypedArray::class, (new TypedArray($type)));
}

/**
* Test new instance with not allowed type.
*
Expand All @@ -54,26 +54,27 @@ public function testCreateInstanceWithNotAllowedType()
{
$this->assertInstanceOf(TypedArray::class, (new TypedArray('notAllowedType')));
}



/**
* Provide arrays of right typed values.
*
*
* @return array
*/
function rightTypedArrayProvider()
public function rightTypedArrayProvider()
{
return [
['array', [[1],[2]]],
['array', [[1], [2]]],
['bool', [true, false]],
['callable', [function(){}, function(){}]],
['callable', [function () {
}, function () {
}]],
['float', [1.1, 2.2]],
['int', [1, 2]],
['object', [(object)['name' => 'foo'], (object)['name' => 'bar']]],
['object', [(object) ['name' => 'foo'], (object) ['name' => 'bar']]],
['string', ['a', 'b']],
];
}

/**
* Test new instance passing right typed array to constructor.
*
Expand All @@ -83,67 +84,77 @@ public function testCreateInstanceWithRightTypedArray($type, $array)
{
$this->assertInstanceOf(TypedArray::class, (new TypedArray($type, $array)));
}

/**
* Provide arrays of wrong typed values.
*
*
* @return array
*/
function wrongTypedArrayProvider()
public function wrongTypedArrayProvider()
{
return [
['array', [true, false]],
['array', [function(){}, function(){}]],
['array', [function () {
}, function () {
}]],
['array', [1.1, 2.2]],
['array', [1, 2]],
['array', [(object)['name' => 'foo'], (object)['name' => 'bar']]],
['array', [(object) ['name' => 'foo'], (object) ['name' => 'bar']]],
['array', ['a', 'b']],

['bool', [[1],[2]]],
['bool', [function(){}, function(){}]],

['bool', [[1], [2]]],
['bool', [function () {
}, function () {
}]],
['bool', [1.1, 2.2]],
['bool', [1, 2]],
['bool', [(object)['name' => 'foo'], (object)['name' => 'bar']]],
['bool', [(object) ['name' => 'foo'], (object) ['name' => 'bar']]],
['bool', ['a', 'b']],
['callable', [[1],[2]]],

['callable', [[1], [2]]],
['callable', [true, false]],
['callable', [1.1, 2.2]],
['callable', [1, 2]],
['callable', [(object)['name' => 'foo'], (object)['name' => 'bar']]],
['callable', ['a', 'b']],
['float', [[1],[2]]],
['callable', [(object) ['name' => 'foo'], (object) ['name' => 'bar']]],
['callable', ['a', 'b']],

['float', [[1], [2]]],
['float', [true, false]],
['float', [function(){}, function(){}]],
['float', [function () {
}, function () {
}]],
['float', [1, 2]],
['float', [(object)['name' => 'foo'], (object)['name' => 'bar']]],
['float', [(object) ['name' => 'foo'], (object) ['name' => 'bar']]],
['float', ['a', 'b']],
['int', [[1],[2]]],

['int', [[1], [2]]],
['int', [true, false]],
['int', [function(){}, function(){}]],
['int', [function () {
}, function () {
}]],
['int', [1.1, 2.2]],
['int', [(object)['name' => 'foo'], (object)['name' => 'bar']]],
['int', [(object) ['name' => 'foo'], (object) ['name' => 'bar']]],
['int', ['a', 'b']],
['object', [[1],[2]]],

['object', [[1], [2]]],
['object', [true, false]],
//skip this because closure pass as object
//['object', [function(){}, function(){}]],
['object', [1.1, 2.2]],
['object', [1, 2]],
['object', ['a', 'b']],
['string', [[1],[2]]],

['string', [[1], [2]]],
['string', [true, false]],
['string', [function(){}, function(){}]],
['string', [function () {
}, function () {
}]],
['string', [1.1, 2.2]],
['string', [1, 2]],
['string', [(object)['name' => 'foo'], (object)['name' => 'bar']]],
['string', [(object) ['name' => 'foo'], (object) ['name' => 'bar']]],
];
}

/**
* Test new instance passing array with invalid element to constructor.
*
Expand All @@ -154,25 +165,26 @@ public function testCreateInstanceWithWrongTypedArray($type, $array)
{
$this->assertInstanceOf(TypedArray::class, (new TypedArray($type, $array)));
}

/**
* Provide values of right types.
*
*
* @return array
*/
function rightTypedValueProvider()
public function rightTypedValueProvider()
{
return [
['array',[1]],
['array', [1]],
['bool', true],
['callable', function(){}],
['callable', function () {
}],
['float', 1.1],
['int', 1],
['object',(object)['name' => 'foo']],
['object', (object) ['name' => 'foo']],
['string', 'a'],
];
}

/**
* Test assign to array a right typed value.
*
Expand All @@ -185,67 +197,72 @@ public function testAssignrRightTypedValueToArray($type, $value)

$this->assertEquals(1, $array->count());
}

/**
* Provide values of wrong types.
*
*
* @return array
*/
function wrongTypedValueProvider()
public function wrongTypedValueProvider()
{
return [
['array', true],
['array', function(){}],
['array', function () {
}],
['array', 1.1],
['array', 1],
['array', (object)['name' => 'foo']],
['array', (object) ['name' => 'foo']],
['array', 'a'],

['bool', [1]],
['bool', function(){}],
['bool', function () {
}],
['bool', 1.1],
['bool', 1],
['bool', (object)['name' => 'foo']],
['bool', (object) ['name' => 'foo']],
['bool', 'a'],

['callable', [1]],
['callable', true],
['callable', 1.1],
['callable', 1],
['callable', (object)['name' => 'foo']],
['callable', 'a'],
['callable', (object) ['name' => 'foo']],
['callable', 'a'],

['float', [1]],
['float', true],
['float', function(){}],
['float', function () {
}],
['float', 1],
['float', (object)['name' => 'foo']],
['float', (object) ['name' => 'foo']],
['float', 'a'],

['int', [1]],
['int', true],
['int', function(){}],
['int', function () {
}],
['int', 1.1],
['int', (object)['name' => 'foo']],
['int', (object) ['name' => 'foo']],
['int', 'a', 'b'],

['object', [1]],
['object', true],
//skip this because closure pass as object
//['object',[function(){}, function(){}]],
['object', 1.1],
['object', 1],
['object', 'a'],

['string', [1]],
['string', true],
['string', function(){}],
['string', function () {
}],
['string', 1.1],
['string', 1],
['string', (object)['name' => 'foo']],
['string', (object) ['name' => 'foo']],
];
}

/**
* Test assign to array a wrong typed value.
*
Expand Down
Loading

0 comments on commit 1039625

Please sign in to comment.