['ID', 'Accountid', 'Last', 'Email', 'FENContact1'], 'accounts' => ['ID', 'Name', 'Type'], 'renewals' => ['id', 'account_id', 'status', 'selected'], 'members.ExcludedAccounts' => ['ExcludedAccount'], ]); $parser = new DslParser(); $validator = new DslValidator($metadata); $compiler = new DslCompiler($metadata); $cases = [ [ 'dsl' => "contacts and accounts where contacts.Last contains 'smith' and contacts.Accountid = accounts.ID", 'expectValid' => true, ], [ 'dsl' => 'accounts where pending-renewal', 'expectValid' => false, ], [ 'dsl' => 'contacts and members.ExcludedAccounts', 'expectValid' => false, ], ]; $failures = []; foreach ($cases as $case) { $ast = $parser->parse($case['dsl']); $validation = $validator->validate($ast); $isValid = $validation['errors'] === []; if ($isValid !== $case['expectValid']) { $failures[] = ['dsl' => $case['dsl'], 'errors' => $validation['errors']]; continue; } if ($isValid) { $compiled = $compiler->compile($ast); if (strpos($compiled['sql'], 'SELECT ') !== 0) { $failures[] = ['dsl' => $case['dsl'], 'errors' => ['Compilation did not produce SELECT']]; } } } if ($failures !== []) { fwrite(STDERR, "DSL pipeline test failures:\n" . json_encode($failures, JSON_PRETTY_PRINT) . "\n"); exit(1); } echo "DSL pipeline tests passed\n";