Skip to content

Commit 9213254

Browse files
committed
Merge remote-tracking branch 'origin/dev'
# Conflicts: # tests/GenerationTest.php
2 parents 3be042d + 5123c58 commit 9213254

10 files changed

Lines changed: 74 additions & 28 deletions

.github/workflows/tests.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- dev
88
pull_request:
99
branches:
10+
- dev
1011
- master
1112

1213
jobs:
@@ -17,20 +18,24 @@ jobs:
1718
fail-fast: true
1819
matrix:
1920
php: ['8.4', '8.3', '8.2']
20-
laravel: ['10.*', '11.*', '12.*']
21+
laravel: ['10.*', '11.*', '12.*', '13.*']
2122
dependency-version: [prefer-stable]
2223
exclude:
2324
- php: 8.4
2425
laravel: 10.*
2526
- php: 8.4
2627
laravel: 11.*
28+
- laravel: 13.*
29+
php: '8.2'
2730
include:
2831
- laravel: 10.*
2932
testbench: 8.*
3033
- laravel: 11.*
3134
testbench: 9.*
3235
- laravel: 12.*
3336
testbench: 10.*
37+
- laravel: 13.*
38+
testbench: 11.*
3439

3540
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ubuntu-latest
3641

@@ -50,9 +55,11 @@ jobs:
5055

5156
- name: Install dependencies
5257
run: |
53-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
54-
if [[ "${{ matrix.laravel }}" == "10.*" ]]; then composer require "doctrine/dbal:^3.3" --no-interaction --no-update; fi
55-
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
58+
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
59+
composer require "orchestra/testbench:${{ matrix.testbench }}" --dev --no-interaction --no-update
60+
if [[ "${{ matrix.laravel }}" == "10.*" ]]; then composer require "doctrine/dbal:^3.3" --no-interaction --no-update; fi
61+
if [[ "${{ matrix.laravel }}" == "13.*" ]]; then composer config minimum-stability dev; fi
62+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
5663
5764
- name: Execute tests
58-
run: vendor/bin/phpunit
65+
run: vendor/bin/phpunit

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ vendor
55
coverage
66
.idea
77
tests/__snapshots__/
8-
.phpunit.result.cache
8+
.phpunit.cache

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
},
2424
"require-dev": {
2525
"larapack/dd": "^1.0",
26-
"orchestra/testbench": "^8.0|^9.0|^10.0",
27-
"phpunit/phpunit": "^9.5.10|^10.5|^11.0",
26+
"orchestra/testbench": "^8.0|^9.0|^10.0|^11.0",
27+
"phpunit/phpunit": "^9.5.10|^10.5|^11.0|^12.0",
2828
"spatie/phpunit-snapshot-assertions": "^4.2|^5.1"
2929
},
3030
"autoload": {

config/config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
// App\Post::class,
3636
],
3737

38+
/*
39+
* If you want to rename models in the generated diagram, you can specify aliases
40+
* for them here.
41+
*/
42+
'aliases' => [
43+
// User::class => 'CustomUser',
44+
],
45+
3846
/*
3947
* If true, all directories specified will be scanned recursively for models.
4048
* Set this to false if you prefer to explicitly define each directory that should

phpunit.xml.dist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
45
colors="true"
5-
processIsolation="false"
6-
stopOnFailure="false">
6+
cacheDirectory=".phpunit.cache">
77
<testsuites>
88
<testsuite name="BeyondCode Test Suite">
99
<directory>tests</directory>

src/GenerateDiagramCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,18 @@ public function __construct(ModelFinder $modelFinder, RelationFinder $relationFi
5555
public function handle()
5656
{
5757
$models = $this->getModelsThatShouldBeInspected();
58+
$aliases = array_filter(config('erd-generator.aliases', []), 'is_string');
5859

5960
$this->info("Found {$models->count()} models.");
6061
$this->info("Inspecting model relations.");
6162

6263
$bar = $this->output->createProgressBar($models->count());
6364

64-
$models->transform(function ($model) use ($bar) {
65+
$models->transform(function ($model) use ($bar, $aliases) {
6566
$bar->advance();
6667
return new GraphModel(
6768
$model,
68-
(new ReflectionClass($model))->getShortName(),
69+
$aliases[$model] ?? (new ReflectionClass($model))->getShortName(),
6970
$this->relationFinder->getModelRelations($model)
7071
);
7172
});

tests/FindModelsFromConfigTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
use BeyondCode\ErdGenerator\Tests\Models\Comment;
88
use BeyondCode\ErdGenerator\Tests\Models\Post;
99
use BeyondCode\ErdGenerator\Tests\Models\User;
10+
use PHPUnit\Framework\Attributes\Test;
1011

1112
class FindModelsFromConfigTest extends TestCase
1213
{
1314

14-
/** @test */
15+
#[Test]
1516
public function it_can_find_class_names_from_directory()
1617
{
1718
$finder = new ModelFinder(app()->make('files'));
@@ -26,7 +27,7 @@ public function it_can_find_class_names_from_directory()
2627
);
2728
}
2829

29-
/** @test */
30+
#[Test]
3031
public function it_will_ignore_a_model_if_it_is_excluded_on_config()
3132
{
3233
$this->app['config']->set('erd-generator.ignore', [
@@ -47,7 +48,7 @@ public function it_will_ignore_a_model_if_it_is_excluded_on_config()
4748
);
4849
}
4950

50-
/** @test */
51+
#[Test]
5152
public function it_will_only_return_models_in_whitelist_if_present()
5253
{
5354
$this->app['config']->set('erd-generator.whitelist', [

tests/GenerationTest.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
namespace BeyondCode\ErdGenerator\Tests;
44

5+
use BeyondCode\ErdGenerator\Tests\Models\Avatar;
6+
use BeyondCode\ErdGenerator\Tests\Models\User;
57
use Spatie\Snapshots\MatchesSnapshots;
68
use Illuminate\Support\Facades\Artisan;
9+
use PHPUnit\Framework\Attributes\Test;
710

811
class GenerationTest extends TestCase
912
{
1013
use MatchesSnapshots;
1114

12-
/** @test */
15+
#[Test]
1316
public function it_generated_graphviz_for_test_models()
1417
{
1518
$this->app['config']->set('erd-generator.use_db_schema', false);
@@ -22,7 +25,7 @@ public function it_generated_graphviz_for_test_models()
2225
$this->assertMatchesSnapshot(Artisan::output());
2326
}
2427

25-
/** @test */
28+
#[Test]
2629
public function it_generated_graphviz_for_test_models_with_db_columns_and_types()
2730
{
2831
$this->app['config']->set('erd-generator.directories', [__DIR__ . '/Models']);
@@ -34,7 +37,7 @@ public function it_generated_graphviz_for_test_models_with_db_columns_and_types(
3437
$this->assertMatchesSnapshot(Artisan::output());
3538
}
3639

37-
/** @test */
40+
#[Test]
3841
public function it_generated_graphviz_for_test_models_with_db_columns()
3942
{
4043
$this->app['config']->set('erd-generator.use_column_types', false);
@@ -47,7 +50,7 @@ public function it_generated_graphviz_for_test_models_with_db_columns()
4750
$this->assertMatchesSnapshot(Artisan::output());
4851
}
4952

50-
/** @test */
53+
#[Test]
5154
public function it_generated_graphviz_for_test_models_with_db_columns_with_some_excluded_on_config()
5255
{
5356
$this->app['config']->set('erd-generator.use_column_types', false);
@@ -64,7 +67,31 @@ public function it_generated_graphviz_for_test_models_with_db_columns_with_some_
6467
$this->assertMatchesSnapshot(Artisan::output());
6568
}
6669

67-
/** @test */
70+
#[Test]
71+
public function it_generated_graphviz_for_test_models_with_aliases()
72+
{
73+
$this->app['config']->set('erd-generator.directories', [__DIR__ . '/Models']);
74+
$this->app['config']->set('erd-generator.aliases', [
75+
Avatar::class => 123,
76+
User::class => 'CustomUser'
77+
]);
78+
79+
Artisan::call('generate:erd', [
80+
'--format' => 'text'
81+
]);
82+
83+
$output = Artisan::output();
84+
85+
$this->assertStringContainsString('>CustomUser<', $output);
86+
87+
// Avatar class must not be renamed, as the alias was not a string
88+
$this->assertStringContainsString('>Avatar<', $output);
89+
90+
// Comment class must not be renamed, as it was not included in the aliases array
91+
$this->assertStringContainsString('>Comment<', $output);
92+
}
93+
94+
#[Test]
6895
public function it_generated_graphviz_in_jpeg_format()
6996
{
7097
$this->app['config']->set('erd-generator.directories', [__DIR__ . '/Models']);
@@ -76,7 +103,7 @@ public function it_generated_graphviz_in_jpeg_format()
76103
$this->assertStringContainsString('Wrote diagram to graph.jpeg', Artisan::output());
77104
}
78105

79-
/** @test */
106+
#[Test]
80107
public function it_generates_text_output_file_with_text_output_option()
81108
{
82109
$this->app['config']->set('erd-generator.directories', [__DIR__ . '/Models']);
@@ -106,7 +133,7 @@ public function it_generates_text_output_file_with_text_output_option()
106133
}
107134
}
108135

109-
/** @test */
136+
#[Test]
110137
public function it_generates_structured_text_output_for_txt_extension()
111138
{
112139
$this->app['config']->set('erd-generator.directories', [__DIR__ . '/Models']);
@@ -137,7 +164,7 @@ public function it_generates_structured_text_output_for_txt_extension()
137164
}
138165
}
139166

140-
/** @test */
167+
#[Test]
141168
public function it_generates_structured_text_output_with_correct_content()
142169
{
143170
$this->app['config']->set('erd-generator.directories', [__DIR__ . '/Models']);

tests/GetModelRelationsTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
use BeyondCode\ErdGenerator\Tests\Models\Post;
1010
use BeyondCode\ErdGenerator\Tests\Models\User;
1111
use Illuminate\Support\Arr;
12+
use PHPUnit\Framework\Attributes\Test;
1213

1314

1415
class GetModelRelationsTest extends TestCase
1516
{
1617

17-
/** @test */
18+
#[Test]
1819
public function it_can_find_model_relations()
1920
{
2021
$finder = new RelationFinder();
@@ -51,7 +52,7 @@ public function it_can_find_model_relations()
5152
$this->assertSame(null, $avatar->getForeignKey());
5253
}
5354

54-
/** @test */
55+
#[Test]
5556
public function it_will_ignore_a_relation_if_it_is_excluded_on_config()
5657
{
5758
$this->app['config']->set('erd-generator.ignore', [

tests/ModelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace BeyondCode\ErdGenerator\Tests;
44

55
use BeyondCode\ErdGenerator\Model;
6+
use PHPUnit\Framework\Attributes\Test;
67

78
class ModelTest extends TestCase
89
{
9-
/** @test */
10+
#[Test]
1011
public function it_generates_a_node_name_without_hyphens()
1112
{
1213
$model = new Model('Test_Class', 'Test_Class', collect());

0 commit comments

Comments
 (0)