43 lines
2.1 KiB
Swift
43 lines
2.1 KiB
Swift
import Foundation
|
|
import HelderCore
|
|
import Testing
|
|
|
|
@Suite struct ArtisanConsoleTests {
|
|
@Test("stdout lines are classified", arguments: [
|
|
(" Connection ............................ mysql · odynt", ArtisanLineKind.output),
|
|
(" Tables ................................ 16", .output),
|
|
(" INFO Wrote database/helder/schema.json (18.4 KB).", .success),
|
|
(" Wrote database/helder/schema.json (18.4 KB)", .success),
|
|
(" DONE Schema dumped in 0.41s.", .success),
|
|
(" ERROR SQLSTATE[HY000] [2002] Connection refused.", .error),
|
|
(" Illuminate\\Database\\QueryException", .error),
|
|
("", .output),
|
|
])
|
|
func classify(line: String, expected: ArtisanLineKind) {
|
|
#expect(ArtisanOutputClassifier.classify(line, isError: false) == expected)
|
|
}
|
|
|
|
@Test func everyStderrLineIsAnError() {
|
|
#expect(ArtisanOutputClassifier.classify("PHP Warning: something", isError: true) == .error)
|
|
#expect(ArtisanOutputClassifier.line(" DONE x", isError: true) == ArtisanConsoleLine(text: " DONE x", kind: .error))
|
|
}
|
|
|
|
@Test func theEchoAndPathsMatchTheCommand() {
|
|
#expect(ArtisanOutputClassifier.commandEcho == "$ php artisan helder:schema")
|
|
#expect(SchemaPaths.commandFile == "app/Console/Commands/HelderSchemaCommand.php")
|
|
#expect(SchemaPaths.dumpFile == "database/helder/schema.json")
|
|
#expect(SchemaPaths.artisanFile == "artisan")
|
|
}
|
|
|
|
@Test func thePromptNamesTheFileTheContractAndTheIgnoreFile() {
|
|
let text = SchemaCommandPrompt.text
|
|
#expect(text.hasPrefix("Build an Artisan command that dumps this app's database schema for Helder"))
|
|
#expect(text.contains("Class: App\\Console\\Commands\\HelderSchemaCommand, extends Illuminate\\Console\\Command"))
|
|
#expect(text.contains("File: " + SchemaPaths.commandFile))
|
|
#expect(text.contains("\"foreign_keys\": [ <Schema::getForeignKeys($table), unchanged> ]"))
|
|
#expect(text.contains("`*` and `!.gitignore`"))
|
|
#expect(text.hasSuffix("run `php artisan helder:schema` once and show me the output."))
|
|
#expect(text.contains("\n{\n \"version\": 1,\n"))
|
|
}
|
|
}
|