-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-multi-version.sh
More file actions
executable file
·255 lines (208 loc) · 7.4 KB
/
test-multi-version.sh
File metadata and controls
executable file
·255 lines (208 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/bash
# Multi-Version Testing Script for Laravel Model Schema Checker
# Tests against Laravel 11 and 12 using DDEV
set -e
echo "🧪 Laravel Model Schema Checker - Multi-Version Test"
echo "=================================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if DDEV is available
if ! command -v ddev &> /dev/null; then
print_error "DDEV is not installed or not in PATH"
echo "Please install DDEV: https://ddev.readthedocs.io/en/latest/users/install/"
exit 1
fi
# Check if we're in the right directory
if [ ! -f "composer.json" ] || [ ! -d "src" ]; then
print_error "Please run this from the laravel-model-schema-checker root directory"
exit 1
fi
# Store the project root directory
PROJECT_ROOT="$(pwd)"
# Laravel versions to test
LARAVEL_VERSIONS=("11" "12")
print_status "Testing against Laravel versions: ${LARAVEL_VERSIONS[*]} using DDEV"
print_status "Each version will run in its own isolated DDEV environment"
# Function to test a specific Laravel version
test_laravel_version() {
local laravel_version=$1
local project_name="test-laravel-$laravel_version"
local project_dir="/tmp/$project_name"
print_status "Testing Laravel $laravel_version with DDEV..."
# Clean up any existing DDEV project
if ddev list | grep -q "$project_name"; then
print_status "Removing existing DDEV project: $project_name"
ddev stop "$project_name" > /dev/null 2>&1 || true
ddev delete "$project_name" --omit-snapshot > /dev/null 2>&1 || true
fi
# Clean up project directory
rm -rf "$project_dir"
# Create project directory
mkdir -p "$project_dir"
cd "$project_dir"
# Initialize DDEV project
print_status "Initializing DDEV project for Laravel $laravel_version..."
# Copy DDEV configuration template
if [ -f "$PROJECT_ROOT/ddev-configs/laravel-$laravel_version.yaml" ]; then
mkdir -p .ddev
cp "$PROJECT_ROOT/ddev-configs/laravel-$laravel_version.yaml" .ddev/config.yaml
# Update the project name in the config
sed -i "s/name: test-laravel-$laravel_version/name: $project_name/" .ddev/config.yaml
else
print_error "DDEV configuration template not found for Laravel $laravel_version at $PROJECT_ROOT/ddev-configs/laravel-$laravel_version.yaml"
cd - > /dev/null
return 1
fi
# Create Laravel project using DDEV
print_status "Creating Laravel $laravel_version project with DDEV..."
if ! ddev composer create --no-interaction --prefer-dist laravel/laravel:^${laravel_version}.0 .; then
print_error "Failed to create Laravel $laravel_version project with DDEV"
cd - > /dev/null
return 1
fi
print_success "Laravel $laravel_version project created with DDEV"
# Start DDEV project
print_status "Starting DDEV project..."
if ! ddev start > /dev/null 2>&1; then
print_error "Failed to start DDEV project for Laravel $laravel_version"
cd - > /dev/null
return 1
fi
# Install package by copying files directly to vendor directory
print_status "Installing Laravel Model Schema Checker package..."
# Create vendor directory structure
mkdir -p vendor/ndestates
# Copy package files directly
cp -r "$PROJECT_ROOT" vendor/ndestates/laravel-model-schema-checker
# Remove the copied test directories to avoid conflicts
rm -rf vendor/ndestates/laravel-model-schema-checker/test-package
rm -rf vendor/ndestates/laravel-model-schema-checker/ddev-configs
# Run composer install to ensure dependencies are resolved
if ! ddev composer install --no-interaction; then
print_error "Failed to install dependencies in Laravel $laravel_version"
ddev stop > /dev/null 2>&1 || true
cd - > /dev/null
return 1
fi
# Register the package
if ! ddev artisan package:discover --ansi; then
print_error "Failed to discover package in Laravel $laravel_version"
ddev stop > /dev/null 2>&1 || true
cd - > /dev/null
return 1
fi
print_success "Package installed in Laravel $laravel_version"
# Test basic functionality
print_status "Testing basic functionality..."
# Test help command
if ddev artisan model:schema-check --help > /dev/null 2>&1; then
print_success "Help command works in Laravel $laravel_version"
else
print_error "Help command failed in Laravel $laravel_version"
ddev stop > /dev/null 2>&1 || true
cd - > /dev/null
return 1
fi
# Test dry run
if ddev artisan model:schema-check --dry-run > /dev/null 2>&1; then
print_success "Dry run works in Laravel $laravel_version"
else
print_error "Dry run failed in Laravel $laravel_version"
ddev stop > /dev/null 2>&1 || true
cd - > /dev/null
return 1
fi
# Test backup functionality
if ddev artisan model:schema-check --backup > /dev/null 2>&1; then
print_success "Backup functionality works in Laravel $laravel_version"
else
print_error "Backup functionality failed in Laravel $laravel_version"
ddev stop > /dev/null 2>&1 || true
cd - > /dev/null
return 1
fi
# Stop DDEV project
print_status "Stopping DDEV project..."
ddev stop > /dev/null 2>&1 || true
cd - > /dev/null
# Cleanup
rm -rf "$project_dir"
print_success "Laravel $laravel_version test completed successfully"
return 0
}
# Run tests for each Laravel version
FAILED_VERSIONS=()
for version in "${LARAVEL_VERSIONS[@]}"; do
if test_laravel_version "$version"; then
print_success "✅ Laravel $version: PASSED"
else
print_error "❌ Laravel $version: FAILED"
FAILED_VERSIONS+=("$version")
fi
echo ""
done
# Run local code quality checks
print_status "Running code quality checks..."
# Run PHPStan
if composer stan > /dev/null 2>&1; then
print_success "PHPStan analysis passed"
else
print_error "PHPStan analysis failed"
exit 1
fi
# Run PHPUnit
if composer test > /dev/null 2>&1; then
print_success "Unit tests passed"
else
print_error "Unit tests failed"
exit 1
fi
# Run PHP CodeSniffer
if composer cs > /dev/null 2>&1; then
print_success "Code style check passed"
else
print_error "Code style check failed"
exit 1
fi
# Run PHPMD
if composer md > /dev/null 2>&1; then
print_success "Mess detection passed"
else
print_warning "Mess detection found issues (review output above)"
fi
# Summary
echo ""
echo "📊 Test Summary"
echo "=============="
if [ ${#FAILED_VERSIONS[@]} -eq 0 ]; then
print_success "🎉 All tests passed!"
print_success "Laravel Model Schema Checker is compatible with Laravel ${LARAVEL_VERSIONS[*]} using DDEV"
else
print_error "❌ Some tests failed for Laravel versions: ${FAILED_VERSIONS[*]}"
exit 1
fi
echo ""
print_status "Next steps:"
echo "1. Review any code quality issues found"
echo "2. Run manual testing: ./test-ddev.sh"
echo "3. Update documentation if needed"
echo "4. Prepare for v3.0.0 release"
echo ""
print_status "Note: All DDEV test environments have been cleaned up"