Skip to content

Commit 19a7e15

Browse files
author
Bruce Wells
committed
Housekeeping for line endings
1 parent 71b0187 commit 19a7e15

File tree

7 files changed

+112
-104
lines changed

7 files changed

+112
-104
lines changed

.gitiattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# no binary files in this repo and store all files with LF line endings.
2+
3+
# for windows do the following:
4+
# git config --global core.eol native
5+
# git config --global core.autocrlf true
6+
7+
* text=auto

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ bin/
44
composer.lock
55
.php_cs.cache
66
.phpunit.result.cache
7+
phpunit.xml

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ It is recommended you run [https://github.com/validator/validator](https://githu
1717
```
1818
java -Xss512k -cp vnu.jar nu.validator.servlet.Main 8888
1919
```
20-
In your phpunit.xml.dist config file, add the following lines in the **phpunit** element:
20+
If you are not using a local server, you will need to add the following lines to your phpunit.xml config in the **phpunit** element:
2121
```xml
2222
<php>
23-
<env name="PHPFUI\HTMLUnitTester\Extensions_url" value="http://127.0.0.1:8888"/>
24-
<env name="PHPFUI\HTMLUnitTester\Extensions_delay" value="0"/>
23+
<env name="PHPFUI\HTMLUnitTester\Extensions_url" value="http://validator.w3.org/nu"/>
24+
<env name="PHPFUI\HTMLUnitTester\Extensions_delay" value="500000"/>
2525
</php>
2626
```
27-
You can run against the online version at (http://validator.w3.org/nu/), but is recomended to use a delay of 500000 or higher to avoid overloading the server.
2827

2928
## Usage
3029
Extend your unit tests from \PHPFUI\HTMLUnitTester\Extensions

src/PHPFUI/HTMLUnitTester/ErrorConstraint.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
2-
2+
33
/*
44
* This file is part of the HTMLUnitTester package.
55
*
66
* (c) Bruce Wells <brucekwells@gmail.com>
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
10-
*/
11-
12-
namespace PHPFUI\HTMLUnitTester;
13-
10+
*/
11+
12+
namespace PHPFUI\HTMLUnitTester;
13+
1414
class ErrorConstraint extends \PHPUnit\Framework\Constraint\Constraint
1515
{
1616
/**
@@ -20,8 +20,8 @@ class ErrorConstraint extends \PHPUnit\Framework\Constraint\Constraint
2020
public function toString() : string
2121
{
2222
return 'is valid';
23-
}
24-
23+
}
24+
2525
/**
2626
* Return additional failure description where needed.
2727
*
@@ -34,8 +34,8 @@ public function toString() : string
3434
protected function additionalFailureDescription($other) : string
3535
{
3636
return implode("\n", $other->getErrors());
37-
}
38-
37+
}
38+
3939
/**
4040
* Returns the description of the failure.
4141
*
@@ -48,8 +48,8 @@ protected function additionalFailureDescription($other) : string
4848
protected function failureDescription($other) : string
4949
{
5050
return 'the markup ' . $this->toString();
51-
}
52-
51+
}
52+
5353
/**
5454
* Evaluates the constraint for parameter $other. Returns TRUE if the
5555
* constraint is met, FALSE otherwise.
@@ -60,6 +60,6 @@ protected function failureDescription($other) : string
6060
protected function matches($other) : bool
6161
{
6262
return ! $other->hasErrors();
63-
}
64-
65-
}
63+
}
64+
65+
}
Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
33
/**
44
* This file is part of the PHPFUI/HTMLUnitTester package
55
*
@@ -8,159 +8,159 @@
88
* For the full copyright and license information, please view
99
* the LICENSE.md file that was distributed with this source
1010
* code
11-
*/
12-
13-
namespace PHPFUI\HTMLUnitTester;
14-
11+
*/
12+
13+
namespace PHPFUI\HTMLUnitTester;
14+
1515
class Extensions extends \PHPUnit\Framework\TestCase implements \PHPUnit\Runner\Hook
16-
{
17-
16+
{
17+
1818
private static $throttle;
19-
private static $validator;
20-
19+
private static $validator;
20+
2121
public static function setUpBeforeClass() : void
2222
{
2323
$url = $_ENV[__CLASS__ . '_url'] ?? 'http://127.0.0.1:8888';
2424
$throttleMicroSeconds = $_ENV[__CLASS__ . '_delay'] ?? 0;
2525
if (! filter_var($url, FILTER_VALIDATE_URL))
2626
{
2727
throw new \PHPUnit\Framework\Exception($url . ' is not a valid URL');
28-
}
29-
28+
}
29+
3030
self::$throttle = new Throttle($throttleMicroSeconds);
3131
self::$validator = new \HtmlValidator\Validator($url);
32-
}
33-
32+
}
33+
3434
public function assertNotWarningCss(string $css, string $message = '') : void
3535
{
3636
$response = $this->validateCss($css);
3737
self::assertThat($response, new WarningConstraint(), $message);
38-
}
39-
38+
}
39+
4040
public function assertNotWarningCssFile(string $file, string $message = '') : void
4141
{
4242
$response = $this->validateCss($this->getFromFile($file));
4343
self::assertThat($response, new WarningConstraint(), $message);
44-
}
45-
44+
}
45+
4646
public function assertNotWarningCssUrl(string $url, string $message = '') : void
4747
{
4848
$response = $this->validateCss($this->getFromUrl($url));
4949
self::assertThat($response, new WarningConstraint(), $message);
50-
}
51-
50+
}
51+
5252
public function assertNotWarningFile(string $file, string $message = '') : void
5353
{
5454
$response = $this->validateHtml($this->getFromFile($file));
5555
self::assertThat($response, new WarningConstraint(), $message);
56-
}
57-
56+
}
57+
5858
public function assertNotWarningHtml(string $html, string $message = '') : void
5959
{
6060
$response = $this->validateHtml($html);
6161
self::assertThat($response, new WarningConstraint(), $message);
62-
}
63-
62+
}
63+
6464
public function assertNotWarningUrl(string $url, string $message = '') : void
6565
{
6666
$response = $this->validateHtml($this->getFromUrl($url));
6767
self::assertThat($response, new ErrorConstraint(), $message);
68-
}
69-
68+
}
69+
7070
public function assertValidCss(string $css, string $message = '') : void
7171
{
7272
$response = $this->validateCss($css);
7373
self::assertThat($response, new ErrorConstraint(), $message);
74-
}
75-
74+
}
75+
7676
public function assertValidCssFile(string $file, string $message = '') : void
7777
{
7878
$response = $this->validateCss($this->getFromFile($file));
7979
self::assertThat($response, new ErrorConstraint(), $message);
80-
}
81-
80+
}
81+
8282
public function assertValidCssUrl(string $url, string $message = '') : void
8383
{
8484
$response = $this->validateCss($this->getFromUrl($url));
8585
self::assertThat($response, new ErrorConstraint(), $message);
86-
}
87-
86+
}
87+
8888
public function assertValidFile(string $file, string $message = '') : void
8989
{
9090
$response = $this->validateHtml($this->getFromFile($file));
9191
self::assertThat($response, new ErrorConstraint(), $message);
92-
}
93-
92+
}
93+
9494
public function assertValidHtml(string $html, string $message = '') : void
9595
{
9696
$response = $this->validateHtml($html);
9797
self::assertThat($response, new ErrorConstraint(), $message);
98-
}
99-
98+
}
99+
100100
public function assertValidUrl(string $url, string $message = '') : void
101101
{
102102
$response = $this->validateHtml($this->getFromUrl($url));
103103
self::assertThat($response, new ErrorConstraint(), $message);
104-
}
105-
104+
}
105+
106106
private function getFromFile(string $file) : string
107107
{
108108
if (! file_exists($file))
109109
{
110110
throw new \PHPUnit\Framework\Exception("File {$file} was not found.\n");
111-
}
112-
111+
}
112+
113113
if (! is_readable($file))
114114
{
115115
throw new \PHPUnit\Framework\Exception("File {$file} is not readable.\n");
116116
}
117-
$html = file_get_contents($file);
118-
117+
$html = file_get_contents($file);
118+
119119
return $html;
120-
}
121-
120+
}
121+
122122
private function getFromUrl(string $url) : string
123123
{
124124
// Check that $url is a valid url
125125
if (false === filter_var($url, FILTER_VALIDATE_URL))
126126
{
127127
throw new \PHPUnit\Framework\Exception("Url {$url} is not valid.\n");
128-
}
129-
128+
}
129+
130130
$context = stream_context_create(['http' => ['user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0']]);
131-
$html = file_get_contents($url, false, $context);
132-
131+
$html = file_get_contents($url, false, $context);
132+
133133
// Check that something was returned
134134
if (! strlen($html))
135135
{
136136
throw new \PHPUnit\Framework\Exception("{$url} is empty.\n");
137-
}
138-
137+
}
138+
139139
return $html;
140-
}
141-
140+
}
141+
142142
private function validateCss(string $css) : \HtmlValidator\Response
143143
{
144144
if (false === stripos($css, 'html>'))
145145
{
146146
$css = '<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Title</title><style>' . $css . '</style></head><body><hr></body></html>';
147147
}
148148
self::$throttle->delay();
149-
$response = self::$validator->validateDocument($css);
150-
149+
$response = self::$validator->validateDocument($css);
150+
151151
return $response;
152-
}
153-
152+
}
153+
154154
private function validateHtml(string $html) : \HtmlValidator\Response
155155
{
156156
if (false === stripos($html, 'html>'))
157157
{
158158
$html = '<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Title</title></head><body>' . $html . '</body></html>';
159159
}
160160
self::$throttle->delay();
161-
$response = self::$validator->validateDocument($html);
162-
161+
$response = self::$validator->validateDocument($html);
162+
163163
return $response;
164-
}
165-
164+
}
165+
166166
}

src/PHPFUI/HTMLUnitTester/WarningConstraint.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
2-
2+
33
/*
44
* This file is part of the HTMLUnitTester package.
55
*
66
* (c) Bruce Wells <brucekwells@gmail.com>
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
10-
*/
11-
12-
namespace PHPFUI\HTMLUnitTester;
13-
10+
*/
11+
12+
namespace PHPFUI\HTMLUnitTester;
13+
1414
class WarningConstraint extends \PHPUnit\Framework\Constraint\Constraint
1515
{
1616
/**
@@ -20,8 +20,8 @@ class WarningConstraint extends \PHPUnit\Framework\Constraint\Constraint
2020
public function toString() : string
2121
{
2222
return 'is valid';
23-
}
24-
23+
}
24+
2525
/**
2626
* Return additional failure description where needed.
2727
*
@@ -34,8 +34,8 @@ public function toString() : string
3434
protected function additionalFailureDescription($other) : string
3535
{
3636
return implode("\n", $other->getWarnings());
37-
}
38-
37+
}
38+
3939
/**
4040
* Returns the description of the failure.
4141
*
@@ -48,8 +48,8 @@ protected function additionalFailureDescription($other) : string
4848
protected function failureDescription($other) : string
4949
{
5050
return 'the markup ' . $this->toString();
51-
}
52-
51+
}
52+
5353
/**
5454
* Evaluates the constraint for parameter $other. Returns TRUE if the
5555
* constraint is met, FALSE otherwise.
@@ -60,6 +60,6 @@ protected function failureDescription($other) : string
6060
protected function matches($other) : bool
6161
{
6262
return ! $other->hasWarnings();
63-
}
64-
65-
}
63+
}
64+
65+
}

0 commit comments

Comments
 (0)