Skip to content

Commit 8f5e12a

Browse files
committed
Make sure DatabaseCacheBootstrapper runs after DatabaseTenancyBootstrapper, misc wip changes
1 parent 5971831 commit 8f5e12a

6 files changed

Lines changed: 70 additions & 8 deletions

File tree

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,16 @@ RUN echo "apc.enable_cli=1" >> "$PHP_INI_DIR/php.ini"
3030
# Only used on GHA
3131
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
3232

33+
# Conditionally install and configure Xdebug (last step for faster rebuilds)
34+
ARG XDEBUG_ENABLED=false
35+
RUN if [ "$XDEBUG_ENABLED" = "true" ]; then \
36+
pecl install xdebug && docker-php-ext-enable xdebug && \
37+
echo "xdebug.mode=debug" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
38+
echo "xdebug.start_with_request=yes" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
39+
echo "xdebug.client_host=host.docker.internal" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
40+
echo "xdebug.client_port=9003" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
41+
echo "xdebug.discover_client_host=true" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" && \
42+
echo "xdebug.log=/var/log/xdebug.log" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini"; \
43+
fi
44+
3345
WORKDIR /var/www/html

composer.json

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@
6363
"docker-up": "docker compose up -d",
6464
"docker-down": "docker compose down",
6565
"docker-restart": "docker compose down && docker compose up -d",
66-
"docker-rebuild": "PHP_VERSION=8.4 docker compose up -d --no-deps --build",
66+
"docker-rebuild": [
67+
"Composer\\Config::disableProcessTimeout",
68+
"PHP_VERSION=8.4 docker compose up -d --no-deps --build"
69+
],
70+
"docker-rebuild-with-xdebug": [
71+
"Composer\\Config::disableProcessTimeout",
72+
"PHP_VERSION=8.4 XDEBUG_ENABLED=true docker compose up -d --no-deps --build"
73+
],
6774
"docker-m1": "ln -s docker-compose-m1.override.yml docker-compose.override.yml",
6875
"testbench-unlink": "rm ./vendor/orchestra/testbench-core/laravel/vendor",
6976
"testbench-link": "ln -s /var/www/html/vendor ./vendor/orchestra/testbench-core/laravel/vendor",
@@ -72,10 +79,22 @@
7279
"phpstan": "vendor/bin/phpstan --memory-limit=256M",
7380
"phpstan-pro": "vendor/bin/phpstan --memory-limit=256M --pro",
7481
"cs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --config=.php-cs-fixer.php",
75-
"test": "./test --no-coverage",
76-
"test-full": "./test",
77-
"act": "act -j tests --matrix 'laravel:^11.0'",
78-
"act-input": "act -j tests --matrix 'laravel:^11.0' --input"
82+
"test": [
83+
"Composer\\Config::disableProcessTimeout",
84+
"./test --no-coverage"
85+
],
86+
"test-full": [
87+
"Composer\\Config::disableProcessTimeout",
88+
"./test"
89+
],
90+
"act": [
91+
"Composer\\Config::disableProcessTimeout",
92+
"act -j tests --matrix 'laravel:^11.0'"
93+
],
94+
"act-input": [
95+
"Composer\\Config::disableProcessTimeout",
96+
"act -j tests --matrix 'laravel:^11.0' --input"
97+
]
7998
},
8099
"minimum-stability": "dev",
81100
"prefer-stable": true,

docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ services:
22
test:
33
build:
44
context: .
5+
args:
6+
XDEBUG_ENABLED: ${XDEBUG_ENABLED:-false}
57
depends_on:
68
mysql:
79
condition: service_healthy
@@ -18,7 +20,8 @@ services:
1820
dynamodb:
1921
condition: service_healthy
2022
volumes:
21-
- .:/var/www/html:cached
23+
- .:$PWD:cached
24+
working_dir: $PWD
2225
environment:
2326
DOCKER: 1
2427
DB_PASSWORD: password
@@ -30,6 +33,8 @@ services:
3033
TENANCY_TEST_SQLSRV_HOST: mssql
3134
TENANCY_TEST_SQLSRV_USERNAME: sa
3235
TENANCY_TEST_SQLSRV_PASSWORD: P@ssword
36+
extra_hosts:
37+
- "host.docker.internal:host-gateway"
3338
stdin_open: true
3439
tty: true
3540
mysql:

src/Bootstrappers/DatabaseCacheBootstrapper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Stancl\Tenancy\Bootstrappers;
66

7+
use Exception;
78
use Illuminate\Cache\CacheManager;
89
use Illuminate\Config\Repository;
910
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
@@ -39,6 +40,10 @@ public function __construct(
3940

4041
public function bootstrap(Tenant $tenant): void
4142
{
43+
if (! config('database.connections.tenant')) {
44+
throw new Exception('DatabaseCacheBootstrapper must run after DatabaseTenancyBootstrapper.');
45+
}
46+
4247
$stores = $this->getDatabaseCacheStores();
4348

4449
foreach ($stores as $storeName) {

tests/Pest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,42 @@
22

33
namespace Stancl\Tenancy\Tests;
44

5+
use Illuminate\Database\Schema\Blueprint;
56
use Stancl\Tenancy\Tests\TestCase;
67
use Stancl\JobPipeline\JobPipeline;
78
use Illuminate\Support\Facades\Event;
9+
use Illuminate\Support\Facades\Schema;
810
use Stancl\Tenancy\Jobs\CreateDatabase;
911
use Stancl\Tenancy\Events\TenantCreated;
12+
use Stancl\Tenancy\Jobs\MigrateDatabase;
1013

1114
uses(TestCase::class)->in(__DIR__);
1215

13-
function withTenantDatabases()
16+
function withTenantDatabases(bool $migrate = false)
1417
{
15-
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
18+
Event::listen(TenantCreated::class, JobPipeline::make($migrate
19+
? [CreateDatabase::class]
20+
: [CreateDatabase::class, MigrateDatabase::class]
21+
)->send(function (TenantCreated $event) {
1622
return $event->tenant;
1723
})->toListener());
1824
}
1925

26+
function withCacheTables()
27+
{
28+
Schema::create('cache', function (Blueprint $table) {
29+
$table->string('key')->primary();
30+
$table->mediumText('value');
31+
$table->integer('expiration');
32+
});
33+
34+
Schema::create('cache_locks', function (Blueprint $table) {
35+
$table->string('key')->primary();
36+
$table->string('owner');
37+
$table->integer('expiration');
38+
});
39+
}
40+
2041
function pest(): TestCase
2142
{
2243
return \Pest\TestSuite::getInstance()->test;

0 commit comments

Comments
 (0)