Skip to content

Commit ab2a488

Browse files
xZero707mihai-vlc
authored andcommitted
Tests and autoloading updates, use variadic parameters (#26)
* Tests and autoloading updates - Removed tests/bootstrap.php as redundant - Added autoload-dev to composer.json - Added namespace to test - Use new PHPUnit structure * Use variadic parameters instead of func_get_args() This breaks compatibilty with <PHP5.6 Advantages: up to 3 times faster than func_get_args() * Update from fabpot/php-cs-fixer to friendsofphp/php-cs-fixer fabpot/php-cs-fixer package is abandoned and no longer maintained * Add composer scripts (custom commands) # To run the tests composer test # To check project for PSR-2 compliance composer check-style # To check and fix style accordingly to PSR-2 standards composer fix-style * PSR-2 compliant fixes * Use squizlabs/php_codesniffer instead Bugfix: Non-existing command * Travis should run tests as well
1 parent bd1cd4c commit ab2a488

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
language: php
22
php:
3-
- '5.3'
4-
- '5.4'
5-
- '5.5'
63
- '5.6'
74
- '7.0'
85
- hhvm
96
- nightly
107
before_script:
118
- composer install
129
script:
13-
- vendor/bin/php-cs-fixer fix --level=psr2 --dry-run src
14-
- vendor/bin/php-cs-fixer fix --level=psr2 --dry-run tests/VerbalExpressionsTest.php
10+
- composer check-style
11+
- composer test

composer.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@
44
"type": "project",
55
"description": "PHP Regular expressions made easy",
66
"require": {
7-
"php": ">=5.3"
7+
"php": ">=5.6",
8+
"squizlabs/php_codesniffer": "^3.1"
89
},
910
"require-dev": {
10-
"phpunit/phpunit": "* >=4",
11-
"fabpot/php-cs-fixer": "^1.11"
12-
},
13-
"suggest": {
14-
"fabpot/php-cs-fixer": "PHP CS Fixer (testing for PSR-2 compliance)"
11+
"phpunit/phpunit": "* >=4"
1512
},
1613
"minimum-stability": "stable",
1714
"autoload": {
1815
"psr-4": {
1916
"VerbalExpressions\\PHPVerbalExpressions\\": "src/"
2017
}
18+
},
19+
"autoload-dev": {
20+
"psr-4": {
21+
"VerbalExpressions\\PHPVerbalExpressions\\Tests\\": "tests/"
22+
}
23+
},
24+
"scripts": {
25+
"test": "vendor/bin/phpunit",
26+
"check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
27+
"fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
2128
}
2229
}

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
stopOnIncomplete="false"
1212
stopOnSkipped="false"
1313
syntaxCheck="false"
14-
bootstrap="tests/bootstrap.php">
14+
bootstrap="vendor/autoload.php">
1515
<testsuites>
1616
<testsuite name="Application Test Suite">
1717
<directory>./tests/</directory>

src/VerbalExpressions.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,18 @@ public function any($value)
297297
* @return VerbalExpressions
298298
* @throws \InvalidArgumentException
299299
*/
300-
public function range()
300+
public function range(... $args)
301301
{
302-
$arg_num = func_num_args();
302+
$arg_num = count($args);
303303

304304
if ($arg_num%2 != 0) {
305305
throw new \InvalidArgumentException('Number of args must be even', 1);
306306
}
307307

308308
$value = '[';
309-
$arg_list = func_get_args();
310309

311310
for ($i = 0; $i < $arg_num;) {
312-
$value .= self::sanitize($arg_list[$i++]) . '-' . self::sanitize($arg_list[$i++]);
311+
$value .= self::sanitize($args[$i++]) . '-' . self::sanitize($args[$i++]);
313312
}
314313

315314
$value .= ']';

tests/VerbalExpressionsTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22

3+
namespace VerbalExpressions\PHPVerbalExpressions\Tests;
4+
35
use VerbalExpressions\PHPVerbalExpressions\VerbalExpressions;
6+
use PHPUnit\Framework\TestCase;
47

5-
class VerbalExpressionsTest extends PHPUnit_Framework_TestCase
8+
class VerbalExpressionsTest extends TestCase
69
{
710
/**
811
* @dataProvider provideValidUrls
@@ -314,7 +317,7 @@ public function testGetRegex()
314317
/**
315318
* @depends testGetRegex
316319
*/
317-
public function testGetRegex_multiple()
320+
public function testGetRegexMultiple()
318321
{
319322
$regex = new VerbalExpressions();
320323
$regex->startOfLine()
@@ -326,7 +329,7 @@ public function testGetRegex_multiple()
326329
/**
327330
* @expectedException InvalidArgumentException
328331
*/
329-
public function testRange_throwsException()
332+
public function testRangeThrowsException()
330333
{
331334
$regex = new VerbalExpressions();
332335
$regex->range(1, 2, 3);
@@ -335,7 +338,7 @@ public function testRange_throwsException()
335338
/**
336339
* @depends testGetRegex
337340
*/
338-
public function testRange_lowercase()
341+
public function testRangeLowercase()
339342
{
340343
$lowercaseAlpha = new VerbalExpressions();
341344
$lowercaseAlpha->range('a', 'z')
@@ -360,7 +363,7 @@ public function testRange_lowercase()
360363
/**
361364
* @depends testGetRegex
362365
*/
363-
public function testRange_uppercase()
366+
public function testRangeUppercase()
364367
{
365368
$uppercaseAlpha = new VerbalExpressions();
366369
$uppercaseAlpha->range('A', 'Z')
@@ -387,7 +390,7 @@ public function testRange_uppercase()
387390
/**
388391
* @depends testGetRegex
389392
*/
390-
public function testRange_numerical()
393+
public function testRangeNumerical()
391394
{
392395
$zeroToNine = new VerbalExpressions();
393396
$zeroToNine->range(0, 9)
@@ -418,7 +421,7 @@ public function testRange_numerical()
418421
/**
419422
* @depends testGetRegex
420423
*/
421-
public function testRange_hexadecimal()
424+
public function testRangeHexadecimal()
422425
{
423426
$hexadecimal = new VerbalExpressions();
424427
$hexadecimal->startOfLine()
@@ -435,9 +438,9 @@ public function testRange_hexadecimal()
435438
}
436439

437440
/**
438-
* @depends testRange_hexadecimal
441+
* @depends testRangeHexadecimal
439442
*/
440-
public function testRange_md5()
443+
public function testRangeMd5()
441444
{
442445
$md5 = new VerbalExpressions();
443446
$md5->startOfLine()
@@ -454,9 +457,9 @@ public function testRange_md5()
454457
}
455458

456459
/*
457-
* @depends testRange_hexadecimal
460+
* @depends testRangeHexadecimal
458461
*/
459-
public function testRange_sha1()
462+
public function testRangeSha1()
460463
{
461464
$sha1 = new VerbalExpressions();
462465
$sha1->startOfLine()

tests/bootstrap.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)