Skip to content

Commit

Permalink
l11
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Jul 31, 2024
1 parent 7196bd6 commit 209d7fc
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]

name: PHP ${{ matrix.php }}
env:
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
}
},
"require": {
"doctrine/dbal": "^3.5",
"illuminate/collections": "^8.0|^9.0|^10.0",
"illuminate/database": "^8.0|^9.0|^10.0",
"illuminate/collections": "^8.0|^9.0|^10.0|^11.0",
"illuminate/database": "^8.0|^9.0|^10.0|^11.0",
"nikic/php-parser": "^4.15"
},
"require-dev": {
"doctrine/dbal": "^3.5|^4.0",
"guzzlehttp/guzzle": "^7.5",
"mockery/mockery": "^1.5",
"orchestra/testbench": "^6.25|^7.13|^8.0",
"phpunit/phpunit": "^9.5",
"spatie/laravel-permission": "^5.7",
"spatie/phpunit-snapshot-assertions": "^4.2"
"orchestra/testbench": "^6.25|^7.13|^8.0|^9.0",
"phpunit/phpunit": "^9.5|^10.0|^11.0",
"spatie/laravel-permission": "^5.7|^6.0",
"spatie/phpunit-snapshot-assertions": "^4.2|^5.1.6"
},
"scripts": {
"post-autoload-dump": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (Schema::hasTable('users')) {
return;
}

Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (Schema::hasTable('password_reset_tokens')) {
return;
}

Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('password_reset_tokens');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (Schema::hasTable('failed_jobs')) {
return;
}

Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('failed_jobs');
}
};
36 changes: 11 additions & 25 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false" beStrictAboutCoverageMetadata="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
20 changes: 20 additions & 0 deletions src/Adapter/Contracts/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Recca0120\LaravelErd\Adapter\Contracts;

interface Column
{
public function getName(): string;

public function getNotnull(): bool;

public function getPrecision(): int;

public function getColumnType(): string;

public function getDefault();

public function getComment(): ?string;

public function getAutoincrement(): bool;
}
8 changes: 8 additions & 0 deletions src/Adapter/Contracts/SchemaManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Recca0120\LaravelErd\Adapter\Contracts;

interface SchemaManager
{
public function introspectTable(string $name): Table;
}
20 changes: 20 additions & 0 deletions src/Adapter/Contracts/Table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Recca0120\LaravelErd\Adapter\Contracts;

use Illuminate\Support\Collection;

interface Table
{
public function getName(): string;

/**
* @return Collection<int, Column>
*/
public function getColumns(): Collection;

/**
* @return Collection<int, string>
*/
public function getPrimaryKey(): Collection;
}
23 changes: 12 additions & 11 deletions src/Adapter/Column.php → src/Adapter/DBAL/Column.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace Recca0120\LaravelErd\Adapter;
namespace Recca0120\LaravelErd\Adapter\DBAL;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\Column as DBALColumn;
use Doctrine\DBAL\Types\Type;
use Recca0120\LaravelErd\Adapter\Contracts\Column as ColumnContract;

class Column
class Column implements ColumnContract
{
private DBALColumn $column;

Expand All @@ -30,15 +31,6 @@ public function getPrecision(): int
return $this->column->getPrecision();
}

public function getColumnType(): string
{
try {
return Type::getTypeRegistry()->lookupName($this->column->getType());
} catch (Exception $e) {
return 'unknown';
}
}

public function getDefault()
{
return $this->column->getDefault();
Expand All @@ -53,4 +45,13 @@ public function getAutoincrement(): bool
{
return $this->column->getAutoincrement();
}

public function getColumnType(): string
{
try {
return Type::getTypeRegistry()->lookupName($this->column->getType());
} catch (Exception $e) {
return 'unknown';
}
}
}
23 changes: 23 additions & 0 deletions src/Adapter/DBAL/SchemaManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Recca0120\LaravelErd\Adapter\DBAL;

use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Illuminate\Database\Connection;
use Recca0120\LaravelErd\Adapter\Contracts\SchemaManager as SchemaManagerContract;
use Recca0120\LaravelErd\Adapter\Contracts\Table as TableContract;

class SchemaManager implements SchemaManagerContract
{
private AbstractSchemaManager $schemaManager;

public function __construct(Connection $connection)
{
$this->schemaManager = $connection->getDoctrineSchemaManager();
}

public function introspectTable(string $name): TableContract
{
return new Table($this->schemaManager->introspectTable($name));
}
}
8 changes: 3 additions & 5 deletions src/Adapter/Table.php → src/Adapter/DBAL/Table.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace Recca0120\LaravelErd\Adapter;
namespace Recca0120\LaravelErd\Adapter\DBAL;

use Doctrine\DBAL\Schema\Column as DBALColumn;
use Doctrine\DBAL\Schema\Table as DBALTable;
use Illuminate\Support\Collection;
use Recca0120\LaravelErd\Adapter\Contracts\Table as TableContract;

class Table
class Table implements TableContract
{
private DBALTable $table;

Expand All @@ -30,9 +31,6 @@ public function getColumns(): Collection
});
}

/**
* @return Collection<int, string>
*/
public function getPrimaryKey(): Collection
{
$primaryKey = $this->table->getPrimaryKey();
Expand Down
54 changes: 54 additions & 0 deletions src/Adapter/Laravel/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Recca0120\LaravelErd\Adapter\Laravel;

use Recca0120\LaravelErd\Adapter\Contracts\Column as ColumnContract;

class Column implements ColumnContract
{
private array $column;

public function __construct(array $column)
{
$this->column = $column;
}

public function getName(): string
{
return $this->column['name'];
}

public function getNotnull(): bool
{
return ! $this->column['nullable'];
}

public function getPrecision(): int
{
return $this->column['precision'] ?? 10;
}

public function getColumnType(): string
{
$type = $this->column['type'];

return $type === 'varchar' ? 'string' : $type;
}

public function getDefault()
{
$default = $this->column['default'];

return $default ? trim($default, "'") : $default;
}

public function getComment(): ?string
{
return $this->column['comment'] ?? null;
}

public function getAutoincrement(): bool
{
return $this->column['auto_increment'];
}
}
Loading

0 comments on commit 209d7fc

Please sign in to comment.