|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | + |
| 7 | +use Smeghead\PhpClassDiagram\Config\Options; |
| 8 | +use Smeghead\PhpClassDiagram\DiagramElement\Entry; |
| 9 | +use Smeghead\PhpClassDiagram\DiagramElement\Relation; |
| 10 | +use Smeghead\PhpClassDiagram\Php\PhpReader; |
| 11 | + |
| 12 | +final class ClassDiagramClassNameSummaryTest extends TestCase |
| 13 | +{ |
| 14 | + private $fixtureDir; |
| 15 | + public function setUp(): void |
| 16 | + { |
| 17 | + $this->fixtureDir = sprintf('%s/fixtures', __DIR__); |
| 18 | + } |
| 19 | + |
| 20 | + public function testClassnameWithSummary(): void |
| 21 | + { |
| 22 | + $options = new Options([ |
| 23 | + 'enable-class-name-summary' => true |
| 24 | + ]); |
| 25 | + $directory = sprintf('%s/classname-summary', $this->fixtureDir); |
| 26 | + $filename = sprintf('%s/classname-summary/product/Product.php', $this->fixtureDir); |
| 27 | + $entries[] = new Entry('product', PhpReader::parseFile($directory, $filename, $options)[0]->getInfo(), $options); |
| 28 | + $filename = sprintf('%s/classname-summary/product/Price.php', $this->fixtureDir); |
| 29 | + $entries[] = new Entry('product', PhpReader::parseFile($directory, $filename, $options)[0]->getInfo(), $options); |
| 30 | + $filename = sprintf('%s/classname-summary/product/Name.php', $this->fixtureDir); |
| 31 | + $entries[] = new Entry('product', PhpReader::parseFile($directory, $filename, $options)[0]->getInfo(), $options); |
| 32 | + |
| 33 | + $rel = new Relation($entries, $options); |
| 34 | + $expected =<<<EOS |
| 35 | +@startuml class-diagram |
| 36 | + package product as product { |
| 37 | + class "Product\\n<b>製品</b>" as product_Product { |
| 38 | + -name : Name |
| 39 | + -price : Price |
| 40 | + +method1(param1) |
| 41 | + } |
| 42 | + class "Price\\n<b>価格</b>" as product_Price { |
| 43 | + -price : int |
| 44 | + } |
| 45 | + class "Name\\n<b>製品名</b>" as product_Name { |
| 46 | + -name : string |
| 47 | + } |
| 48 | + } |
| 49 | + product_Product ..> product_Name |
| 50 | + product_Product ..> product_Price |
| 51 | + product_Product ..> product_Product |
| 52 | +@enduml |
| 53 | +EOS; |
| 54 | + $this->assertSame($expected, implode(PHP_EOL, $rel->dump()), 'output PlantUML script.'); |
| 55 | + } |
| 56 | + public function testClassnameWithoutSummary(): void |
| 57 | + { |
| 58 | + $options = new Options([ |
| 59 | + 'disable-class-name-summary' => true |
| 60 | + ]); |
| 61 | + $directory = sprintf('%s/classname-summary', $this->fixtureDir); |
| 62 | + $filename = sprintf('%s/classname-summary/product/Product.php', $this->fixtureDir); |
| 63 | + $entries[] = new Entry('product', PhpReader::parseFile($directory, $filename, $options)[0]->getInfo(), $options); |
| 64 | + $filename = sprintf('%s/classname-summary/product/Price.php', $this->fixtureDir); |
| 65 | + $entries[] = new Entry('product', PhpReader::parseFile($directory, $filename, $options)[0]->getInfo(), $options); |
| 66 | + $filename = sprintf('%s/classname-summary/product/Name.php', $this->fixtureDir); |
| 67 | + $entries[] = new Entry('product', PhpReader::parseFile($directory, $filename, $options)[0]->getInfo(), $options); |
| 68 | + |
| 69 | + $rel = new Relation($entries, $options); |
| 70 | + $expected =<<<EOS |
| 71 | +@startuml class-diagram |
| 72 | + package product as product { |
| 73 | + class "Product" as product_Product { |
| 74 | + -name : Name |
| 75 | + -price : Price |
| 76 | + +method1(param1) |
| 77 | + } |
| 78 | + class "Price" as product_Price { |
| 79 | + -price : int |
| 80 | + } |
| 81 | + class "Name" as product_Name { |
| 82 | + -name : string |
| 83 | + } |
| 84 | + } |
| 85 | + product_Product ..> product_Name |
| 86 | + product_Product ..> product_Price |
| 87 | + product_Product ..> product_Product |
| 88 | +@enduml |
| 89 | +EOS; |
| 90 | + $this->assertSame($expected, implode(PHP_EOL, $rel->dump()), 'output PlantUML script.'); |
| 91 | + } |
| 92 | + |
| 93 | +} |
0 commit comments