Skip to content

Commit

Permalink
Upgrade to latest versions of phpunit and Carbon (#30)
Browse files Browse the repository at this point in the history
revert to phpunit 6.0

make shim methods static

for compatibility with php 7.2 and 7.3

use void to match current signature

only apply shim if php <= 7.2

allow travis failures for hhvm and php 5.6
  • Loading branch information
jijoel authored and William committed Feb 19, 2019
1 parent 65351a2 commit d978b8f
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 26 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- hhvm

matrix:
allow_failures:
- php: hhvm
- php: 5.6

before_script:
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

script:
- phpunit
- phpunit
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
"require": {
"illuminate/support": "~5.3",
"illuminate/validation": "~5.3",
"nesbot/carbon": "~1.0"
"nesbot/carbon": "~1.0|~2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "~6.0|~7.0|~8.0"
},
"autoload": {
"psr-4": {
"Waavi\\Sanitizer\\": "src/"
}
},
"autoload-dev": {
"classmap": ["tests"]
},
"extra": {
"laravel": {
"providers": [
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Sanitizer Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
1 change: 1 addition & 0 deletions tests/CustomFilter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Contracts\Filter;

class CustomFilter implements Filter
Expand Down
3 changes: 2 additions & 1 deletion tests/FactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Laravel\Factory;
use Waavi\Sanitizer\Sanitizer;

class FactoryTest extends PHPUnit_Framework_TestCase
class FactoryTest extends TestCase
{
public function sanitize($data, $rules)
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Filters/CapitalizeTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class CapitalizeTest extends PHPUnit_Framework_TestCase
class CapitalizeTest extends TestCase
{
/**
* @param $data
Expand Down
19 changes: 11 additions & 8 deletions tests/Filters/CastTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class CastTest extends PHPUnit_Framework_TestCase
class CastTest extends TestCase
{
use _PHPUnitShim;

/**
* @param $data
* @param $rules
Expand All @@ -17,19 +20,19 @@ public function sanitize($data, $rules)

/**
* @test
* @expectedException \InvalidArgumentException
*/
public function it_throws_exception_when_no_cast_type_is_set()
{
$this->expectException(\InvalidArgumentException::class);
$this->sanitize(['name' => 'Name'], ['name' => 'cast']);
}

/**
* @test
* @expectedException \InvalidArgumentException
*/
public function it_throws_exception_when_non_existing_cast_type_is_set()
{
$this->expectException(\InvalidArgumentException::class);
$this->sanitize(['name' => 'Name'], ['name' => 'cast:bullshit']);
}

Expand All @@ -39,7 +42,7 @@ public function it_throws_exception_when_non_existing_cast_type_is_set()
public function it_casts_to_integer()
{
$results = $this->sanitize(['var' => '15.6'], ['var' => 'cast:integer']);
$this->assertInternalType('int', $results['var']);
$this->assertIsInt($results['var']);
$this->assertEquals(15, $results['var']);
}

Expand All @@ -49,7 +52,7 @@ public function it_casts_to_integer()
public function it_casts_to_float()
{
$results = $this->sanitize(['var' => '15.6'], ['var' => 'cast:double']);
$this->assertInternalType('float', $results['var']);
$this->assertIsFloat($results['var']);
$this->assertEquals(15.6, $results['var']);
}

Expand All @@ -59,7 +62,7 @@ public function it_casts_to_float()
public function it_casts_to_string()
{
$results = $this->sanitize(['var' => 15], ['var' => 'cast:string']);
$this->assertInternalType('string', $results['var']);
$this->assertIsString($results['var']);
$this->assertEquals('15', $results['var']);
}

Expand All @@ -69,7 +72,7 @@ public function it_casts_to_string()
public function it_casts_to_boolean()
{
$results = $this->sanitize(['var' => 15], ['var' => 'cast:boolean']);
$this->assertInternalType('boolean', $results['var']);
$this->assertIsBool($results['var']);
$this->assertEquals(true, $results['var']);
}

Expand Down Expand Up @@ -116,7 +119,7 @@ public function it_casts_json_to_array()
];
$encodedData = json_encode($data);
$results = $this->sanitize(['var' => $encodedData], ['var' => 'cast:array']);
$this->assertInternalType('array', $results['var']);
$this->assertIsArray($results['var']);
$this->assertEquals('Name', $results['var']['name']);
$this->assertEquals(15.6, $results['var']['cost']);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Filters/DigitTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class DigitTest extends PHPUnit_Framework_TestCase
class DigitTest extends TestCase
{
/**
* @param $data
Expand Down
3 changes: 2 additions & 1 deletion tests/Filters/EscapeHTMLTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class EscapeHTMLTest extends PHPUnit_Framework_TestCase
class EscapeHTMLTest extends TestCase
{
/**
* @param $data
Expand Down
5 changes: 3 additions & 2 deletions tests/Filters/FormatDateTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class FormatDateTest extends PHPUnit_Framework_TestCase
class FormatDateTest extends TestCase
{
/**
* @param $data
Expand Down Expand Up @@ -32,10 +33,10 @@ public function it_formats_dates()

/**
* @test
* @expectedException \InvalidArgumentException
*/
public function it_requires_two_arguments()
{
$this->expectException(\InvalidArgumentException::class);
$data = [
'name' => '21/03/1983',
];
Expand Down
3 changes: 2 additions & 1 deletion tests/Filters/LowercaseTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class LowercaseTest extends PHPUnit_Framework_TestCase
class LowercaseTest extends TestCase
{
/**
* @param $data
Expand Down
3 changes: 2 additions & 1 deletion tests/Filters/StripTagsTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class StripTagsTest extends PHPUnit_Framework_TestCase
class StripTagsTest extends TestCase
{
/**
* @param $data
Expand Down
3 changes: 2 additions & 1 deletion tests/Filters/TrimTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class TrimTest extends PHPUnit_Framework_TestCase
class TrimTest extends TestCase
{
/**
* @param $data
Expand Down
3 changes: 2 additions & 1 deletion tests/Filters/UppercaseTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class UppercaseTest extends PHPUnit_Framework_TestCase
class UppercaseTest extends TestCase
{
/**
* @param $data
Expand Down
6 changes: 3 additions & 3 deletions tests/SanitizerTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Waavi\Sanitizer\Sanitizer;

class SanitizerTest extends PHPUnit_Framework_TestCase
class SanitizerTest extends TestCase
{
/**
* @param $data
Expand Down Expand Up @@ -78,11 +79,10 @@ public function test_wildcard_filters()

/**
* @test
* @expectedException \InvalidArgumentException
*/
public function it_throws_exception_if_non_existing_filter()
{
$this->setExpectedException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$data = [
'name' => ' HellO EverYboDy ',
];
Expand Down
37 changes: 37 additions & 0 deletions tests/_PHPUnitShim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

if (version_compare(PHP_VERSION, '7.2.0', '>=')) {
trait _PHPUnitShim {}
}

if (version_compare(PHP_VERSION, '7.2.0', '<')) {
trait _PHPUnitShim
{

public function assertIsArray($actual, $message='')
{
$this->assertInternalType('array', $actual, $message);
}

public function assertIsBool($actual, $message='')
{
$this->assertInternalType('bool', $actual, $message);
}

public function assertIsFloat($actual, $message='')
{
$this->assertInternalType('float', $actual, $message);
}

public function assertIsInt($actual, $message='')
{
$this->assertInternalType('integer', $actual, $message);
}

public function assertIsString($actual, $message='')
{
$this->assertInternalType('string', $actual, $message);
}

}
}

0 comments on commit d978b8f

Please sign in to comment.