Skip to content

Commit 3e95207

Browse files
author
JP
committed
fix: test environment setup for clean Docker installs
- Add .env.testing.example pre-configured for Docker Compose local dev - Document .env.testing requirement and stopOnFailure behavior in LOCAL_DEVELOPMENT_HOWTO.md - Update .gitignore to allow .env.testing.example despite .env.* rule - Seed groups API and scopes in TestSeeder so OAuth2GroupApiTest passes in clean environments
1 parent 0d6b7e3 commit 3e95207

File tree

4 files changed

+152
-2
lines changed

4 files changed

+152
-2
lines changed

.env.testing.example

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# .env.testing.example
2+
# Copy this to .env.testing before running the test suite.
3+
# Pre-configured for the standard Docker Compose local setup.
4+
# Adjust DB/Redis credentials if you changed them from the defaults.
5+
6+
APP_ENV=testing
7+
APP_DEBUG=true
8+
# Generate with: php artisan key:generate --show
9+
APP_KEY=
10+
APP_URL=http://localhost
11+
12+
DB_CONNECTION=mysql
13+
DB_HOST=db
14+
DB_PORT=3306
15+
DB_DATABASE=idp_local
16+
DB_USERNAME=idp_user
17+
DB_PASSWORD=1qaz2wsx!
18+
DB_USE_SSL=false
19+
20+
REDIS_HOST=redis
21+
REDIS_PORT=6379
22+
REDIS_DB=0
23+
REDIS_PASSWORD=1qaz2wsx!
24+
REDIS_DATABASES=16
25+
26+
CACHE_DRIVER=redis
27+
SESSION_DRIVER=redis
28+
SESSION_COOKIE_DOMAIN=localhost
29+
SESSION_COOKIE_SECURE=false
30+
31+
QUEUE_DRIVER=redis
32+
QUEUE_CONN=openstackid
33+
QUEUE_DATABASE=openstackid
34+
35+
MAIL_DRIVER=log
36+
MAIL_FROM_EMAIL=noreply@localhost
37+
MAIL_FROM_NAME=OpenStackID
38+
39+
CORS_ALLOWED_HEADERS="origin, content-type, accept, authorization, x-requested-with"
40+
CORS_ALLOWED_METHODS="GET, POST, OPTIONS, PUT, DELETE"
41+
CORS_USE_PRE_FLIGHT_CACHING=true
42+
CORS_MAX_AGE=3200
43+
44+
CURL_TIMEOUT=60
45+
CURL_ALLOWS_REDIRECT=false
46+
CURL_VERIFY_SSL_CERT=false
47+
48+
SSL_ENABLED=false
49+
DB_LOG_ENABLED=false
50+
ACCESS_TOKEN_CACHE_LIFETIME=300
51+
API_RESPONSE_CACHE_LIFETIME=600
52+
53+
LOG_LEVEL=debug
54+
55+
RECAPTCHA_PUBLIC_KEY=
56+
RECAPTCHA_PRIVATE_KEY=
57+
58+
BANNING_ENABLE=true
59+
SUPPORT_EMAIL=test@localhost
60+
MAIL_SEND_WELCOME_EMAIL=0
61+
62+
AUTH_ALLOWS_NATIVE_AUTH=1
63+
AUTH_ALLOWS_OTP=1
64+
AUTH_ALLOWS_NATIVE_AUTH_CONFIG=1
65+
OTP_DEFAULT_LIFETIME=600
66+
OTP_DEFAULT_LENGTH=6
67+
68+
AUTH_PASSWORD_RESET_LIFETIME=1800
69+
AUTH_PASSWORD_SHAPE_PATTERN="^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-])"
70+
AUTH_PASSWORD_SHAPE_WARNING="Password must include at least one uppercase letter, one lowercase letter, one number, and one special character."
71+
72+
OTEL_SERVICE_ENABLED=false
73+
OTEL_SDK_DISABLED=true
74+
75+
L5_SWAGGER_CONST_HOST=http://localhost
76+
L5_SWAGGER_GENERATE_ALWAYS=false
77+
78+
FACEBOOK_REDIRECT_URI=/auth/login/facebook/callback
79+
GOOGLE_REDIRECT_URI=/auth/login/google/callback
80+
APPLE_REDIRECT_URI=/auth/login/apple/callback
81+
LINKEDIN_REDIRECT_URI=/auth/login/linkedin/callback
82+
83+
APP_NAME="Open Event"
84+
TENANT_NAME="the Open Event Platform"

.gitignore

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Homestead.yaml
1515
Homestead.json
1616
.env
1717
.env.*
18+
!.env.testing.example
1819
storage/*
1920
/public/assets/jquery-cookie/
2021
/public/assets/crypto-js/

LOCAL_DEVELOPMENT_HOWTO.md

100644100755
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,31 @@ check containers health status
4343

4444
````bash
4545
docker inspect --format "{{json .State.Health }}" www-openstack-model-db-local | jq '.
46-
````
46+
````
47+
Running the Test Suite
48+
======================
49+
50+
The test suite uses `APP_ENV=testing`, which causes Laravel to load `.env.testing`
51+
instead of `.env`. **You must create a `.env.testing` file before running tests** —
52+
this is a Laravel convention and is not obvious from the error output if it's missing.
53+
54+
Copy the example file and adjust if needed:
55+
56+
```bash
57+
cp .env.testing.example .env.testing
58+
```
59+
60+
The example file is pre-configured for the standard Docker Compose setup (same
61+
credentials as `.env`). If you changed any DB or Redis credentials, update `.env.testing`
62+
to match.
63+
64+
Then run the tests:
65+
66+
```bash
67+
./run_tests.sh
68+
```
69+
70+
**Note:** The test suite clears and re-seeds the relevant DB tables on every run, so
71+
you do not need to run `idp:fresh` before running tests. Also, `phpunit.xml` is
72+
configured with `stopOnFailure=true`if you see fewer tests than expected, it means
73+
an earlier test failed and halted the suite.

database/seeds/TestSeeder.php

100644100755
Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ public function run()
455455
$this->seedApiScopes();
456456
$this->seedApiEndpointScopes();
457457
$this->seedApiScopeScopes();
458+
$this->seedGroupScopes();
458459
$this->seedTestApiEndpoints();
459460
// clients
460461
$this->seedTestUsersAndClients();
@@ -740,6 +741,13 @@ private function seedApis(){
740741
'description' => 'Api Scopes CRUD operations',
741742
'resource_server' => $resource_server,
742743
'logo' => asset('/assets/img/apis/server.png')
744+
),
745+
array(
746+
'name' => 'groups',
747+
'active' => true,
748+
'description' => 'Groups Info API',
749+
'resource_server' => $resource_server,
750+
'logo' => asset('/assets/img/apis/server.png')
743751
),
744752
];
745753

@@ -1162,7 +1170,37 @@ private function seedApiScopes(){
11621170
EntityManager::flush();
11631171
}
11641172

1165-
private function seedTestApiEndpoints(){
1173+
private function seedGroupScopes(){
1174+
$api_repository = EntityManager::getRepository(Api::class);
1175+
$api = $api_repository->findOneBy(['name' => 'groups']);
1176+
if(is_null($api)) return;
1177+
1178+
$scope_payloads = [
1179+
array(
1180+
'name' => \App\libs\OAuth2\IGroupScopes::ReadAll,
1181+
'short_description' => 'Allows access to Groups info.',
1182+
'description' => 'Allows access to Groups info.',
1183+
'api' => $api,
1184+
'system' => false,
1185+
'active' => true,
1186+
),
1187+
array(
1188+
'name' => \App\libs\OAuth2\IGroupScopes::Write,
1189+
'short_description' => 'Allows access to write Groups info.',
1190+
'description' => 'Allows access to write Groups info.',
1191+
'api' => $api,
1192+
'system' => false,
1193+
'active' => true,
1194+
),
1195+
];
1196+
1197+
foreach($scope_payloads as $payload) {
1198+
EntityManager::persist(ApiScopeFactory::build($payload));
1199+
}
1200+
EntityManager::flush();
1201+
}
1202+
1203+
private function seedTestApiEndpoints(){
11661204

11671205
$current_realm = Config::get('app.url');
11681206

0 commit comments

Comments
 (0)