Skip to content

Commit d87338a

Browse files
Merge pull request #962 from mikebronner/patch-2
Update for Laravel 8 compatibility.
2 parents ebcd05d + 087ba16 commit d87338a

14 files changed

+92
-64
lines changed

.circleci/config.yml

+13-13
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ references:
3535
- MYSQL_PASSWORD: testing
3636
- MYSQL_ALLOW_EMPTY_PASSWORD: yes
3737
- MYSQL_ROOT_HOST: "%"
38-
38+
3939
mysql: &mysql
4040
image: mysql:latest
4141
entrypoint: ['/entrypoint.sh', '--default-authentication-plugin=mysql_native_password']
@@ -75,9 +75,9 @@ references:
7575
- APP_KEY: deela5kinohw0haekoothahSh8eexach
7676

7777
jobs:
78-
"php-7.2-apache":
78+
"php-7.3-apache":
7979
docker:
80-
- image: php:7.2-apache
80+
- image: php:7.3-apache
8181
environment: *environment
8282
- *mysql
8383
- *mariadb
@@ -86,9 +86,9 @@ jobs:
8686
- *mariadb2
8787
- *pgsql2
8888
<<: *steps
89-
"php-7.3-apache":
89+
"php-7.3-nginx":
9090
docker:
91-
- image: php:7.3-apache
91+
- image: php:7.3-fpm
9292
environment: *environment
9393
- *mysql
9494
- *mariadb
@@ -97,9 +97,9 @@ jobs:
9797
- *mariadb2
9898
- *pgsql2
9999
<<: *steps
100-
"php-7.2-nginx":
100+
"php-7.4-apache":
101101
docker:
102-
- image: php:7.2-fpm
102+
- image: php:7.3-apache
103103
environment: *environment
104104
- *mysql
105105
- *mariadb
@@ -108,7 +108,7 @@ jobs:
108108
- *mariadb2
109109
- *pgsql2
110110
<<: *steps
111-
"php-7.3-nginx":
111+
"php-7.4-nginx":
112112
docker:
113113
- image: php:7.3-fpm
114114
environment: *environment
@@ -145,22 +145,22 @@ jobs:
145145
- run: mysql --host=mariadb2 -e "grant all privileges on *.* to 'testing'@'%' with grant option;"
146146
- run: DB_CONNECTION=mysql DB_HOST=mariadb TENANCY_SYSTEM_CONNECTION_NAME=mysql ./vendor/bin/phpunit -c ci.phpunit.xml --coverage-clover=coverage.xml
147147
- run: bash <(curl -s https://codecov.io/bash)
148-
148+
149149

150150
workflows:
151151
version: 2
152152
test:
153153
jobs:
154-
- "php-7.2-apache"
155154
- "php-7.3-apache"
156-
- "php-7.2-nginx"
157155
- "php-7.3-nginx"
156+
- "php-7.4-apache"
157+
- "php-7.4-nginx"
158158
- coverage:
159159
filters:
160160
branches:
161161
only: /^([0-9]+)\.x$/
162162
requires:
163-
- "php-7.2-apache"
164163
- "php-7.3-apache"
165-
- "php-7.2-nginx"
166164
- "php-7.3-nginx"
165+
- "php-7.4-apache"
166+
- "php-7.4-nginx"

ci.phpunit.xml

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424
</whitelist>
2525
</filter>
2626
<php>
27-
<env name="IN_CI" value="1"/>
2827
<env name="APP_ENV" value="testing"/>
2928
<env name="APP_KEY" value="Phei9thoong3ai8aqu4ieHie6kee1zee"/>
3029
<env name="DB_DATABASE" value="testing"/>
3130
<env name="DB_PASSWORD" value="root"/>
3231
<env name="DB_USERNAME" value="root"/>
32+
<env name="IN_CI" value="1"/>
33+
<env name="LIMIT_UUID_LENGTH_32" value="1"/>
34+
<env name="MAIL_MAILER" value="log"/>
3335
<env name="QUEUE_DRIVER" value="sync"/>
34-
<env name="TENANCY_DATABASE_AUTO_DELETE" value="1"/>
3536
<env name="TENANCY_DATABASE_AUTO_DELETE_USER" value="1"/>
37+
<env name="TENANCY_DATABASE_AUTO_DELETE" value="1"/>
3638
<env name="TENANCY_DEFAULT_HOSTNAME" value="local.testing"/>
39+
<env name="TENANCY_SYSTEM_CONNECTION_NAME" value="mysql"/>
3740
</php>
3841
</phpunit>

composer.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
"docs": "https://tenancy.dev"
2424
},
2525
"require": {
26-
"php": "^7.2",
26+
"php": "^7.3",
2727
"phpseclib/phpseclib": "~2.0",
2828
"doctrine/dbal": "~2.5",
2929
"ramsey/uuid": "^4.0",
30-
"laravel/framework": "^7.0"
30+
"laravel/framework": "^8.0"
3131
},
3232
"require-dev": {
33-
"phpunit/phpunit": "^8.0",
34-
"symfony/dom-crawler": "~3.1",
35-
"laravel/laravel": "^7.0",
33+
"fzaninotto/faker": "^1.8",
34+
"laravel/laravel": "^8.0",
3635
"mockery/mockery": "^1.0",
37-
"fzaninotto/faker": "^1.8"
36+
"phpunit/phpunit": "^9.0",
37+
"symfony/dom-crawler": "~3.1"
3838
},
3939
"autoload": {
4040
"psr-4": {
@@ -45,11 +45,11 @@
4545
"psr-4": {
4646
"Hyn\\Tenancy\\Tests\\": "tests/unit-tests/",
4747
"Hyn\\Tenancy\\Tests\\Extend\\": "tests/extend/",
48+
"Hyn\\Tenancy\\Tests\\Seeds\\": "tests/seeds/",
4849
"Hyn\\Tenancy\\Tests\\Traits\\": "tests/traits/"
4950
},
5051
"classmap": [
51-
"tests/Test.php",
52-
"tests/seeds/SampleSeeder.php"
52+
"tests/Test.php"
5353
]
5454
},
5555
"extra": {

phpunit.xml

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
>
2+
<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">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">./src/</directory>
6+
</include>
7+
</coverage>
128
<testsuites>
139
<testsuite name="Installation Test Suite">
1410
<file>./tests/unit-tests/InstallationTest.php</file>
@@ -18,17 +14,13 @@
1814
<exclude>./tests/unit-tests/InstallationTest.php</exclude>
1915
</testsuite>
2016
</testsuites>
21-
<filter>
22-
<whitelist processUncoveredFilesFromWhitelist="true">
23-
<directory suffix=".php">./src/</directory>
24-
</whitelist>
25-
</filter>
2617
<php>
2718
<env name="APP_ENV" value="testing"/>
2819
<env name="APP_KEY" value="Phei9thoong3ai8aqu4ieHie6kee1zee"/>
2920
<env name="DB_DATABASE" value="tenancy"/>
3021
<env name="DB_PASSWORD" value=""/>
3122
<env name="DB_USERNAME" value="root"/>
23+
<env name="MAIL_MAILER" value="log"/>
3224
<env name="LIMIT_UUID_LENGTH_32" value="1"/>
3325
<env name="QUEUE_DRIVER" value="sync"/>
3426
<env name="TENANCY_DATABASE_AUTO_DELETE" value="1"/>

readme.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Join our Discord server](https://discordapp.com/api/guilds/146267795754057729/embed.png)](https://tenancy.dev/chat)
77
[![Mentioned in Awesome Laravel](https://awesome.re/mentioned-badge.svg)](https://github.com/chiraggude/awesome-laravel)
88

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

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

@@ -35,10 +35,10 @@ Database separation methods:
3535

3636
## Requirements, recommended environment
3737

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

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

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

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

5656
#### Manual service registration
5757

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

6161
```json

src/Providers/Tenants/ConnectionProvider.php

+20-5
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,34 @@ public function register()
3838
protected function registerMigrationCommands()
3939
{
4040
$this->app->singleton(Console\Migrations\FreshCommand::class, function (Application $app) {
41-
return new Console\Migrations\FreshCommand($app->make('migrator'));
41+
return new Console\Migrations\FreshCommand(
42+
$app->make('migrator'),
43+
$app->make("events")
44+
);
4245
});
4346
$this->app->singleton(Console\Migrations\MigrateCommand::class, function (Application $app) {
44-
return new Console\Migrations\MigrateCommand($app->make('migrator'));
47+
return new Console\Migrations\MigrateCommand(
48+
$app->make('migrator'),
49+
$app->make("events")
50+
);
4551
});
4652
$this->app->singleton(Console\Migrations\RollbackCommand::class, function (Application $app) {
47-
return new Console\Migrations\RollbackCommand($app->make('migrator'));
53+
return new Console\Migrations\RollbackCommand(
54+
$app->make('migrator'),
55+
$app->make("events")
56+
);
4857
});
4958
$this->app->singleton(Console\Migrations\ResetCommand::class, function (Application $app) {
50-
return new Console\Migrations\ResetCommand($app->make('migrator'));
59+
return new Console\Migrations\ResetCommand(
60+
$app->make('migrator'),
61+
$app->make("events")
62+
);
5163
});
5264
$this->app->singleton(Console\Migrations\RefreshCommand::class, function (Application $app) {
53-
return new Console\Migrations\RefreshCommand($app->make('migrator'));
65+
return new Console\Migrations\RefreshCommand(
66+
$app->make('migrator'),
67+
$app->make("events")
68+
);
5469
});
5570
$this->app->singleton(Console\Seeds\SeedCommand::class, function (Application $app) {
5671
return new Console\Seeds\SeedCommand($app['db']);

src/Traits/MutatesMigrationCommands.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
namespace Hyn\Tenancy\Traits;
1616

17-
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;
17+
use InvalidArgumentException;
1818
use Hyn\Tenancy\Database\Connection;
19+
use Illuminate\Contracts\Events\Dispatcher;
1920
use Illuminate\Database\Migrations\Migrator;
20-
use InvalidArgumentException;
21+
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;
2122

2223
trait MutatesMigrationCommands
2324
{
@@ -31,9 +32,9 @@ trait MutatesMigrationCommands
3132
*/
3233
private $connection;
3334

34-
public function __construct(Migrator $migrator)
35+
public function __construct(Migrator $migrator, Dispatcher $dispatcher)
3536
{
36-
parent::__construct($migrator);
37+
parent::__construct($migrator, $dispatcher);
3738

3839
$this->setName('tenancy:' . $this->getName());
3940
$this->specifyParameters();

tests/seeds/SampleSeeder.php

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<?php
22

3+
/*
4+
* This file is part of the hyn/multi-tenant package.
5+
*
6+
* (c) Daniël Klabbers <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @see https://tenancy.dev
12+
* @see https://github.com/hyn/multi-tenant
13+
*/
14+
15+
namespace Hyn\Tenancy\Tests\Seeds;
16+
317
/*
418
* This file is part of the hyn/multi-tenant package.
519
*

tests/traits/InteractsWithMigrations.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Hyn\Tenancy\Providers\TenancyProvider;
1818
use Hyn\Tenancy\Providers\Tenants\ConfigurationProvider;
1919
use Illuminate\Database\Eloquent\Collection;
20-
use SampleSeeder;
20+
use Hyn\Tenancy\Tests\Seeds\SampleSeeder;
2121
use Mockery;
2222
use Hyn\Tenancy\Database\Connection;
2323
use Illuminate\Contracts\Console\Kernel;

tests/unit-tests/Commands/FreshCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Hyn\Tenancy\Database\Console\Migrations\FreshCommand;
1818
use Hyn\Tenancy\Models\Website;
1919
use Illuminate\Contracts\Foundation\Application;
20-
use SampleSeeder;
20+
use Hyn\Tenancy\Tests\Seeds\SampleSeeder;
2121

2222
class FreshCommandTest extends DatabaseCommandTest
2323
{

tests/unit-tests/Commands/SeedCommandTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Hyn\Tenancy\Database\Console\Seeds\SeedCommand;
1818
use Hyn\Tenancy\Models\Website;
1919
use Illuminate\Contracts\Console\Kernel;
20-
use SampleSeeder;
20+
use Hyn\Tenancy\Tests\Seeds\SampleSeeder;
2121

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

110110
$this->assertEquals(
111-
2, $this->connection->get()->table('samples')->count(),
111+
2,
112+
$this->connection->get()->table('samples')->count(),
112113
"Connection for {$website->uuid} has incorrect sample data"
113114
);
114115
});

tests/unit-tests/Queue/TenantAwareJobTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace Hyn\Tenancy\Tests\Queue;
1616

17-
use App\User;
17+
use App\Models\User;
1818
use Illuminate\Contracts\Foundation\Application;
1919
use Hyn\Tenancy\Tests\Test;
2020
use Illuminate\Bus\Queueable;
@@ -93,7 +93,7 @@ public function current_website_id_is_included_in_notification_job_payload()
9393

9494
Event::fake();
9595

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

9999
Event::assertDispatched(JobProcessed::class, function ($event) {

tests/unit-tests/Repositories/HostnameRepositoryTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
* @see https://github.com/hyn/multi-tenant
1313
*/
1414

15-
namespace Hyn\Tenancy\Tests;
15+
namespace Hyn\Tenancy\Tests\Repositories;
1616

17-
use Hyn\Tenancy\Exceptions\ModelValidationException;
18-
use Illuminate\Contracts\Foundation\Application;
17+
use Hyn\Tenancy\Tests\Test;
1918
use Illuminate\Support\Arr;
19+
use Illuminate\Contracts\Foundation\Application;
20+
use Hyn\Tenancy\Exceptions\ModelValidationException;
2021

2122
class HostnameRepositoryTest extends Test
2223
{

tests/unit-tests/Repositories/WebsiteRepositoryTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
* @see https://github.com/hyn/multi-tenant
1313
*/
1414

15-
namespace Hyn\Tenancy\Tests;
15+
namespace Hyn\Tenancy\Tests\Repositories;
1616

17+
use Hyn\Tenancy\Tests\Test;
1718
use Illuminate\Contracts\Foundation\Application;
1819

1920
class WebsiteRepositoryTest extends Test

0 commit comments

Comments
 (0)