Skip to content

Commit

Permalink
Add PHP 8 support
Browse files Browse the repository at this point in the history
Prepare v0.8.0

Signed-off-by: Michael Haeuslmann <[email protected]>
  • Loading branch information
mihaeu committed May 2, 2021
1 parent 42e3ae0 commit 075d60d
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 83 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ php:
- "7.3"
- "7.2"

branches:
only:
- "main"

install:
- "mkdir -p build/logs"
- "composer validate --strict"
Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.8.0] - 2021-05-02
### Added
- PHP 8 support

## [0.7.0] - 2020-06-19
### Removed
- Removed support for Symfony 2 and 3
Expand Down Expand Up @@ -88,8 +92,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- first tagged release
- uml, text, dsm and metrics command

[Unreleased]: https://github.com/mihaeu/dephpend/compare/0.7.0...HEAD
[0.6.3]: https://github.com/mihaeu/dephpend/compare/0.6.3...0.7.0
[Unreleased]: https://github.com/mihaeu/dephpend/compare/0.8.0...HEAD
[0.8.0]: https://github.com/mihaeu/dephpend/compare/0.7.0...0.8.0
[0.7.0]: https://github.com/mihaeu/dephpend/compare/0.6.3...0.7.0
[0.6.3]: https://github.com/mihaeu/dephpend/compare/0.6.2...0.6.3
[0.6.2]: https://github.com/mihaeu/dephpend/compare/0.6.1...0.6.2
[0.6.1]: https://github.com/mihaeu/dephpend/compare/0.6.0...0.6.1
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ composer install

## Usage

You should almost always run QA tools without XDebug (unless you need code coverage of course). You could use a separate `php.ini` where XDebug is not loaded and pass that to php or you just use the `-n` option (this will however not load any extensions).
You should almost always run QA tools without XDebug (unless you need code coverage of course). You could use a separate `php.ini` where XDebug is not loaded and pass that to php or you just use the `-n` option (this will however not load any extensions, so you have to specify those separately).

```
# or bin/dephpend depending on how you installed this
$ php -n dephpend.phar
$ php -n -d extension=tokenizer.so -d extension=json.so -d extension=mbstring.so dephpend.phar
_ _____ _ _ _____ _
| | | __ \| | | | __ \ | |
__| | ___| |__) | |__| | |__) |__ _ __ __| |
/ _` |/ _ \ ___/| __ | ___/ _ \ '_ \ / _` |
| (_| | __/ | | | | | | | __/ | | | (_| |
\__,_|\___|_| |_| |_|_| \___|_| |_|\__,_| version 0.7.0
\__,_|\___|_| |_| |_|_| \___|_| |_|\__,_| version 0.8.0
Usage:
command [options] [arguments]
Expand Down Expand Up @@ -162,10 +162,10 @@ For more info just run `php dephpend.phar help text`.
For quick debugging use the `text` command. Say you want to find out which classes depend on XYZ and what XYZ depends on, you'd run:

```bash
php -n dephpend.phar text src | grep XYZ
php dephpend.phar text src | grep XYZ

# or for more complex applications use filters
php -n dephpend.phar text symfony --no-classes --depth 3 --exclude-regex='/Test/'
php dephpend.phar text symfony --no-classes --depth 3 --exclude-regex='/Test/'
```

### UML
Expand All @@ -175,10 +175,10 @@ Generates UML class or package diagrams of your source code. Requires [PlantUML]
You can either run

```bash
php -n dephpend.phar uml --output=uml.png src
php dephpend.phar uml --output=uml.png src

# or for post-processing
php -n dephpend.phar uml --output=uml.png --keep-uml src
php dephpend.phar uml --output=uml.png --keep-uml src
```

but most likely what you want to do is to use the `--no-classes` and `--depth[=DEPTH]` option. If your app has more than 20 classes, the UML will become messy if you don't use namespace instead of class level. Experiment with different depth values, but usually a depth of 2 or 3 is what you want.
Expand All @@ -190,9 +190,9 @@ If you've tried decrypting massive UML diagrams before, you know that they becom
This feature is still under construction and right now it's not really fun to use. If you still want to try run

```bash
php -n dephpend.phar dsm src > dependencies.html
php dephpend.phar dsm src > dependencies.html

php -n dephpend.phar dsm src --no-classes | bcat
php dephpend.phar dsm src --no-classes | bcat
```
or pipe it to something like [bcat](https://rtomayko.github.io/bcat/).

Expand All @@ -201,7 +201,7 @@ or pipe it to something like [bcat](https://rtomayko.github.io/bcat/).
The most common package metrics have already been implemented, but there are more to come. Check them out by running the following command:

```bash
php -n dephpend.phar metrics src
php dephpend.phar metrics src
```

This feature is not production ready and it's better to rely on [PHP Depend](https://pdepend.org) for this.
Expand Down Expand Up @@ -249,7 +249,7 @@ php -c php-with-traces.ini -S localhost:8080
The better the sample run and the more of your application it covers, the better the results are going to be. After that process the trace file using the `--dynamic` option.

```bash
php -n dephpend.phar text src \
php dephpend.phar text src \
--no-classes \
--filter-from=Mihaeu\\PhpDependencies \
--exclude-regex='/(Test)|(Mock)/' \
Expand All @@ -270,7 +270,7 @@ Using the `text` command it is fairly straightforward to create a script which v
#!/usr/bin/env php
<?php

$output = shell_exec('php -n dephpend.phar text src --no-classes');
$output = shell_exec('php dephpend.phar text src --no-classes');
$constraints = [
'OS --> .*Analyser',
'Analyser --> .*OS',
Expand Down
4 changes: 2 additions & 2 deletions bin/check-code-cov
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ ERROR_COLOR='\x1b[31;01m'
WARN_COLOR='\x1b[33;01m'

min_cov=95
cov=`vendor/bin/phpunit --coverage-text --colors=never \
cov=$(vendor/bin/phpunit --coverage-text --colors=never \
| egrep -o "Lines:[[:space:]]+([0-9])+" \
| head -n1 \
| sed 's/Lines: *//'`
| sed 's/Lines: *//')

if [ "$cov" -eq "100" ]; then
printf "${OK_COLOR}✓ Coverage is $cov%%${NO_COLOR}\n"
Expand Down
2 changes: 1 addition & 1 deletion bin/dephpend
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $name = <<<EOT
EOT;

$dependencyContainer = new DependencyContainer($internals);
$application = new Application($name, '0.7.0', $dependencyContainer->dispatcher());
$application = new Application($name, '0.8.0', $dependencyContainer->dispatcher());
$application->add($dependencyContainer->umlCommand());
$application->add($dependencyContainer->dotCommand());
$application->add($dependencyContainer->dsmCommand());
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"symfony/console": "^4 || ^5",
"symfony/event-dispatcher": "^4 || ^5"
},
"suggest": {
"ext-json": "*",
"ext-mbstring": "*",
"ext-tokenizer": "*"
},
"require-dev": {
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^8.0",
Expand All @@ -40,7 +45,8 @@
"Mihaeu\\PhpDependencies\\Tests\\Feature\\": ["tests/feature/"]
},
"files": [
"vendor/phpunit/phpunit/src/Framework/Assert/Functions.php"
"vendor/phpunit/phpunit/src/Framework/Assert/Functions.php",
"tests/feature/constants.php"
]
},
"support": {
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/UmlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->plantUmlWrapper->generate(
$this->dependencies->reduceEachDependency($this->postProcessors),
$destination,
$options['keep-uml']
$options['keep-uml'] ?? false
);

return 0;
Expand Down
5 changes: 1 addition & 4 deletions tests/feature/DsmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@

class DsmTest extends TestCase
{
private const DEPHPEND = PHP_BINARY.' -n '.__DIR__.'/../../bin/dephpend';
private const SRC = __DIR__.'/../../src';

public function testCreatesSimpleDsmInHtml(): void
{
assertRegExp(
'@\d: PhpParser</th><td>([1-9]\d*).+.+@s',
shell_exec(self::DEPHPEND.' dsm '.self::SRC.' --no-classes -d 2 --format=html')
shell_exec(DEPHPEND_BIN.' dsm '.SRC_PATH.' --no-classes --depth=2 --format=html')
);
}
}
8 changes: 3 additions & 5 deletions tests/feature/HelpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@

class HelpTest extends TestCase
{
private const DEPHPEND = PHP_BINARY.' -n '.__DIR__.'/../../bin/dephpend';

public function testNoArgumentsShowsHelp(): void
{
self::assertRegExp('/command \[options\] \[arguments\].*/s', shell_exec(self::DEPHPEND));
self::assertRegExp('/command \[options\] \[arguments\].*/s', shell_exec(DEPHPEND_BIN));
}

public function testHelpShowsHelp(): void
{
self::assertRegExp('/Usage:.*Options:.*Help:.*/s', shell_exec(self::DEPHPEND.' help'));
self::assertRegExp('/Usage:.*Options:.*Help:.*/s', shell_exec(DEPHPEND_BIN.' help'));
}

public function testShowsHelpForCommand(): void
{
self::assertRegExp('/Arguments:.*source.*Options:.*--internals.*/s', shell_exec(self::DEPHPEND.' help text'));
self::assertRegExp('/Arguments:.*source.*Options:.*--internals.*/s', shell_exec(DEPHPEND_BIN.' help text'));
}
}
4 changes: 1 addition & 3 deletions tests/feature/ListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

class ListTest extends TestCase
{
private const DEPHPEND = PHP_BINARY.' -n '.__DIR__.'/../../bin/dephpend';

public function testNoArgumentsShowsHelp(): void
{
assertRegExp('/dsm.*metrics.*text.*uml.*/s', shell_exec(self::DEPHPEND.' list'));
assertRegExp('/dsm.*metrics.*text.*uml.*/s', shell_exec(DEPHPEND_BIN.' list'));
}
}
5 changes: 1 addition & 4 deletions tests/feature/MetricsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@

class MetricsTest extends TestCase
{
private const DEPHPEND = PHP_BINARY.' -n '.__DIR__.'/../../bin/dephpend';
private const SRC = __DIR__.'/../../src';

public function testComputeMetricsForDephpend(): void
{
assertRegExp(
'/Classes:.*\d\d.*Abstract classes:.*\d+.*Abstractness:.*\d\.\d+/s',
shell_exec(self::DEPHPEND.' metrics '.self::SRC)
shell_exec(DEPHPEND_BIN.' metrics '.SRC_PATH)
);
}
}
28 changes: 2 additions & 26 deletions tests/feature/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,14 @@

class TextTest extends TestCase
{
private const DEPHPEND = PHP_BINARY.' -n '.__DIR__.'/../../bin/dephpend';
private const SRC = __DIR__.'/../../src';

public function testTextCommandOnDephpendSourceWithoutClassesAndWithRegexAndFromFilter(): void
{
assertEquals(
'Mihaeu\PhpDependencies\Analyser --> Mihaeu\PhpDependencies\Dependencies'.PHP_EOL
.'Mihaeu\PhpDependencies\Analyser --> Mihaeu\PhpDependencies\OS'.PHP_EOL,
shell_exec(self::DEPHPEND.' text '.self::SRC
.' --no-classes -f Mihaeu\\\\PhpDependencies\\\\Analyser -e "/Parser/"')
);
}

public function testTextCommandOnPhpUnitWithUnderscoreNamespaces(): void
{
$expected = <<<EOT
PHPUnit\Runner --> PHPUnit
PHPUnit\Runner --> PHPUnit\Util
PHPUnit\Runner --> SebastianBergmann
PHPUnit\Runner --> PHPUnit\Framework
PHPUnit\Runner --> SebastianBergmann\FileIterator
PHPUnit\Runner --> PHPUnit\Util\PHP
PHPUnit\Runner --> SebastianBergmann\Timer
PHPUnit\Runner --> Text
PHPUnit\Runner\Filter --> PHPUnit\Framework
PHPUnit\Runner\Filter --> PHPUnit\Util
EOT;
assertEquals(
$expected,
shell_exec(self::DEPHPEND.' text '.__DIR__.'/../../vendor/phpunit/phpunit/src'
.' --underscore-namespaces --no-classes -f "PHPUnit\\\\Runner"')
shell_exec(DEPHPEND_BIN.' text '.SRC_PATH
.' --no-classes --filter-from=Mihaeu\\\\PhpDependencies\\\\Analyser --exclude-regex="/Parser/"')
);
}
}
5 changes: 1 addition & 4 deletions tests/feature/UmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

class UmlTest extends TestCase
{
private const DEPHPEND = PHP_BINARY.' -n '.__DIR__.'/../../bin/dephpend';
private const SRC = __DIR__.'/../../src';

public function testCreatesUml(): void
{
system('plantuml -version > /dev/null 2>&1', $returnStatus);
Expand Down Expand Up @@ -45,7 +42,7 @@ public function testCreatesUml(): void

$tempFilePng = sys_get_temp_dir().'/dephpend-uml-test.png';
$tempFileUml = sys_get_temp_dir().'/dephpend-uml-test.uml';
shell_exec(self::DEPHPEND.' uml '.self::SRC.' --no-classes --keep-uml '
shell_exec(DEPHPEND_BIN.' uml '.SRC_PATH.' --no-classes --keep-uml '
.'--output="'.$tempFilePng.'" -f Mihaeu\\\\PhpDependencies\\\\OS');
assertEquals(
$expected,
Expand Down
9 changes: 9 additions & 0 deletions tests/feature/constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

const DEPHPEND_BIN = PHP_BINARY
. ' -n '
. ' -d extension=tokenizer.so'
. ' -d extension=json.so '
. ' -d extension=mbstring.so '
. __DIR__ . '/../../bin/dephpend';
const SRC_PATH = __DIR__ . '/../../src';
13 changes: 3 additions & 10 deletions tests/unit/Cli/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public function testWarningIfXDebugEnabled(): void
$errorOutput = $this->createMock(ErrorOutput::class);
$this->application->setErrorOutput($errorOutput);

// not sure how to mock this, so we test only one case
// not sure how to mock this, so we test only one case, there's always one error message regarding
// Symfony console setup, so if there's no xdebug loaded we still see one message
if (!extension_loaded('xdebug')) {
$errorOutput->expects(never())->method('writeln')->with(self::XDEBUG_WARNING);
$errorOutput->expects(once())->method('writeln');
} else {
$errorOutput->expects(exactly(2))->method('writeln');
}
Expand Down Expand Up @@ -88,8 +89,6 @@ public function testPrintsErrorMessageIfParserThrowsException(): void
public function testValidatesDsmInput(): void
{
$_SERVER['argv'] = ['', 'dsm', sys_get_temp_dir(), '--format=html'];
$input = $this->createMock(Input::class);
$output = $this->createMock(Output::class);

$errorOutput = $this->createMock(ErrorOutput::class);
$application = new Application('', '', $this->dispatcher);
Expand All @@ -102,8 +101,6 @@ public function testValidatesDsmInput(): void
public function testValidatesUmlInput(): void
{
$_SERVER['argv'] = ['', 'uml', sys_get_temp_dir(), '--output=test.png'];
$input = $this->createMock(Input::class);
$output = $this->createMock(Output::class);

$errorOutput = $this->createMock(ErrorOutput::class);
$application = new Application('', '', $this->dispatcher);
Expand All @@ -116,8 +113,6 @@ public function testValidatesUmlInput(): void
public function testValidatesMetricInput(): void
{
$_SERVER['argv'] = ['', 'metrics', sys_get_temp_dir()];
$input = $this->createMock(Input::class);
$output = $this->createMock(Output::class);

$errorOutput = $this->createMock(ErrorOutput::class);
$application = new Application('', '', $this->dispatcher);
Expand All @@ -130,8 +125,6 @@ public function testValidatesMetricInput(): void
public function testValidatesDotInput(): void
{
$_SERVER['argv'] = ['', 'dot', sys_get_temp_dir()];
$input = $this->createMock(Input::class);
$output = $this->createMock(Output::class);

$errorOutput = $this->createMock(ErrorOutput::class);
$application = new Application('', '', $this->dispatcher);
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/Cli/UmlCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function testCheckIfSourceExists(): void
public function testOutputHasToBeDefined(): void
{
$this->input->method('getArgument')->willReturn([sys_get_temp_dir()]);
$this->input->method('getOptions')->willReturn(['output' => null]);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Output not defined (use "help" for more information).');
$this->umlCommand->run(
Expand All @@ -62,11 +63,11 @@ public function testOutputHasToBeDefined(): void

public function testChecksIfDestinationIsWritable(): void
{
$mockFile = vfsStream::setup();
vfsStream::newFile('example', 0000)->at($mockFile);
$tempDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . rand() . time();
mkdir($tempDirectory, 0444);

$this->input->method('getArgument')->willReturn([sys_get_temp_dir()]);
$this->input->method('getOptions')->willReturn(['output' => $mockFile->url()]);
$this->input->method('getArgument')->willReturn([$tempDirectory]);
$this->input->method('getOptions')->willReturn(['output' => $tempDirectory . '/does_not_exist.png']);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Destination is not writable.');
$this->umlCommand->run(
Expand Down

0 comments on commit 075d60d

Please sign in to comment.