Skip to content

Commit 011694b

Browse files
diogogomeswwwjafar690
authored andcommitted
Fix model names with underscores (#41)
* change Avatar to User_Avatar * fix tests * remove - from node name * docblocks * fix ref * snapshots * make unit test to ensure hiphens are handle * rename User_Avatar to Avatar, it's nicer * fix docblocks
1 parent 70c8cf8 commit 011694b

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

src/GenerateDiagramCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace BeyondCode\ErdGenerator;
44

5-
use ReflectionClass;
5+
use BeyondCode\ErdGenerator\Model as GraphModel;
66
use Illuminate\Console\Command;
7-
use phpDocumentor\GraphViz\Graph;
87
use Illuminate\Support\Collection;
9-
use BeyondCode\ErdGenerator\Model as GraphModel;
8+
use phpDocumentor\GraphViz\Graph;
9+
use ReflectionClass;
1010

1111
class GenerateDiagramCommand extends Command
1212
{
@@ -49,6 +49,9 @@ public function __construct(ModelFinder $modelFinder, RelationFinder $relationFi
4949
$this->graphBuilder = $graphBuilder;
5050
}
5151

52+
/**
53+
* @throws \phpDocumentor\GraphViz\Exception
54+
*/
5255
public function handle()
5356
{
5457
$models = $this->getModelsThatShouldBeInspected();

src/Model.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getModel()
3030
*/
3131
public function getNodeName()
3232
{
33-
return str_slug($this->model);
33+
return str_replace('-', '', str_slug($this->model));
3434
}
3535

3636
/**
@@ -42,7 +42,7 @@ public function getLabel()
4242
}
4343

4444
/**
45-
* @return ModelRelation[]
45+
* @return Collection
4646
*/
4747
public function getRelations()
4848
{

tests/FindModelsFromConfigTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ public function it_can_find_class_names_from_directory()
1919
$classNames = $finder->getModelsInDirectory(__DIR__ . "/Models");
2020

2121
$this->assertCount(4, $classNames);
22-
$this->assertSame(Avatar::class, $classNames->first());
22+
23+
$this->assertSame(
24+
[Avatar::class, Comment::class, Post::class, User::class],
25+
$classNames->values()->all()
26+
);
2327
}
2428

2529
/** @test */
@@ -42,5 +46,4 @@ public function it_will_ignore_a_model_if_it_is_excluded_on_config()
4246
$classNames->values()->all()
4347
);
4448
}
45-
4649
}

tests/ModelTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace BeyondCode\ErdGenerator\Tests;
4+
5+
use BeyondCode\ErdGenerator\Model;
6+
7+
class ModelTest extends TestCase
8+
{
9+
/** @test */
10+
public function it_generates_a_node_name_without_hyphens()
11+
{
12+
$model = new Model('Test_Class', 'Test_Class', collect());
13+
14+
$this->assertEquals('testclass', $model->getNodeName());
15+
}
16+
}

0 commit comments

Comments
 (0)