Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from jobcloud/feat/bump-vendor
Browse files Browse the repository at this point in the history
feat: bump PHPUnit to min 6 to have compatible tests with PHP 7.2, too
  • Loading branch information
haeber authored Jun 11, 2018
2 parents 4b58b99 + 7cf8578 commit e834cd1
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 80 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm

before_script:
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A simple validator to check closure signatures.

## Requirements

PHP ~5.3
PHP ~7.0

## Installation

Expand All @@ -32,9 +32,11 @@ $validator = new Validator;
$givenSignature = $validator->getSignatureFromClosure($closure);
$wishedSignature = new Signature(array(
new Parameter('param1'),
new Parameter('param2')
$wishedSignature = new Signature(
[
new Parameter('param1'),
new Parameter('param2')
]
);
```

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
}
],
"require": {
"php": ">=5.3"
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "^6.0"
},
"autoload": {
"psr-4": { "Jobcloud\\ClosureValidator\\": "src/" }
Expand Down
12 changes: 6 additions & 6 deletions src/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ class Diff implements ToArrayInterface
/**
* @var Parameter[]|array
*/
protected $missingParameters = array();
protected $missingParameters = [];

/**
* @var Parameter[]|array
*/
protected $additionalParameters = array();
protected $additionalParameters = [];

/**
* @param Parameter[]|array $missingParameters
* @param Parameter[]|array $additionalParameters
*/
public function __construct(array $missingParameters = array(), array $additionalParameters = array())
public function __construct(array $missingParameters = [], array $additionalParameters = [])
{
foreach ($missingParameters as $missingParameter) {
$this->addMissingParameter($missingParameter);
Expand All @@ -40,10 +40,10 @@ public function __construct(array $missingParameters = array(), array $additiona
*/
public function toArray()
{
return array(
return [
'missingParameters' => $this->getParametersAsArray($this->missingParameters),
'additionalParameters' => $this->getParametersAsArray($this->additionalParameters)
);
];
}

/**
Expand All @@ -53,7 +53,7 @@ public function toArray()
*/
protected function getParametersAsArray(array $parameters)
{
$parametersAsArray = array();
$parametersAsArray = [];
foreach ($parameters as $parameter) {
$parametersAsArray[] = $parameter->toArray();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function __construct(string $name, $type = null)
*/
public function toArray()
{
return array(
return [
'name' => $this->getName(),
'type' => $this->getType()
);
];
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class Signature implements ToArrayInterface
/**
* @var Parameter[]|array
*/
protected $parameters = array();
protected $parameters = [];

/**
* @param Parameter[]|array $parameters
*/
public function __construct(array $parameters = array())
public function __construct(array $parameters = [])
{
foreach ($parameters as $parameter) {
$this->addParameter($parameter);
Expand All @@ -30,14 +30,14 @@ public function __construct(array $parameters = array())
*/
public function toArray()
{
$parameters = array();
$parameters = [];
foreach ($this->parameters as $parameter) {
$parameters[] = $parameter->toArray();
}

return array(
return [
'parameters' => $parameters
);
];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Validator
*/
public function getSignatureFromClosure(\Closure $closure)
{
$parameters = array();
$parameters = [];

$reflectionFunction = new \ReflectionFunction($closure);
foreach ($reflectionFunction->getParameters() as $reflectionParameter) {
Expand Down Expand Up @@ -70,7 +70,7 @@ public function validOrException(Signature $givenSignature, Signature $wishedSig
*/
protected function getDifferentParameter(array $parameters1, array $parameters2)
{
$differentParameters = array();
$differentParameters = [];
foreach ($parameters1 as $i => $parameter1) {
if (!isset($parameters2[$i]) || $parameter1 != $parameters2[$i]) {
$differentParameters[] = $parameter1;
Expand Down
35 changes: 18 additions & 17 deletions tests/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

use Jobcloud\ClosureValidator\Diff;
use Jobcloud\ClosureValidator\Parameter;
use PHPUnit\Framework\TestCase;

class DiffTest extends \PHPUnit_Framework_TestCase
class DiffTest extends TestCase
{
public function testIdentical()
{
$diff = new Diff();

$this->assertTrue($diff->isIdentical());
$this->assertEquals(
array(
'missingParameters' => array(),
'additionalParameters' => array()
),
[
'missingParameters' => [],
'additionalParameters' => []
],
$diff->toArray()
);
}
Expand All @@ -25,19 +26,19 @@ public function testMissingParameter()
{
$parameter = new Parameter('parameter');

$diff = new Diff(array($parameter));
$diff = new Diff([$parameter]);

$missingParameters = $diff->getMissingParameters();

$this->assertFalse($diff->isIdentical());
$this->assertSame($parameter, $missingParameters[0]);
$this->assertEquals(
array(
'missingParameters' => array(
[
'missingParameters' => [
$parameter->toArray()
),
'additionalParameters' => array()
),
],
'additionalParameters' => []
],
$diff->toArray()
);
}
Expand All @@ -46,19 +47,19 @@ public function testAdditionalParameter()
{
$parameter = new Parameter('parameter');

$diff = new Diff(array(), array($parameter));
$diff = new Diff([], [$parameter]);

$additionalParameters = $diff->getAdditionalParameters();

$this->assertFalse($diff->isIdentical());
$this->assertSame($parameter, $additionalParameters[0]);
$this->assertEquals(
array(
'missingParameters' => array(),
'additionalParameters' => array(
[
'missingParameters' => [],
'additionalParameters' => [
$parameter->toArray()
)
),
]
],
$diff->toArray()
);
}
Expand Down
11 changes: 6 additions & 5 deletions tests/ParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Jobcloud\Tests\ClosureValidator;

use Jobcloud\ClosureValidator\Parameter;
use PHPUnit\Framework\TestCase;

class ParameterTest extends \PHPUnit_Framework_TestCase
class ParameterTest extends TestCase
{
public function testWithoutType()
{
Expand All @@ -13,10 +14,10 @@ public function testWithoutType()
$this->assertEquals('parameter', $parameter->getName());
$this->assertNull($parameter->getType());
$this->assertEquals(
array(
[
'name' => 'parameter',
'type' => null
),
],
$parameter->toArray()
);
}
Expand All @@ -28,10 +29,10 @@ public function testWithType()
$this->assertEquals('parameter', $parameter->getName());
$this->assertEquals(Parameter::CLASS_NAME, $parameter->getType());
$this->assertEquals(
array(
[
'name' => 'parameter',
'type' => Parameter::CLASS_NAME
),
],
$parameter->toArray()
);
}
Expand Down
15 changes: 8 additions & 7 deletions tests/SignatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@

use Jobcloud\ClosureValidator\Parameter;
use Jobcloud\ClosureValidator\Signature;
use PHPUnit\Framework\TestCase;

class SignatureTest extends \PHPUnit_Framework_TestCase
class SignatureTest extends TestCase
{
public function testWithoutParameter()
{
$signature = new Signature();

$this->assertCount(0, $signature->getParameters());
$this->assertEquals(array('parameters' => array()), $signature->toArray());
$this->assertEquals(['parameters' => []], $signature->toArray());
}

public function testWithParameter()
{
$parameter = new Parameter('parameter', Parameter::CLASS_NAME);
$signature = new Signature(array($parameter));
$signature = new Signature([$parameter]);

$parameters = $signature->getParameters();

$this->assertCount(1, $parameters);
$this->assertEquals($parameter, $parameters[0]);
$this->assertEquals(
array(
'parameters' => array(
[
'parameters' => [
$parameter->toArray()
)
),
]
],
$signature->toArray()
);
}
Expand Down
Loading

0 comments on commit e834cd1

Please sign in to comment.