CodeSampleX

샘플

symfony/console 8.1.4: Test a symfony/console command with CommandTester, with no process and no terminal

검증된 샘플 — composer symfony/console 8.1.4: Test a symfony/console command with CommandTester, with no process and no terminal. php 8 · linux alpine/x64 …

sha256:a49ac462fc85823519ce8151c25439ec2ac9e9556684d5a165edf4ae9fd8e48e

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 php 8 linux x64 php 8 php composer

검증 실행 환경

환경 컨트랙트 단계 실행일
php 8 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · composer@1
2026-08-14
php 8 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · composer@1
2026-08-18

케이스

HOW
목표
Test a symfony/console command with CommandTester, with no process and no terminal
패키지
심벌
  • Symfony.Component.Console.Tester.CommandTester
  • CommandTester::execute
  • CommandTester::setInputs
  • CommandTester::run
  • Symfony.Component.Console.Tester.ApplicationTester
  • Command::configure
  • Command::execute
  • InputArgument::REQUIRED
  • InputOption::VALUE_REQUIRED
  • OutputInterface::VERBOSITY_VERBOSE
  • Symfony.Component.Console.Question.Question
환경
php 8
생성일
2026-08-14T14:11:03Z

컨트랙트

  1. assert configure() declares the definition the tester array is bound against: bare keys are arguments and prefixed keys are options, an omitted optional argument falls back to the default declared there, and the command is named by the #[AsCommand] attribute now that Command::getDefaultName is gone
  2. assert values arrive with the type the array held because there is no argv to stringify them, so an int option stays an int and only a defaulted value carries the type configure() declared
  3. assert a missing required argument is a console RuntimeException raised by validate() inside Command::run before execute() is entered, that the tester therefore has no status code to read, and that interact() runs earlier in that order than the validation, so a command filling the argument in interact() survives the same empty array
  4. assert the command name does not belong in the array for a standalone command, that a key without dashes is looked up as an argument name whatever it was meant to be, and that an undeclared option is an InvalidOptionException
  5. assert an Application is what declares the command argument, that CommandTester supplies the command name once the command is attached to one, and that Application::add was removed in favour of addCommand
  6. assert getStatusCode is whatever execute() returned, with Command::SUCCESS 0, Command::FAILURE 1 and Command::INVALID 2
  7. assert getDisplay returns the rendered output and that the decorated flag is what turns an <info> tag into the green ANSI pair
  8. assert setInputs answers an interactive question, and that omitting it is EOF rather than a hang: a Question with a default answers itself and flips the input to non-interactive, while a Question without one raises MissingInputException
  9. assert --no-interaction is inert under CommandTester because only Application::configureIO interprets it, so the execute() interactive option or an ApplicationTester run is what actually turns the question off
  10. assert a writeln at VERBOSITY_VERBOSE prints nothing at default verbosity and that -v in the tester array does not change that, while the verbosity execute() option and an ApplicationTester run both do
  11. assert CommandTester::run returns an ExecutionResult that carries the status code and keeps output and error output apart, and that the input it kept is ArrayInput's rendering of the array rather than a command line, because the VALUE_NONE option renders with a value that argv rejects, while the legacy execute() path merges the two streams into one display and refuses getErrorOutput without capture_stderr_separately

파일

  • composer.json
  • composer.lock
  • csx.json
  • phpunit.xml
  • src/AskNameCommand.php
  • src/ConsoleApp.php
  • src/GreetCommand.php
  • test/CommandTesterTest.php

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

anonymous