Skip to content

Commit 416fb67

Browse files
committed
test: increase code coverage to 85%
- Add comprehensive tests for MonitorManager (SQLite-specific methods, query stats) - Add tests for Seed class helper methods (schema, find, execute, insert, update, delete, raw) - Add tests for ExternalReferenceProcessingTrait (WHERE EXISTS/NOT EXISTS scenarios) - Add tests for BaseCliCommand (loadEnvFile, buildConfigFromEnv, readInput, readConfirmation, loadCacheConfig) - Extend RetryableConnection tests (waitBeforeRetry, config validation, retry operations) - Fix readPassword() to return empty string in non-interactive mode to prevent blocking - Fix SeedGenerator to skip interactive prompts in non-interactive mode - Ensure all CLI tests set PDODB_NON_INTERACTIVE and PHPUNIT environment variables - Add non-interactive mode check in bin/pdodb script - Improve environment variable cleanup in test tearDown methods All tests pass without blocking or requiring user input.
1 parent 097d195 commit 416fb67

10 files changed

Lines changed: 1103 additions & 17 deletions

bin/pdodb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ require_once $autoloadPath;
4848

4949
use tommyknocker\pdodb\cli\Application;
5050

51+
// Ensure non-interactive mode for tests and CI
52+
if (getenv('PHPUNIT') !== false || getenv('PDODB_NON_INTERACTIVE') !== false) {
53+
putenv('PDODB_NON_INTERACTIVE=1');
54+
putenv('PHPUNIT=1');
55+
}
56+
5157
$application = new Application();
5258
exit($application->run($argv));
5359

src/cli/BaseCliCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ protected static function readPassword(string $prompt): string
440440
|| !stream_isatty(STDIN);
441441

442442
if ($nonInteractive) {
443-
// In non-interactive mode, try to read from stdin if available
444-
$input = trim((string)fgets(STDIN));
445-
return $input;
443+
// In non-interactive mode, return empty string to avoid blocking on fgets(STDIN)
444+
// Tests and CI environments should provide passwords via environment variables or other means
445+
return '';
446446
}
447447

448448
// Use stty to hide input on Unix-like systems

src/cli/SeedGenerator.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,25 @@ public static function generate(?string $name = null, ?string $seedPath = null):
4444
}
4545
}
4646

47-
// Suggest seed type based on name
48-
$suggestions = static::suggestSeedType($name);
49-
if (!empty($suggestions)) {
50-
echo "\nSuggested seed types:\n";
51-
foreach ($suggestions as $i => $suggestion) {
52-
echo ' ' . ($i + 1) . ". {$suggestion}\n";
53-
}
54-
echo " 0. Custom (manual)\n";
55-
$choice = static::readInput("\nSelect seed type", '0');
56-
$selectedIndex = (int)$choice - 1;
57-
if ($selectedIndex >= 0 && $selectedIndex < count($suggestions)) {
58-
$seedType = $suggestions[$selectedIndex];
59-
static::info("Selected: {$seedType}");
47+
// Suggest seed type based on name (skip in non-interactive mode)
48+
$nonInteractive = getenv('PDODB_NON_INTERACTIVE') !== false
49+
|| getenv('PHPUNIT') !== false
50+
|| !stream_isatty(STDIN);
51+
52+
if (!$nonInteractive) {
53+
$suggestions = static::suggestSeedType($name);
54+
if (!empty($suggestions)) {
55+
echo "\nSuggested seed types:\n";
56+
foreach ($suggestions as $i => $suggestion) {
57+
echo ' ' . ($i + 1) . ". {$suggestion}\n";
58+
}
59+
echo " 0. Custom (manual)\n";
60+
$choice = static::readInput("\nSelect seed type", '0');
61+
$selectedIndex = (int)$choice - 1;
62+
if ($selectedIndex >= 0 && $selectedIndex < count($suggestions)) {
63+
$seedType = $suggestions[$selectedIndex];
64+
static::info("Selected: {$seedType}");
65+
}
6066
}
6167
}
6268

0 commit comments

Comments
 (0)