1212use Doctrine \RST \Meta \Metas ;
1313use Symfony \CodeBlockChecker \Listener \CodeNodeCollector ;
1414use Symfony \CodeBlockChecker \Service \Baseline ;
15+ use Symfony \CodeBlockChecker \Service \CodeNodeRunner ;
1516use Symfony \CodeBlockChecker \Service \CodeValidator ;
1617use Symfony \Component \Console \Command \Command ;
1718use Symfony \Component \Console \Input \InputArgument ;
@@ -32,20 +33,23 @@ class CheckDocsCommand extends Command
3233 private CodeNodeCollector $ collector ;
3334 private CodeValidator $ validator ;
3435 private Baseline $ baseline ;
36+ private CodeNodeRunner $ codeNodeRunner ;
3537
36- public function __construct (CodeValidator $ validator , Baseline $ baseline )
38+ public function __construct (CodeValidator $ validator , Baseline $ baseline, CodeNodeRunner $ codeNodeRunner )
3739 {
3840 parent ::__construct (self ::$ defaultName );
3941 $ this ->validator = $ validator ;
4042 $ this ->baseline = $ baseline ;
43+ $ this ->codeNodeRunner = $ codeNodeRunner ;
4144 }
4245
4346 protected function configure ()
4447 {
4548 $ this
4649 ->addArgument ('source-dir ' , InputArgument::REQUIRED , 'RST files Source directory ' )
4750 ->addArgument ('files ' , InputArgument::IS_ARRAY , 'RST files that should be verified. ' , [])
48- ->addOption ('output-format ' , null , InputOption::VALUE_REQUIRED , 'Valid options are github and console ' , 'github ' )
51+ ->addOption ('output-format ' , null , InputOption::VALUE_REQUIRED , 'Valid options are "github" and "console" ' , 'console ' )
52+ ->addOption ('symfony-application ' , null , InputOption::VALUE_REQUIRED , 'Path to a symfony application to test the code blocks ' , false )
4953 ->addOption ('generate-baseline ' , null , InputOption::VALUE_REQUIRED , 'Generate a new baseline ' , false )
5054 ->addOption ('baseline ' , null , InputOption::VALUE_REQUIRED , 'Use a baseline ' , false )
5155 ->setDescription ('Make sure the docs blocks are valid ' )
@@ -93,7 +97,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9397
9498 // This will collect all CodeNodes
9599 $ this ->queueProcessor ->process ($ parseQueue );
100+ // Verify code blocks
96101 $ issues = $ this ->validator ->validateNodes ($ this ->collector ->getNodes ());
102+ if ($ applicationDir = $ input ->getOption ('symfony-application ' )) {
103+ $ issues ->append ($ this ->codeNodeRunner ->runNodes ($ this ->collector ->getNodes (), $ applicationDir ));
104+ }
97105
98106 if ($ baselineFile = $ input ->getOption ('generate-baseline ' )) {
99107 $ this ->baseline ->generate ($ issues , $ baselineFile );
@@ -102,7 +110,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102110 }
103111
104112 if ($ baselineFile = $ input ->getOption ('baseline ' )) {
105- $ issues = $ this ->baseline ->filter ($ issues , $ baselineFile );
113+ $ json = file_get_contents ($ baselineFile );
114+ try {
115+ $ baseline = json_decode ($ json , true , 512 , JSON_THROW_ON_ERROR );
116+ } catch (\JsonException $ e ) {
117+ throw new \RuntimeException ('Could not parse baseline ' , 0 , $ e );
118+ }
119+ $ issues = $ this ->baseline ->filter ($ issues , $ baseline );
106120 }
107121
108122 $ issueCount = count ($ issues );
0 commit comments