Documentation menu

Testing and operations

Command line

Every Taphra app has a taphra script at its root. It is a Symfony Console application: php taphra list shows the commands, php taphra help <command> shows a command's arguments and options. This page lists the commands of a new skeleton app, grouped as php taphra list groups them.

Contents

#

Running commands

#
Shell
php taphra list                 # every command
php taphra list make            # one group
php taphra help migrate         # arguments and options of one command

The usual Symfony Console options work on every command: -n (no questions), -q (quiet), -v, -vv, -vvv (more output), --ansi and --no-ansi, -V (the framework version).

The command line reads its environment from APP_ENV, like a web request. An unset or unknown APP_ENV means production, so php taphra migrate on your laptop uses the prod: section of app/Config/databases.yml unless you set it:

Shell
export APP_ENV=dev              # dev, development or local; stg or staging; anything else is production
php taphra migrate:status

php taphra serve is the exception: it sets APP_ENV=dev for its server when the variable is not set.

General

#
Command What it does
serve Starts PHP's built-in server on app/Static with clean URLs. Options: --host (default 127.0.0.1), --port (default 8000), --tunnel (opens a public URL through ngrok or expose when one of them is installed). For development only.
setup An interactive first-run wizard: asks for the database and cache settings, writes app/Config/databases.yml and app/Config/app.yml, writes a secret key to .env, creates the app/tmp folders and offers to run the migrations.
key:generate Writes a random 64-character hex APP_SECRET_KEY to .env. --force replaces an existing key. composer create-project runs this for you.
tinker An interactive PHP shell with the app booted. Needs PsySH: composer require --dev psy/psysh.
completion Prints a shell completion script (bash, zsh, fish).
list, help The command list and one command's help.

Database

#
Command What it does
migrate (alias migrate:up) Runs the pending migrations, or up to the migration [id]. --dry-run prints what would run, with the SQL, and changes nothing. With more migration folders (packages, paths in migrations.yml), this and the other migrate:* commands cover all of them (Database).
migrate:status Lists every migration as Ran or Pending.
migrate:rollback Rolls back the last migration. --dry-run previews.
migrate:down [id] Rolls back every migration after [id] (without an id, the last one); migrate:down reset rolls back all of them. --dry-run previews.
migrate:reset Rolls back every migration, then runs them all again. --dry-run previews.
migrate:diff [connection] Compares the DataStore definitions with the live schema of a connection (default app_master) and reports the differences. It changes nothing.
make:migration <description> Creates app/Migrations/migration_<YYYYMMDDHHMMSS>_<Description>.php. The words of the description become the class name: php taphra make:migration create posts table writes ..._CreatePostsTable.php.
db:seed Runs App\Seeds\DatabaseSeeder from app/Seeds/. --class=PostSeeder runs another seeder; --fresh drops every table and runs all migrations first.
migration The older dispatcher (migration up, down, create, state). It is kept for existing scripts; new scripts use the migrate:* commands.

Migrations, seeders and factories are covered in Database. Where migration state is kept (a JSON file by default, or a table) is set in app/Config/migrations.yml.

Generators

#

Every generator writes into app/ (tests into test/) and refuses to overwrite a file that exists. They write <Class>.php files in the App\ namespace, which the skeleton's PSR-4 rule (App\ in app/) loads at once. A generator whose class extends a base class the app lacks writes that base class first: AppRestController for make:controller --rest, make:api-resource and make:auth, AppHelper for make:helper.

Command Creates
make:controller <Name> app/Controllers/<Name>Controller.php with an index() action. -r, --rest makes a JSON controller (extending AppRestController); -b, --before-action adds a beforeAction() hook that calls parent::beforeAction(), so the CSRF check stays on. An HTML controller also gets app/Views/<name>/index.tpl.php.
make:datastore <Name> app/DataStores/<Name>DataStore.php. -t, --table sets the table (the default comes from the name), -c, --connection the connection key (default app_master).
make:model <Name> app/Models/<Name>.php.
make:crud <Name> A REST resource in four files: app/DataStores/<Name>DataStore.php, app/Requests/<Name>FormRequest.php, app/Resources/<Name>Resource.php and app/Controllers/<Name>CrudController.php. --table overrides the table name. It prints the routes to add to routes.yml. See REST APIs.
make:api-resource <Name> app/Controllers/Api<Name>Controller.php (list, show, create, update, delete) and app/DataStores/<Name>DataStore.php. -p, --prefix (default /api/v1), -c, --connection, --no-datastore. It prints the routes to add, one GET:/POST:/PUT:/DELETE: section each.
make:auth app/Controllers/AuthController.php with login, refresh and logout actions. -g, --guard is jwt (default) or session. The JWT guard uses Taphra\Auth\Jwt (no extra package) and needs JWT_SECRET, at least 32 bytes; the session guard also writes the login form app/Views/auth/login.tpl.php. It prints the routes to add. See Authentication.
make:policy <Name> app/Policies/<Name>Policy.php with view, create, update and delete abilities. --plain writes an empty policy.
make:middleware <Name> app/Middleware/<Name>.php, a PSR-15 middleware (App\Middleware\<Name>). See Routing.
make:helper <Name> app/Helpers/<Name>Helper.php, a view helper extending AppHelper. List it in a controller's $helpers (['UiHelper']) to use it in the views as $ui.
make:provider <Name> app/Providers/<Name>ServiceProvider.php. Providers in app/Providers/ are found on the next request; you can also list them under app.providers in app.yml. See Container and providers.
make:command <Name> app/Commands/<Name>Command.php, a command object for the command bus.
make:handler <Name> app/Handlers/<Name>Handler.php; with --query, app/QueryHandlers/<Name>Handler.php.
make:console <Name> app/Console/<Name>Command.php, a command for this command line (see below).
make:seeder <Name> app/Seeds/<Name>Seeder.php. Run it with php taphra db:seed --class=<Name>Seeder.
make:factory <Name> app/Factories/<Name>Factory.php, a factory for <Name>DataStore.
make:test <Name> test/unit/<Name>Test.php, or test/integration/<Name>Test.php with -i, --integration. Both are plain PHPUnit test cases; for HTTP tests see Testing.
make:tool <Name> app/AiTools/<Name>Tool.php, a tool an AI agent can call. See AI.
make:prompt <name> app/Prompts/<name>.prompt.php, a prompt template (kebab-case names, for example summarise-article).
make:mcp <Name> app/Controllers/<Name>McpController.php with stub tools, a resource and a prompt to fill in, plus app/Controllers/AppMcpController.php the first time. -d, --from-datastore=PostDataStore reads the DataStore's $casts, $fillable and definition and writes typed list, get, create, update and delete tools and a list resource. See MCP server.
make:dockerfile Dockerfile and docker-compose.yml for local development (PHP's built-in server on 127.0.0.1:8080, and MySQL with a random DB_PASSWORD kept in .env). It stops when either file exists. See Deployment.

Routes

#
Command What it does
route:list Prints the routes the router serves: the all: section, the method sections (GET:, POST: and so on), route groups, the routes added from PHP and by packages (Routing), and named routes.
route:openapi Writes an OpenAPI 3.0 description of the routes from the @Api* annotations on controller methods and the rules of their FormRequests. -o, --output (default docs/openapi.yaml), -f, --format (yaml or json), --title. See REST APIs.

URLs of the form /controller/action work without a route; see Routing.

Cache and optimisation

#
Command What it does
cache:clear Empties the application cache and the compiled config and translation files in app/tmp/config_cache/ and app/tmp/lang_cache/ (it leaves tphr_frozen.php). -t, --tag=<tag> clears only the entries with that tag when the cache backend supports tags.
optimize Compiles the config files and routes of the current APP_ENV into app/tmp/tphr_frozen.php, writes app/tmp/config.cache.php, app/tmp/routes.cache.php and the files in app/tmp/config_cache/, and writes app/tmp/preload.php for OPcache preloading. Run it on every deploy, with the production APP_ENV.
optimize:clear (aliases config:cache:clear, route:cache:clear) Deletes what optimize wrote, except preload.php, and the config cache entries in the application cache.

How these fit into a deploy is in Deployment.

Queues and the scheduler

#
Command What it does
queue:work [queue] Processes jobs until it is stopped. The queue defaults to app.queue.defaultQueue, else default. --connection (a connection from queue.yml, default default), --sleep (seconds to wait when the queue is empty, default 3), --tries (attempts before a job fails, default 3), --concurrency (worker processes, default 1; needs ext-pcntl). With ext-pcntl, SIGTERM and SIGINT let the current job finish before the worker exits.
queue:listen [queue] Processes jobs and restarts when the code changes. For development. --sleep as above.
queue:failed A placeholder in 1.0: it prints a reminder. Failed jobs are logged and dropped after the last retry (see Queues).
schedule:run Runs the scheduled tasks that are due. Call it from cron every minute.
schedule:list Lists the scheduled tasks and when each runs next.

Tasks are defined in app/Console/Kernel.php. See Queues and Scheduler; running workers and cron in production is in Deployment.

Debugging

#
Command What it does
debug:request Prints the last request recorded in app/tmp/Log/requests.log: method, URI, status, time and headers. -t, --tail=5 shows the last five, -w, --watch follows new ones as they arrive, -l, --log-file reads another file. Requests are only recorded outside production and with logging.log_requests: true in app.yml.

See Logging.

Localisation

#
Command What it does
lang:scan [locale] Scans the source for translation keys and reports the keys missing from the catalogue of [locale] (default: app.locale). --orphans also lists keys in the catalogue that no source file uses; -p, --path scans another folder than app/.

See Localisation.

MCP

#
Command What it does
mcp:serve Starts the MCP server over stdio, for desktop apps, IDEs and other MCP clients that start the server as a process. It finds every MCP controller in app/Controllers. --list prints the tools, resources and prompts it would serve, then exits.

See MCP server.

AI builder

#

The AI builder is a preview feature: it works, and its behaviour may still change in minor releases.

Command What it does
ai:build [description] Builds or extends the app from a description. -p, --provider (anthropic, openai or ollama), -m, --model, --continue (resume the last session), --port (the port shown in the test URL at the end, default 8080).
ai:fix [error] Diagnoses an error message or stack trace and proposes a fix. Reads the error from standard input when none is given. -p, --provider, -m, --model.
ai:rollback [id] Undoes a build session from its receipt (default: the latest). -l, --list lists the receipts, -y, --yes skips the confirmation, -f, --force also restores or deletes files edited after the build.

Both ai:build and ai:fix ask before every file change and before every command outside a fixed allow-list. --dontaskforpermissions applies them without asking and prints a warning; blocked commands stay blocked. See AI builder.

Your own commands

#

php taphra make:console SendReport writes app/Console/SendReportCommand.php. Every class in app/Console/ that extends Taphra\Console\Command is registered when the command line starts. Name the command with Symfony's #[AsCommand] attribute, declare arguments and options in configure(), and put the work in handle(), which returns the exit code:

PHP
// app/Console/GreetCommand.php
namespace App\Console;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Taphra\Console\Command;

#[AsCommand(name: 'app:greet', description: 'Greet someone')]
class GreetCommand extends Command
{
    protected function configure(): void
    {
        $this->addArgument('name', InputArgument::REQUIRED, 'Who to greet')
             ->addOption('shout', null, InputOption::VALUE_NONE, 'Upper-case the greeting');
    }

    protected function handle(): int
    {
        $greeting = 'Hello, ' . $this->input->getArgument('name');
        if ($this->input->getOption('shout')) {
            $greeting = strtoupper($greeting);
        }
        $this->info($greeting);

        return 0;
    }
}
Shell
php taphra app:greet Ada            # Hello, Ada
php taphra app:greet Ada --shout    # HELLO, ADA

Besides $this->input and $this->output, the base class has line(), info(), comment() and error() for output, and ask() and confirm() for questions.

Maintainer commands

#

upgrade:check and upgrade:prep come from taphra/dev, the development tooling of the framework repository. They read and write the upgrade notes in the repository's docs/upgrade/ folder, so they are for work on the framework itself, not for apps. To see what changed between versions, read the upgrade notes and the changelog: see Upgrading.