Skip to content

Commit 98fa017

Browse files
committed
Fix test scripts
They now all depend on vendor dev deps Upgrade phpunit Add coverage check script that can fail the build
1 parent fc73017 commit 98fa017

19 files changed

+76
-37
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ example/results
99
.DS_Store
1010
cache.properties
1111
.tmp
12+
.phpunit.result.cache
13+
.php_cs.cache

.php_cs

-11
This file was deleted.

.php_cs.dist

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__ . '/src/');
5+
6+
return PhpCsFixer\Config::create()
7+
->setRules([
8+
'@PSR2' => true
9+
])
10+
->setFinder($finder);
11+

bin/coverage

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
2+
3+
4+
# Go to the root dir so configs and vendor dir is found
5+
cd $(git rev-parse --show-toplevel)
26

37
tmpfile="./.tmp/code-coverage"
4-
composer exec -- phpunit --colors=auto --coverage-html="$tmpfile" --coverage-text
8+
tmpfile_php="./.tmp/code-coverage_php"
9+
10+
./vendor/bin/phpunit --colors=auto --coverage-php "$tmpfile_php" --coverage-html="$tmpfile" --coverage-text

bin/coverage-check.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
$requiredLineCoverage = 60.0;
3+
4+
chdir(dirname(__FILE__));
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
exec('./coverage');
9+
$coverage = require_once('../.tmp/code-coverage_php');
10+
$report = $coverage->getReport();
11+
$percentage = round(($report->getNumExecutedLines() / $report->getNumExecutableLines()) * 100, 2);
12+
13+
print "Line Coverage: " . $percentage;
14+
if ($percentage < $requiredLineCoverage) {
15+
print "\nTOO LOW: should be >= " . $requiredLineCoverage . "%\n";
16+
exit(1);
17+
} else {
18+
print "\nOK\n";
19+
exit(0);
20+
}

bin/fix-style

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
2+
3+
cd $(git rev-parse --show-toplevel)
24

35
echo -e "\nPHPCBF"
4-
phpcbf --standard=PSR2 tests/ src/
6+
./vendor/bin/phpcbf --standard=PSR2 tests/ src/
57
echo -e "\nPHP-CS-FIXER"
6-
php-cs-fixer fix --verbose
8+
./vendor/bin/php-cs-fixer fix --verbose

bin/test

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
2+
3+
# Go to the root dir first, so configs and vendor dir is found
4+
cd $(git rev-parse --show-toplevel)
25

36
echo -e "\nPHPLINT src/:"
47
find src/ -iname "*.php" -print0 | xargs -0 -n1 php -l 1>/dev/null || exit $?
58
echo -e "\nPHPLINT tests/:"
69
find tests/ -iname "*.php" -print0 | xargs -0 -n1 php -l 1>/dev/null || exit $?
710
echo -e "\nPHPUNIT:"
8-
composer exec -- phpunit --stop-on-error --stop-on-failure --report-useless-tests --colors=auto || exit $?
11+
./vendor/bin/phpunit --stop-on-error --stop-on-failure --colors=auto || exit $?
912
echo -e "\nPHPCS src/:"
10-
phpcs --warning-severity=0 --standard=PSR2 src/ || exit $?
13+
./vendor/bin/phpcs --warning-severity=0 --standard=PSR2 src/ || exit $?
1114
echo -e "\nPHPCS tests/:"
12-
phpcs --warning-severity=0 --standard=PSR2 tests/ || exit $?
15+
./vendor/bin/phpcs --warning-severity=0 --standard=PSR2 tests/ || exit $?
1316
echo -e "\nPHPMD src/:"
14-
phpmd src/ text phpmd.xml || exit $?
17+
./vendor/bin/phpmd src/ text phpmd.xml || exit $?
1518
echo -e "\nPHPMD tests/:"
16-
phpmd tests/ text phpmd-tests.xml || exit $?
19+
./vendor/bin/phpmd tests/ text phpmd-tests.xml || exit $?
1720
echo -e "\nPHPCPD src/:"
18-
phpcpd --min-lines=7 --min-tokens=30 --fuzzy -v src/ || exit $?
21+
./vendor/bin/phpcpd --min-lines=7 --min-tokens=30 --fuzzy -v src/ || exit $?
1922
echo -e "\nPHPCPD tests/:"
20-
phpcpd --min-lines=7 --min-tokens=30 --fuzzy tests/ #|| exit $?
23+
./vendor/bin/phpcpd --min-lines=7 --min-tokens=30 --fuzzy tests/ || exit $?
24+
2125

22-
echo "\n\n All Done, no failures.\n"
26+
echo -e "\n\n All Done, no failures.\n"

composer.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
"vdb/uri": "^0.2"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^5.7.0"
27+
"phpunit/phpunit": "^8.0.0",
28+
"squizlabs/php_codesniffer": "^3.0.0",
29+
"phpmd/phpmd": "^2.0.0",
30+
"sebastian/phpcpd": "^4.0.0",
31+
"friendsofphp/php-cs-fixer": "^2.0.0"
2832
},
2933
"autoload": {
3034
"psr-0": {

phpunit.xml.dist

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
colors="true"
66
processIsolation="false"
77
stopOnFailure="false"
8-
syntaxCheck="false"
98
bootstrap="./vendor/autoload.php">
109
<filter>
1110
<whitelist processUncoveredFilesFromWhitelist="true">

src/VDB/Spider/Spider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct($seed, $spiderId = null)
5454

5555
// This makes the spider handle signals gracefully and allows us to do cleanup
5656
if (php_sapi_name() == 'cli') {
57-
declare (ticks = 1);
57+
declare(ticks = 1);
5858
if (function_exists('pcntl_signal')) {
5959
pcntl_signal(SIGTERM, array($this, 'handleSignal'));
6060
pcntl_signal(SIGINT, array($this, 'handleSignal'));

src/VDB/Spider/Uri/UriDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,5 @@ public function getFragment()
126126
return $this->decorated->getFragment();
127127
}
128128

129-
// @codeCoverageIgnoreEnd
129+
// @codeCoverageIgnoreEnd
130130
}

tests/VDB/Spider/Tests/Discoverer/DiscovererSetTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DiscovererSetTest extends DiscovererTestCase
2626
private $discovererSet;
2727

2828

29-
public function setUp()
29+
public function setUp(): void
3030
{
3131
parent::setUp();
3232
}

tests/VDB/Spider/Tests/Discoverer/DiscovererTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ abstract class DiscovererTestCase extends TestCase
3737

3838
protected $uriInBody1;
3939

40-
protected function setUp()
40+
protected function setUp(): void
4141
{
4242
$this->uriInBody1 = 'http://php-spider.org/contact/';
4343

tests/VDB/Spider/Tests/Downloader/DownloaderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DownloaderTest extends TestCase
3939
*/
4040
protected $html;
4141

42-
public function setUp()
42+
public function setUp(): void
4343
{
4444
$this->html = file_get_contents(__DIR__ . '/../Fixtures/DownloaderTestHTMLResource.html');
4545
$this->resource = new Resource(

tests/VDB/Spider/Tests/Filter/Postfetch/MimeTypeFilterTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MimeTypeFilterTest extends TestCase
2626
/** @var DiscoveredUri */
2727
protected $uri;
2828

29-
protected function setUp()
29+
protected function setUp(): void
3030
{
3131
$this->uri = new DiscoveredUri(new Uri('http://foobar.com/image.jpg'));
3232

tests/VDB/Spider/Tests/PersistenceHandler/FileSerializedResourcePersistenceHandlerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FileSerializedResourcePersistenceHandlerTest extends TestCase
2727
protected $persistenceRootPath;
2828

2929

30-
public function setUp()
30+
public function setUp(): void
3131
{
3232
$this->persistenceRootPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'spider-UT' . DIRECTORY_SEPARATOR;
3333
exec('rm -rf ' . $this->persistenceRootPath);

tests/VDB/Spider/Tests/ResourceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ResourceTest extends TestCase
2020
*/
2121
protected $html;
2222

23-
protected function setUp()
23+
protected function setUp(): void
2424
{
2525
$this->html = file_get_contents(__DIR__ . '/Fixtures/ResourceTestHTMLResource.html');
2626
$this->resource = new Resource(

tests/VDB/Spider/Tests/SpiderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class SpiderTest extends TestCase
8383
*
8484
* Note: E links to F.
8585
*/
86-
protected function setUp()
86+
protected function setUp(): void
8787
{
8888
$this->spider = new Spider('http://php-spider.org/A');
8989

tests/VDB/Spider/Tests/TestCase.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
use VDB\Spider\Uri\DiscoveredUri;
1717
use VDB\Uri\Uri;
1818

19+
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
20+
1921
/**
2022
*
2123
*/
22-
class TestCase extends \PHPUnit_Framework_TestCase
24+
class TestCase extends PHPUnitTestCase
2325
{
2426
/**
2527
* @param DiscoveredUri $uri

0 commit comments

Comments
 (0)