Skip to content

Commit

Permalink
Merge pull request #14 from telkins/overall-improvements
Browse files Browse the repository at this point in the history
Overall improvements
  • Loading branch information
telkins authored Jan 2, 2021
2 parents 5eec52e + 4fcee4e commit b870ef3
Show file tree
Hide file tree
Showing 23 changed files with 400 additions and 360 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: run tests

on: [push, pull_request]

jobs:
test:
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: laravel-dag-manager-db
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.0, 7.4]
laravel: [8.*, 7.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 7.*
testbench: 5.*
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

# - name: Create database
# run: |
# sudo /etc/init.d/mysql start
# mysql -u root -proot -e 'CREATE DATABASE IF NOT EXISTS laravel_mt_landlord;'
# mysql -u root -proot -e 'CREATE DATABASE IF NOT EXISTS laravel_mt_tenant_1;'
# mysql -u root -proot -e 'CREATE DATABASE IF NOT EXISTS laravel_mt_tenant_2;'

# - name: Start Redis
# uses: supercharge/redis-github-action@1.1.0
# with:
# redis-version: 5

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
env:
APP_ENV: testing
DB_CONNECTION: mysql
DB_NAME: laravel-dag-manager-db
DB_PASSWORD:
DB_USER: root
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ Homestead.json

composer.lock
.phpunit.result.cache

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- ...

## [v1.0.0] - 2020-12-24
### Added
- Remove support of Laravel lower than 8.0
- Remove support of PHP lower than 7.4
- Add property/argument/return types
- Make code more strict
- Remove redundant doc-blocks
- Make table name configurable
- Migrate phpunit configuration
- Make service provider deferrable

## [v0.10.0] - 2020-09-09
### Added
- Laravel 8.0 support
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ php artisan vendor:publish --provider="Telkins\Dag\Providers\DagServiceProvider"
This is the contents of the published config file:
```php
return [

/**
*-------------------------------------------------------------------------
* Max Hops
Expand All @@ -77,22 +76,29 @@ return [
* and memory. Whether or not it's negligible, noticeable, or impactful
* depends on a variety of factors.
*/

'max_hops' => 5,

/**
*-------------------------------------------------------------------------
* Default Database Connection Name
*-------------------------------------------------------------------------
*
* This is the name of the database connection where the dag_edges table
* This is the name of the database connection where the dag table
* can be found.
*
* Set to `null` to use the default connection.
*/

'default_database_connection_name' => null,

/**
*-------------------------------------------------------------------------
* Table Name
*-------------------------------------------------------------------------
*
* This is the name of the table where the dag structure
* will be stored.
*/
'table_name' => 'dag_edges',
];
```

Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
}
],
"require": {
"php": "^7.2",
"illuminate/database": "^6.0|^7.0|^8.0",
"illuminate/support": "^6.0|^7.0|^8.0"
"php": "^7.4 || ^8.0",
"illuminate/contracts": "^7.0 || ^8.0",
"illuminate/database": "^7.0 || ^8.0",
"illuminate/support": "^7.0 || ^8.0"
},
"require-dev": {
"orchestra/testbench": "^4.0|^5.0|^6.0",
"phpunit/phpunit": "^9.0|^9.3"
"orchestra/testbench": "^5.0 || ^6.0",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 12 additions & 4 deletions config/laravel-dag-manager.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

return [
declare(strict_types=1);

return [
/**
*-------------------------------------------------------------------------
* Max Hops
Expand All @@ -16,20 +17,27 @@
* and memory. Whether or not it's negligible, noticeable, or impactful
* depends on a variety of factors.
*/

'max_hops' => 5,

/**
*-------------------------------------------------------------------------
* Default Database Connection Name
*-------------------------------------------------------------------------
*
* This is the name of the database connection where the dag_edges table
* This is the name of the database connection where the dag table
* can be found.
*
* Set to `null` to use the default connection.
*/

'default_database_connection_name' => null,

/**
*-------------------------------------------------------------------------
* Table Name
*-------------------------------------------------------------------------
*
* This is the name of the table where the dag structure
* will be stored.
*/
'table_name' => 'dag_edges',
];
25 changes: 11 additions & 14 deletions database/migrations/create_dag_edges_table.php.stub
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?php

declare(strict_types=1);

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

class CreateDagEdgesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('dag_edges', function (Blueprint $table) {
Schema::create(self::getTableName(), function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('entry_edge_id')->nullable()->comment('The ID of the incoming edge to the start vertex that is the creation reason for this implied edge; direct edges contain the same value as the Id column');
$table->unsignedBigInteger('direct_edge_id')->nullable()->comment('The ID of the direct edge that caused the creation of this implied edge; direct edges contain the same value as the Id column');
Expand All @@ -26,13 +23,13 @@ class CreateDagEdgesTable extends Migration
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists(self::getTableName());
}

private static function getTableName(): string
{
Schema::dropIfExists('dag_edges');
return config('laravel-dag-manager.table_name');
}
}
31 changes: 11 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Laravel DAG Manager Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Laravel DAG Manager Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
7 changes: 7 additions & 0 deletions src/Concerns/UsesDagConfig.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Telkins\Dag\Concerns;

trait UsesDagConfig
Expand All @@ -8,4 +10,9 @@ public function defaultDatabaseConnectionName(): ?string
{
return config('laravel-dag-manager.default_database_connection_name') ?? config('database.default');
}

public function defaultTableName(): ?string
{
return config('laravel-dag-manager.table_name');
}
}
17 changes: 7 additions & 10 deletions src/Exceptions/CircularReferenceException.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<?php

declare(strict_types=1);

namespace Telkins\Dag\Exceptions;

use Exception;
use Throwable;

class CircularReferenceException extends Exception
{
/**
* Create a new exception instance.
*
* @param string|null $message
* @param mixed|null $code
* @param \Exception|null $previous
* @return void
*/
public function __construct($message = null, $code = null, Exception $previous = null)
public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message ?? 'This operation caused a circular reference.', $code, $previous);
$message = ! empty($message) ? $message : 'This operation caused a circular reference.';

parent::__construct($message, $code, $previous);
}
}
11 changes: 4 additions & 7 deletions src/Exceptions/TooManyHopsException.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?php

declare(strict_types=1);

namespace Telkins\Dag\Exceptions;

use Exception;

class TooManyHopsException extends Exception
{
/**
* Create a new exception instance.
*
* @param int $maximumAllowableHops
* @return static
*/
public static function make(int $maximumAllowableHops)
/** @todo Change return to static once on PHP 8. */
public static function make(int $maximumAllowableHops): self
{
return new static("This operation exceeded the maximum allowable hops ({$maximumAllowableHops}).");
}
Expand Down
17 changes: 12 additions & 5 deletions src/Models/DagEdge.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Telkins\Dag\Models;

use Illuminate\Database\Eloquent\Model;
Expand All @@ -20,16 +22,21 @@ class DagEdge extends Model
];

protected $casts = [
'entry_edge_id' => 'int',
'entry_edge_id' => 'int',
'direct_edge_id' => 'int',
'exit_edge_id' => 'int',
'start_vertex' => 'int',
'end_vertex' => 'int',
'hops' => 'int',
'exit_edge_id' => 'int',
'start_vertex' => 'int',
'end_vertex' => 'int',
'hops' => 'int',
];

public function getConnectionName()
{
return $this->defaultDatabaseConnectionName();
}

public function getTableName()
{
return $this->defaultTableName();
}
}
Loading

0 comments on commit b870ef3

Please sign in to comment.