-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from smeghead/add-hide-private-option
feat: add `--hide-private` option. #67
- Loading branch information
Showing
8 changed files
with
263 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
use Smeghead\PhpClassDiagram\Config\Options; | ||
use Smeghead\PhpClassDiagram\DiagramElement\{ | ||
Relation, | ||
Entry, | ||
}; | ||
use Smeghead\PhpClassDiagram\Php\PhpReader; | ||
|
||
final class HidePrivateTest extends TestCase | ||
{ | ||
private string $fixtureDir; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->fixtureDir = sprintf('%s/fixtures', __DIR__); | ||
} | ||
|
||
public function testDefault(): void | ||
{ | ||
$directory = sprintf('%s/hide-private', $this->fixtureDir); | ||
$options = new Options([ | ||
]); | ||
$files = [ | ||
'product/Product.php', | ||
]; | ||
$entries = []; | ||
foreach ($files as $f) { | ||
$filename = sprintf('%s/hide-private/%s', $this->fixtureDir, $f); | ||
$classes = PhpReader::parseFile($directory, $filename, $options); | ||
$entries[] = array_map(fn($c) => new Entry(dirname($f), $c->getInfo(), $options), $classes); | ||
} | ||
$rel = new Relation(array_merge(...$entries), $options); | ||
|
||
$expected = <<<EOS | ||
@startuml class-diagram | ||
package product as product { | ||
class "Product" as product_Product { | ||
+name : string | ||
-memo : string | ||
+publicFunction(param1) | ||
-privateFunction(param1) | ||
} | ||
} | ||
@enduml | ||
EOS; | ||
$this->assertSame($expected, implode(PHP_EOL, $rel->dump()), 'output PlantUML script.'); | ||
} | ||
|
||
public function testHidePrivate(): void | ||
{ | ||
$directory = sprintf('%s/hide-private', $this->fixtureDir); | ||
$options = new Options([ | ||
'hide-private' => true, | ||
]); | ||
$files = [ | ||
'product/Product.php', | ||
]; | ||
$entries = []; | ||
foreach ($files as $f) { | ||
$filename = sprintf('%s/hide-private/%s', $this->fixtureDir, $f); | ||
$classes = PhpReader::parseFile($directory, $filename, $options); | ||
$entries[] = array_map(fn($c) => new Entry(dirname($f), $c->getInfo(), $options), $classes); | ||
} | ||
$rel = new Relation(array_merge(...$entries), $options); | ||
|
||
$expected = <<<EOS | ||
@startuml class-diagram | ||
package product as product { | ||
class "Product" as product_Product { | ||
+name : string | ||
+publicFunction(param1) | ||
} | ||
} | ||
@enduml | ||
EOS; | ||
$this->assertSame($expected, implode(PHP_EOL, $rel->dump()), 'output PlantUML script.'); | ||
} | ||
|
||
public function testHidePrivateProperties(): void | ||
{ | ||
$directory = sprintf('%s/hide-private', $this->fixtureDir); | ||
$options = new Options([ | ||
'hide-private-properties' => true, | ||
]); | ||
$files = [ | ||
'product/Product.php', | ||
]; | ||
$entries = []; | ||
foreach ($files as $f) { | ||
$filename = sprintf('%s/hide-private/%s', $this->fixtureDir, $f); | ||
$classes = PhpReader::parseFile($directory, $filename, $options); | ||
$entries[] = array_map(fn($c) => new Entry(dirname($f), $c->getInfo(), $options), $classes); | ||
} | ||
$rel = new Relation(array_merge(...$entries), $options); | ||
|
||
$expected = <<<EOS | ||
@startuml class-diagram | ||
package product as product { | ||
class "Product" as product_Product { | ||
+name : string | ||
+publicFunction(param1) | ||
-privateFunction(param1) | ||
} | ||
} | ||
@enduml | ||
EOS; | ||
$this->assertSame($expected, implode(PHP_EOL, $rel->dump()), 'output PlantUML script.'); | ||
} | ||
|
||
public function testHidePrivateMethods(): void | ||
{ | ||
$directory = sprintf('%s/hide-private', $this->fixtureDir); | ||
$options = new Options([ | ||
'hide-private-methods' => true, | ||
]); | ||
$files = [ | ||
'product/Product.php', | ||
]; | ||
$entries = []; | ||
foreach ($files as $f) { | ||
$filename = sprintf('%s/hide-private/%s', $this->fixtureDir, $f); | ||
$classes = PhpReader::parseFile($directory, $filename, $options); | ||
$entries[] = array_map(fn($c) => new Entry(dirname($f), $c->getInfo(), $options), $classes); | ||
} | ||
$rel = new Relation(array_merge(...$entries), $options); | ||
|
||
$expected = <<<EOS | ||
@startuml class-diagram | ||
package product as product { | ||
class "Product" as product_Product { | ||
+name : string | ||
-memo : string | ||
+publicFunction(param1) | ||
} | ||
} | ||
@enduml | ||
EOS; | ||
$this->assertSame($expected, implode(PHP_EOL, $rel->dump()), 'output PlantUML script.'); | ||
} | ||
} |
Oops, something went wrong.