Skip to content

Commit

Permalink
Merge pull request #962 from mikebronner/patch-2
Browse files Browse the repository at this point in the history
Update for Laravel 8 compatibility.
  • Loading branch information
ArlonAntonius authored Nov 7, 2020
2 parents ebcd05d + 087ba16 commit d87338a
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 64 deletions.
26 changes: 13 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ references:
- MYSQL_PASSWORD: testing
- MYSQL_ALLOW_EMPTY_PASSWORD: yes
- MYSQL_ROOT_HOST: "%"

mysql: &mysql
image: mysql:latest
entrypoint: ['/entrypoint.sh', '--default-authentication-plugin=mysql_native_password']
Expand Down Expand Up @@ -75,9 +75,9 @@ references:
- APP_KEY: deela5kinohw0haekoothahSh8eexach

jobs:
"php-7.2-apache":
"php-7.3-apache":
docker:
- image: php:7.2-apache
- image: php:7.3-apache
environment: *environment
- *mysql
- *mariadb
Expand All @@ -86,9 +86,9 @@ jobs:
- *mariadb2
- *pgsql2
<<: *steps
"php-7.3-apache":
"php-7.3-nginx":
docker:
- image: php:7.3-apache
- image: php:7.3-fpm
environment: *environment
- *mysql
- *mariadb
Expand All @@ -97,9 +97,9 @@ jobs:
- *mariadb2
- *pgsql2
<<: *steps
"php-7.2-nginx":
"php-7.4-apache":
docker:
- image: php:7.2-fpm
- image: php:7.3-apache
environment: *environment
- *mysql
- *mariadb
Expand All @@ -108,7 +108,7 @@ jobs:
- *mariadb2
- *pgsql2
<<: *steps
"php-7.3-nginx":
"php-7.4-nginx":
docker:
- image: php:7.3-fpm
environment: *environment
Expand Down Expand Up @@ -145,22 +145,22 @@ jobs:
- run: mysql --host=mariadb2 -e "grant all privileges on *.* to 'testing'@'%' with grant option;"
- run: DB_CONNECTION=mysql DB_HOST=mariadb TENANCY_SYSTEM_CONNECTION_NAME=mysql ./vendor/bin/phpunit -c ci.phpunit.xml --coverage-clover=coverage.xml
- run: bash <(curl -s https://codecov.io/bash)


workflows:
version: 2
test:
jobs:
- "php-7.2-apache"
- "php-7.3-apache"
- "php-7.2-nginx"
- "php-7.3-nginx"
- "php-7.4-apache"
- "php-7.4-nginx"
- coverage:
filters:
branches:
only: /^([0-9]+)\.x$/
requires:
- "php-7.2-apache"
- "php-7.3-apache"
- "php-7.2-nginx"
- "php-7.3-nginx"
- "php-7.4-apache"
- "php-7.4-nginx"
7 changes: 5 additions & 2 deletions ci.phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
</whitelist>
</filter>
<php>
<env name="IN_CI" value="1"/>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="Phei9thoong3ai8aqu4ieHie6kee1zee"/>
<env name="DB_DATABASE" value="testing"/>
<env name="DB_PASSWORD" value="root"/>
<env name="DB_USERNAME" value="root"/>
<env name="IN_CI" value="1"/>
<env name="LIMIT_UUID_LENGTH_32" value="1"/>
<env name="MAIL_MAILER" value="log"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="TENANCY_DATABASE_AUTO_DELETE" value="1"/>
<env name="TENANCY_DATABASE_AUTO_DELETE_USER" value="1"/>
<env name="TENANCY_DATABASE_AUTO_DELETE" value="1"/>
<env name="TENANCY_DEFAULT_HOSTNAME" value="local.testing"/>
<env name="TENANCY_SYSTEM_CONNECTION_NAME" value="mysql"/>
</php>
</phpunit>
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
"docs": "https://tenancy.dev"
},
"require": {
"php": "^7.2",
"php": "^7.3",
"phpseclib/phpseclib": "~2.0",
"doctrine/dbal": "~2.5",
"ramsey/uuid": "^4.0",
"laravel/framework": "^7.0"
"laravel/framework": "^8.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"symfony/dom-crawler": "~3.1",
"laravel/laravel": "^7.0",
"fzaninotto/faker": "^1.8",
"laravel/laravel": "^8.0",
"mockery/mockery": "^1.0",
"fzaninotto/faker": "^1.8"
"phpunit/phpunit": "^9.0",
"symfony/dom-crawler": "~3.1"
},
"autoload": {
"psr-4": {
Expand All @@ -45,11 +45,11 @@
"psr-4": {
"Hyn\\Tenancy\\Tests\\": "tests/unit-tests/",
"Hyn\\Tenancy\\Tests\\Extend\\": "tests/extend/",
"Hyn\\Tenancy\\Tests\\Seeds\\": "tests/seeds/",
"Hyn\\Tenancy\\Tests\\Traits\\": "tests/traits/"
},
"classmap": [
"tests/Test.php",
"tests/seeds/SampleSeeder.php"
"tests/Test.php"
]
},
"extra": {
Expand Down
22 changes: 7 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Installation Test Suite">
<file>./tests/unit-tests/InstallationTest.php</file>
Expand All @@ -18,17 +14,13 @@
<exclude>./tests/unit-tests/InstallationTest.php</exclude>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="Phei9thoong3ai8aqu4ieHie6kee1zee"/>
<env name="DB_DATABASE" value="tenancy"/>
<env name="DB_PASSWORD" value=""/>
<env name="DB_USERNAME" value="root"/>
<env name="MAIL_MAILER" value="log"/>
<env name="LIMIT_UUID_LENGTH_32" value="1"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="TENANCY_DATABASE_AUTO_DELETE" value="1"/>
Expand Down
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Join our Discord server](https://discordapp.com/api/guilds/146267795754057729/embed.png)](https://tenancy.dev/chat)
[![Mentioned in Awesome Laravel](https://awesome.re/mentioned-badge.svg)](https://github.com/chiraggude/awesome-laravel)

The unobtrusive Laravel package that makes your app multi tenant. Serving
The unobtrusive Laravel package that makes your app multi tenant. Serving
multiple websites, each with one or more hostnames from the same codebase. But
with clear separation of assets, database and the ability to override logic per
tenant.
Expand All @@ -20,7 +20,7 @@ for different clients or start-ups building the next software as a
Offers:

- Integration with the awesome Laravel framework.
- Event driven, extensible architecture.
- Event driven, extensible architecture.
- Close - optional - integration into the web server.
- The ability to add tenant specific configs, code, routes etc.

Expand All @@ -35,10 +35,10 @@ Database separation methods:

## Requirements, recommended environment

- Latest stable and LTS Laravel versions.
- PHP 7+.
- Laravel 8.0+.
- PHP 7.3+
- Apache or Nginx.
- MySQL, MariaDB or PostgreSQL.
- MySQL, MariaDB, or PostgreSQL.

Please read the full [requirements in the documentation](https://tenancy.dev/docs/hyn/5.4/requirements).

Expand All @@ -51,11 +51,11 @@ composer require hyn/multi-tenant
### Automatic service registration

Using [auto discovery](https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518), the
tenancy package will be auto detected by Laravel automatically.
tenancy package will be auto detected by Laravel automatically.

#### Manual service registration

In case you want to disable webserver integration or prefer manual integration,
In case you want to disable webserver integration or prefer manual integration,
set the `dont-discover` in your application composer.json, like so:

```json
Expand Down
25 changes: 20 additions & 5 deletions src/Providers/Tenants/ConnectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,34 @@ public function register()
protected function registerMigrationCommands()
{
$this->app->singleton(Console\Migrations\FreshCommand::class, function (Application $app) {
return new Console\Migrations\FreshCommand($app->make('migrator'));
return new Console\Migrations\FreshCommand(
$app->make('migrator'),
$app->make("events")
);
});
$this->app->singleton(Console\Migrations\MigrateCommand::class, function (Application $app) {
return new Console\Migrations\MigrateCommand($app->make('migrator'));
return new Console\Migrations\MigrateCommand(
$app->make('migrator'),
$app->make("events")
);
});
$this->app->singleton(Console\Migrations\RollbackCommand::class, function (Application $app) {
return new Console\Migrations\RollbackCommand($app->make('migrator'));
return new Console\Migrations\RollbackCommand(
$app->make('migrator'),
$app->make("events")
);
});
$this->app->singleton(Console\Migrations\ResetCommand::class, function (Application $app) {
return new Console\Migrations\ResetCommand($app->make('migrator'));
return new Console\Migrations\ResetCommand(
$app->make('migrator'),
$app->make("events")
);
});
$this->app->singleton(Console\Migrations\RefreshCommand::class, function (Application $app) {
return new Console\Migrations\RefreshCommand($app->make('migrator'));
return new Console\Migrations\RefreshCommand(
$app->make('migrator'),
$app->make("events")
);
});
$this->app->singleton(Console\Seeds\SeedCommand::class, function (Application $app) {
return new Console\Seeds\SeedCommand($app['db']);
Expand Down
9 changes: 5 additions & 4 deletions src/Traits/MutatesMigrationCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

namespace Hyn\Tenancy\Traits;

use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;
use InvalidArgumentException;
use Hyn\Tenancy\Database\Connection;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Migrations\Migrator;
use InvalidArgumentException;
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;

trait MutatesMigrationCommands
{
Expand All @@ -31,9 +32,9 @@ trait MutatesMigrationCommands
*/
private $connection;

public function __construct(Migrator $migrator)
public function __construct(Migrator $migrator, Dispatcher $dispatcher)
{
parent::__construct($migrator);
parent::__construct($migrator, $dispatcher);

$this->setName('tenancy:' . $this->getName());
$this->specifyParameters();
Expand Down
14 changes: 14 additions & 0 deletions tests/seeds/SampleSeeder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<?php

/*
* This file is part of the hyn/multi-tenant package.
*
* (c) Daniël Klabbers <daniel@klabbers.email>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @see https://tenancy.dev
* @see https://github.com/hyn/multi-tenant
*/

namespace Hyn\Tenancy\Tests\Seeds;

/*
* This file is part of the hyn/multi-tenant package.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/traits/InteractsWithMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Hyn\Tenancy\Providers\TenancyProvider;
use Hyn\Tenancy\Providers\Tenants\ConfigurationProvider;
use Illuminate\Database\Eloquent\Collection;
use SampleSeeder;
use Hyn\Tenancy\Tests\Seeds\SampleSeeder;
use Mockery;
use Hyn\Tenancy\Database\Connection;
use Illuminate\Contracts\Console\Kernel;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/Commands/FreshCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Hyn\Tenancy\Database\Console\Migrations\FreshCommand;
use Hyn\Tenancy\Models\Website;
use Illuminate\Contracts\Foundation\Application;
use SampleSeeder;
use Hyn\Tenancy\Tests\Seeds\SampleSeeder;

class FreshCommandTest extends DatabaseCommandTest
{
Expand Down
5 changes: 3 additions & 2 deletions tests/unit-tests/Commands/SeedCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Hyn\Tenancy\Database\Console\Seeds\SeedCommand;
use Hyn\Tenancy\Models\Website;
use Illuminate\Contracts\Console\Kernel;
use SampleSeeder;
use Hyn\Tenancy\Tests\Seeds\SampleSeeder;

class SeedCommandTest extends DatabaseCommandTest
{
Expand Down Expand Up @@ -108,7 +108,8 @@ public function runs_seed_on_tenants()
$this->assertTrue($this->connection->get()->getDoctrineSchemaManager()->tablesExist('samples'));

$this->assertEquals(
2, $this->connection->get()->table('samples')->count(),
2,
$this->connection->get()->table('samples')->count(),
"Connection for {$website->uuid} has incorrect sample data"
);
});
Expand Down
4 changes: 2 additions & 2 deletions tests/unit-tests/Queue/TenantAwareJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Hyn\Tenancy\Tests\Queue;

use App\User;
use App\Models\User;
use Illuminate\Contracts\Foundation\Application;
use Hyn\Tenancy\Tests\Test;
use Illuminate\Bus\Queueable;
Expand Down Expand Up @@ -93,7 +93,7 @@ public function current_website_id_is_included_in_notification_job_payload()

Event::fake();

$user = factory(User::class)->create();
$user = User::factory()->create();
$user->notify(new TestNotification());

Event::assertDispatched(JobProcessed::class, function ($event) {
Expand Down
7 changes: 4 additions & 3 deletions tests/unit-tests/Repositories/HostnameRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
* @see https://github.com/hyn/multi-tenant
*/

namespace Hyn\Tenancy\Tests;
namespace Hyn\Tenancy\Tests\Repositories;

use Hyn\Tenancy\Exceptions\ModelValidationException;
use Illuminate\Contracts\Foundation\Application;
use Hyn\Tenancy\Tests\Test;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Foundation\Application;
use Hyn\Tenancy\Exceptions\ModelValidationException;

class HostnameRepositoryTest extends Test
{
Expand Down
3 changes: 2 additions & 1 deletion tests/unit-tests/Repositories/WebsiteRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
* @see https://github.com/hyn/multi-tenant
*/

namespace Hyn\Tenancy\Tests;
namespace Hyn\Tenancy\Tests\Repositories;

use Hyn\Tenancy\Tests\Test;
use Illuminate\Contracts\Foundation\Application;

class WebsiteRepositoryTest extends Test
Expand Down

0 comments on commit d87338a

Please sign in to comment.