Skip to content

Commit 9519299

Browse files
authored
Merge pull request #14 from researchgate/upgrade-to-php-timer-5
Update phpunit/php-timer to 4.x/5.x
2 parents f6537af + dec6461 commit 9519299

File tree

8 files changed

+28
-60
lines changed

8 files changed

+28
-60
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/build/
44
/composer.lock
55
composer.phar
6+
/.phpunit.result.cache

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"require": {
1212
"php": "^7.1",
1313
"symfony/console" : "^2.1|^3.0|^4.0|^5.0",
14-
"phpunit/php-timer": "^2.0"
14+
"phpunit/php-timer": "^4.0|^5.0"
1515
},
1616
"autoload" : {
1717
"psr-4" : {
@@ -22,6 +22,6 @@
2222
"phpnsc"
2323
],
2424
"require-dev": {
25-
"phpunit/phpunit": "^7.0"
25+
"phpunit/phpunit": "^9.0"
2626
}
2727
}

src/Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace rg\tools\phpnsc;
1212

13-
use SebastianBergmann\Timer\Timer;
13+
use SebastianBergmann\Timer\ResourceUsageFormatter;
1414
use Symfony\Component\Console;
1515
use Symfony\Component\Console\Application;
1616

@@ -99,7 +99,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
9999
}
100100

101101
$outputClass->printAll();
102-
$outputClass->writeln(Timer::resourceUsage());
102+
$outputClass->writeln((new ResourceUsageFormatter())->resourceUsageSinceStartOfRequest());
103103

104104
return $foundError ? 1 : 0;
105105
}

test/rg/tools/phpnsc/ClassScannerTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<?php
2-
namespace rg\test\tools\phpnsc;
2+
namespace rg\tools\phpnsc;
33

44
use PHPUnit\Framework\TestCase;
5-
use rg\tools\phpnsc\ClassScanner;
6-
use rg\tools\phpnsc\ConsoleOutput;
7-
use rg\tools\phpnsc\FilesystemAccess;
85
use Symfony\Component\Console\Output\NullOutput;
96

107
class ClassScannerTest extends TestCase
@@ -19,7 +16,7 @@ class ClassScannerTest extends TestCase
1916
*/
2017
private $classScanner;
2118

22-
protected function setUp() {
19+
protected function setUp(): void {
2320
parent::setUp();
2421
$output = new NullOutput();
2522
$outputClass = new ConsoleOutput($output);

test/rg/tools/phpnsc/ConfigTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
<?php
2-
namespace rg\test\tools\phpnsc;
2+
namespace rg\tools\phpnsc;
33

44
use PHPUnit\Framework\TestCase;
5-
use rg\tools\phpnsc\Config;
6-
use rg\tools\phpnsc\FilesystemAccess;
75

86
class ConfigTest extends TestCase
97
{
10-
/**
11-
* @var FilesystemMock
12-
*/
13-
private $filesystem;
148

159
/**
1610
* @var Config
1711
*/
1812
private $config;
1913

20-
protected function setUp() {
14+
protected function setUp(): void {
2115
parent::setUp();
22-
$this->filesystem = new FilesystemMock('/root/folder');
23-
$this->config = new Config($this->filesystem);
16+
$filesystem = new FilesystemMock('/root/folder');
17+
$this->config = new Config($filesystem);
2418
}
2519

2620
public function testLoadConfig() {
@@ -36,7 +30,7 @@ public function testLoadConfig() {
3630

3731
class FilesystemMock extends FilesystemAccess
3832
{
39-
public function getFile($filename) {
33+
public function getFile($filename): string {
4034
return '{
4135
"vendor" : "researchgate",
4236
"folders" : {

test/rg/tools/phpnsc/DirectoryScannerTest.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
<?php
2-
namespace rg\test\tools\phpnsc;
2+
namespace rg\tools\phpnsc;
33

44
use PHPUnit\Framework\TestCase;
5-
use rg\tools\phpnsc\DirectoryScanner;
6-
use rg\tools\phpnsc\FilesystemAccess;
75

86
class DirectoryScannerTest extends TestCase
97
{
10-
/**
11-
* @var FilesystemMock
12-
*/
13-
private $filesystem;
148

159
/**
1610
* @var DirectoryScanner
1711
*/
1812
private $directoryScanner;
1913

20-
/**
21-
* @var string
22-
*/
23-
private $root;
24-
25-
protected function setUp() {
14+
protected function setUp(): void {
2615
parent::setUp();
27-
$this->filesystem = new DirectoryScannerFilesystemMock('/root/folder');
28-
$this->root = '/root/folder';
29-
$this->directoryScanner = new DirectoryScanner($this->filesystem, $this->root, '/');
16+
$filesystem = new DirectoryScannerFilesystemMock('/root/folder');
17+
$root = '/root/folder';
18+
$this->directoryScanner = new DirectoryScanner($filesystem, $root, '/');
3019
}
3120

3221
public function testReadDirectory() {
@@ -103,11 +92,11 @@ public function openDirectory($directory) {
10392
return isset($this->filesystem[$directory]) ? $handle : false;
10493
}
10594

106-
public function closeDirectory($handle) {
95+
public function closeDirectory($handle): bool {
10796
return true;
10897
}
10998

110-
public function isDir($path) {
99+
public function isDir($path): bool {
111100
return isset($this->filesystem[$path]);
112101
}
113102

test/rg/tools/phpnsc/NamespaceDependencyCheckerTest.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
11
<?php
2-
namespace rg\test\tools\phpnsc;
2+
namespace rg\tools\phpnsc;
33

44
use PHPUnit\Framework\TestCase;
5-
use rg\tools\phpnsc\ClassScanner;
6-
use rg\tools\phpnsc\FilesystemAccess;
7-
use rg\tools\phpnsc\NamespaceDependencyChecker;
8-
use rg\tools\phpnsc\Output;
95
use Symfony\Component\Console\Output\NullOutput;
106
use Symfony\Component\Console\Output\OutputInterface;
117

128
class NamespaceDependencyCheckerTest extends TestCase
139
{
14-
/**
15-
* @var ClassModifierFilesystemMock
16-
*/
17-
private $filesystem;
1810

1911
/**
2012
* @var array
2113
*/
2214
private $files;
2315

24-
/**
25-
* @var ClassScanner
26-
*/
27-
private $classScanner;
28-
2916
/**
3017
* @var NamespaceDependencyChecker
3118
*/
@@ -36,15 +23,15 @@ class NamespaceDependencyCheckerTest extends TestCase
3623
*/
3724
private $outputClass;
3825

39-
protected function setUp() {
26+
protected function setUp(): void {
4027
parent::setUp();
4128
$output = new NullOutput();
4229
$this->outputClass = new DependencyCheckerOutputMock($output);
43-
$this->filesystem = new ClassModifierFilesystemMock('/root/folder');
44-
$this->files = array_keys($this->filesystem->filesystem);
45-
$this->classScanner = new ClassScanner($this->filesystem, $this->outputClass);
46-
$this->classScanner->parseFilesForClassesAndInterfaces($this->files, '/root/folder', 'vendor');
47-
$this->dependencyChecker = new NamespaceDependencyChecker($this->filesystem, $this->classScanner, 'vendor', '/root/folder', $this->outputClass);
30+
$filesystem = new ClassModifierFilesystemMock('/root/folder');
31+
$this->files = array_keys($filesystem->filesystem);
32+
$classScanner = new ClassScanner($filesystem, $this->outputClass);
33+
$classScanner->parseFilesForClassesAndInterfaces($this->files, '/root/folder', 'vendor');
34+
$this->dependencyChecker = new NamespaceDependencyChecker($filesystem, $classScanner, 'vendor', '/root/folder', $this->outputClass);
4835
}
4936

5037
public function testModifyFiles() {

test/rg/tools/phpnsc/NamespaceStringTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
2-
namespace rg\test\tools\phpnsc;
2+
namespace rg\tools\phpnsc;
33

44
use PHPUnit\Framework\TestCase;
5-
use rg\tools\phpnsc\NamespaceString;
65

76
class NamespaceStringTest extends TestCase {
7+
88
public function testCreateNamespaceString() {
99
$namespaceVendor = 'vendor';
1010
$root = '/root/folder';

0 commit comments

Comments
 (0)