Skip to content

Commit 1b51d7f

Browse files
committed
Merge pull request #7 from frastel/composer
Introducing Composer and PHPUnit support
2 parents 1206366 + 19345ba commit 1b51d7f

File tree

8 files changed

+139
-15
lines changed

8 files changed

+139
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
composer.lock

Example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 22.July.2013
66
*/
77

8-
require_once 'VerbalExpressions.php';
8+
$loader = require __DIR__ . '/vendor/autoload.php';
99

1010
$regex = new \VerbalExpressions\PHPVerbalExpressions\VerbalExpressions();
1111

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ VerbalExpressions is a PHP library that helps to construct hard regular expressi
1010

1111
$regex = new VerbalExpressions;
1212

13-
$regex ->startOfLine()
14-
->then("http")
15-
->maybe("s")
16-
->then("://")
17-
->maybe("www.")
18-
->anythingBut(" ")
19-
->endOfLine();
13+
$regex ->startOfLine()
14+
->then("http")
15+
->maybe("s")
16+
->then("://")
17+
->maybe("www.")
18+
->anythingBut(" ")
19+
->endOfLine();
2020

2121

2222
if($regex->test("http://github.com"))
23-
echo "valid url";
23+
echo "valid url";
2424
else
25-
echo "invalid url";
25+
echo "invalid url";
2626

2727
if (preg_match($regex, 'http://github.com')) {
28-
echo 'valid url';
28+
echo 'valid url';
2929
} else {
30-
echo 'invalud url';
30+
echo 'invalud url';
3131
}
3232

3333

@@ -36,8 +36,8 @@ echo "<pre>". $regex->getRegex() ."</pre>";
3636

3737

3838
echo $regex ->clean(array("modifiers" => "m", "replaceLimit" => 4))
39-
->find(' ')
40-
->replace("This is a small test http://somesite.com and some more text.", "-");
39+
->find(' ')
40+
->replace("This is a small test http://somesite.com and some more text.", "-");
4141

4242
```
4343

@@ -49,3 +49,13 @@ You can see an up to date list of all ports on [VerbalExpressions.github.io](htt
4949
- [Python](https://github.com/VerbalExpressions/PythonVerbalExpressions)
5050
- [Java](https://github.com/VerbalExpressions/JavaVerbalExpressions)
5151
- [C++](https://github.com/VerbalExpressions/CppVerbalExpressions)
52+
53+
## Building the project and running the tests
54+
The project supports Composer so you have to install [Composer](http://getcomposer.org/doc/00-intro.md#installation-nix) first before project setup.
55+
56+
curl -sS https://getcomposer.org/installer | php
57+
php composer.phar install --dev
58+
ln -s vendor/phpunit/phpunit/phpunit.php phpunit
59+
./phpunit
60+
61+

composer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "VerbalExpressions/PHPVerbalExpressions",
3+
"license": "MIT",
4+
"type": "project",
5+
"description": "PHP Regular expressions made easy",
6+
"require": {
7+
},
8+
"require-dev": {
9+
"phpunit/phpunit": "~3.7"
10+
},
11+
"minimum-stability": "stable",
12+
"autoload": {
13+
"psr-0": {
14+
"VerbalExpressions": "src/"
15+
}
16+
}
17+
}

phpunit.xml.dist

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="false"
6+
convertNoticesToExceptions="false"
7+
convertWarningsToExceptions="false"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
stopOnError="false"
11+
stopOnIncomplete="false"
12+
stopOnSkipped="false"
13+
syntaxCheck="false"
14+
bootstrap="tests/bootstrap.php">
15+
<testsuites>
16+
<testsuite name="Application Test Suite">
17+
<directory>./tests/</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<filter>
22+
<whitelist>
23+
<directory>./src</directory>
24+
</whitelist>
25+
</filter>
26+
</phpunit>

VerbalExpressions.php renamed to src/VerbalExpressions/PHPVerbalExpressions/VerbalExpressions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace VerbalExpressions\PHPVerbalExpressions;
4+
45
/**
56
* Verbal Expressions v0.1 (https://github.com/jehna/VerbalExpressions) ported in PHP
67
* @author Mihai Ionut Vilcu ([email protected])
@@ -475,7 +476,7 @@ public function test($value)
475476
return preg_match_all($this->getRegex(), $value);
476477
}
477478

478-
return preg_match($this->getRegex(), $value);
479+
return (bool) preg_match($this->getRegex(), $value);
479480
}
480481

481482
/**
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
use VerbalExpressions\PHPVerbalExpressions\VerbalExpressions;
4+
5+
class VerbalExpressionsTest extends \PHPUnit_Framework_TestCase
6+
{
7+
/**
8+
* @dataProvider provideValidUrls
9+
* @group functional
10+
*/
11+
public function testShouldPassWhenValidUrlGiven($url)
12+
{
13+
$regex = new VerbalExpressions();
14+
$this->buildUrlPattern($regex);
15+
16+
$this->assertTrue($regex->test($url));
17+
}
18+
19+
static public function provideValidUrls()
20+
{
21+
return array(
22+
array('http://github.com'),
23+
array('http://www.github.com'),
24+
array('https://github.com'),
25+
array('https://github.com'),
26+
array('https://github.com/blog'),
27+
array('https://foobar.github.com')
28+
);
29+
}
30+
31+
/**
32+
* @dataProvider provideInvalidUrls
33+
* @group functional
34+
*/
35+
public function testShouldFailWithInvalidUrls($url)
36+
{
37+
$regex = new VerbalExpressions();
38+
$this->buildUrlPattern($regex);
39+
40+
$this->assertFalse($regex->test($url));
41+
}
42+
43+
static public function provideInvalidUrls()
44+
{
45+
return array(
46+
array(' http://github.com'),
47+
array('foo'),
48+
array('htps://github.com'),
49+
array('http:/github.com'),
50+
array('https://github.com /blog'),
51+
);
52+
}
53+
54+
protected function buildUrlPattern(VerbalExpressions $regex)
55+
{
56+
return $regex->startOfLine()
57+
->then("http")
58+
->maybe("s")
59+
->then("://")
60+
->maybe("www.")
61+
->anythingBut(" ")
62+
->endOfLine();
63+
}
64+
}

tests/bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
$loader = require __DIR__ . '/../vendor/autoload.php';
4+
//$loader->add('PHPVerbalExpressions\Tests', __DIR__);

0 commit comments

Comments
 (0)