From fa0ef67d988b7b3eb3ddfb5ef704713bc1065175 Mon Sep 17 00:00:00 2001 From: Sebastian Rapetti Date: Wed, 7 Jun 2017 20:33:50 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/TypedObjectArray.php | 6 +- tests/TypedArrayTest.php | 157 ++++++++++++++++++--------------- tests/TypedObjectArrayTest.php | 30 +++---- tests/bootstrap.php | 2 +- 4 files changed, 106 insertions(+), 89 deletions(-) diff --git a/src/TypedObjectArray.php b/src/TypedObjectArray.php index 71e6901..1e799ee 100644 --- a/src/TypedObjectArray.php +++ b/src/TypedObjectArray.php @@ -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) { diff --git a/tests/TypedArrayTest.php b/tests/TypedArrayTest.php index b5a731d..c54cbc3 100644 --- a/tests/TypedArrayTest.php +++ b/tests/TypedArrayTest.php @@ -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'], @@ -34,7 +34,7 @@ function allowedTypeProvider() ['string'], ]; } - + /** * Test new instance. * @@ -44,7 +44,7 @@ public function testCreateInstance($type) { $this->assertInstanceOf(TypedArray::class, (new TypedArray($type))); } - + /** * Test new instance with not allowed type. * @@ -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. * @@ -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. * @@ -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. * @@ -185,50 +197,54 @@ 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 @@ -236,16 +252,17 @@ function wrongTypedValueProvider() ['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. * diff --git a/tests/TypedObjectArrayTest.php b/tests/TypedObjectArrayTest.php index 9fe4dba..b8bed37 100644 --- a/tests/TypedObjectArrayTest.php +++ b/tests/TypedObjectArrayTest.php @@ -13,7 +13,7 @@ use PHPUnit\Framework\TestCase; /** - * Typed Object Array Test + * Typed Object Array Test. */ class TypedObjectArrayTest extends TestCase { @@ -24,7 +24,7 @@ public function testCreateInstance() { $this->assertInstanceOf(TypedObjectArray::class, (new TypedObjectArray(ArrayObject::class))); } - + /** * Test new instance with not existent class. * @@ -34,24 +34,24 @@ public function testCreateInstanceWithNotExistentClass() { $this->assertInstanceOf(TypedObjectArray::class, (new TypedObjectArray(ArrayBadObject::class))); } - + /** * Test new instance passing right typed array to constructor. */ public function testCreateInstanceWithRightTypedArray() { $this->assertInstanceOf( - TypedObjectArray::class, + TypedObjectArray::class, (new TypedObjectArray( ArrayObject::class, [ - new ArrayObject([1,2,3]), - new ArrayObject([1.1,2.2,3.3]), - new ArrayObject(['a','b','c']) + new ArrayObject([1, 2, 3]), + new ArrayObject([1.1, 2.2, 3.3]), + new ArrayObject(['a', 'b', 'c']), ]) ) ); } - + /** * Test new instance passing array with invalid element to constructor. * @@ -60,28 +60,28 @@ public function testCreateInstanceWithRightTypedArray() public function testCreateInstanceWithWrongTypedArray() { $this->assertInstanceOf( - TypedObjectArray::class, + TypedObjectArray::class, (new TypedObjectArray( ArrayObject::class, [ - new ArrayObject([1,2,3]), - new ArrayObject([1.1,2.2,3.3]), - new SplStack() + new ArrayObject([1, 2, 3]), + new ArrayObject([1.1, 2.2, 3.3]), + new SplStack(), ]) ) ); } - + /** * Test assign to array a right typed value. */ public function testAssignrRightTypedValueToArray() { $array = new TypedObjectArray(ArrayObject::class); - $array[] = new ArrayObject([1,2,3]); + $array[] = new ArrayObject([1, 2, 3]); $this->assertEquals(1, $array->count()); } - + /** * Test assign to array a wrong typed value. * diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6ebd369..481ff39 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,4 +8,4 @@ * @license http://opensource.org/licenses/MIT MIT License */ include dirname(__DIR__).'/src/TypedArray.php'; -include dirname(__DIR__).'/src/TypedObjectArray.php'; \ No newline at end of file +include dirname(__DIR__).'/src/TypedObjectArray.php';