1212use Symfony \Component \Console \Style \SymfonyStyle ;
1313use Testo \Application ;
1414use Testo \Common \Container ;
15- use Testo \Config \ApplicationConfig ;
16- use Testo \Config \FinderConfig ;
17- use Testo \Config \SuiteConfig ;
15+ use Testo \Common \Path ;
1816use Yiisoft \Injector \Injector ;
1917
2018/**
@@ -72,17 +70,12 @@ protected function execute(
7270 InputInterface $ input ,
7371 OutputInterface $ output ,
7472 ): int {
75- $ cfg = new ApplicationConfig (
76- src: new FinderConfig (['src ' ]),
77- suites: [
78- new SuiteConfig (
79- name: 'default ' ,
80- location: new FinderConfig (['tests/Testo ' ]),
81- ),
82- ],
73+ $ this ->application = Application::createFromInput (
74+ configFile: $ this ->getConfigFile ($ input ),
75+ inputOptions: $ input ->getOptions (),
76+ inputArguments: $ input ->getArguments (),
77+ environment: \getenv (),
8378 );
84-
85- $ this ->application = Application::createFromConfig ($ cfg );
8679 $ this ->container = $ this ->application ->getContainer ();
8780
8881 $ this ->container ->set ($ input , InputInterface::class);
@@ -91,4 +84,30 @@ protected function execute(
9184
9285 return $ this ->container ->get (Injector::class)->invoke ($ this ) ?? Command::SUCCESS ;
9386 }
87+
88+ /**
89+ * Resolves configuration file path from input or default location.
90+ *
91+ * @param InputInterface $input Command input
92+ *
93+ * @return Path|null Path to the configuration file
94+ */
95+ protected function getConfigFile (InputInterface $ input ): ?Path
96+ {
97+ /** @var string|null $config */
98+ $ config = $ input ->getOption ('config ' );
99+ $ isConfigured = $ config !== null ;
100+ // $config ??= './testo.xml';
101+ $ config ??= './testo.php ' ;
102+
103+ if (\is_file ($ config )) {
104+ return Path::create ($ config );
105+ }
106+
107+ $ isConfigured and throw new \InvalidArgumentException (
108+ 'Configuration file not found: ' . $ config ,
109+ );
110+
111+ return null ;
112+ }
94113}
0 commit comments