|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\Cli\CampaignConfigValidation; |
|
6
|
|
|
|
|
7
|
|
|
use FileFetcher\SimpleFileFetcher; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\CampaignCollection; |
|
14
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\Validation\CampaignErrorCollection; |
|
15
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\Validation\CampaignUtilizationValidator; |
|
16
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\Validation\FeatureToggleParser; |
|
17
|
|
|
use WMDE\Fundraising\Frontend\Factories\FunFunFactory; |
|
18
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\ConfigReader; |
|
19
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\EnvironmentBootstrapper; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @license GPL-2.0-or-later |
|
23
|
|
|
*/ |
|
24
|
|
|
class ValidateCampaignCodeUtilizationCommand extends Command { |
|
25
|
|
|
|
|
26
|
|
|
private const NAME = 'app:validate:campaigns:utilization'; |
|
27
|
|
|
private const RETURN_CODE_OK = 0; |
|
28
|
|
|
private const RETURN_CODE_ERROR = 1; |
|
29
|
|
|
|
|
30
|
|
|
/** @see \WMDE\Fundraising\Frontend\Factories\ChoiceFactory */ |
|
31
|
|
|
private const CHOICE_FACTORY_LOCATION = 'src/Factories/ChoiceFactory.php'; |
|
32
|
|
|
|
|
33
|
|
|
protected function configure(): void { |
|
34
|
|
|
$this->setName( self::NAME ) |
|
35
|
|
|
->setDescription( 'Validate campaign configuration utilization in source code' ) |
|
36
|
|
|
->setHelp( |
|
37
|
|
|
'This command validates that all campaign configurations are related to a specific entry point in the code' |
|
38
|
|
|
) |
|
39
|
|
|
->setDefinition( |
|
40
|
|
|
new InputDefinition( |
|
41
|
|
|
[ |
|
42
|
|
|
new InputArgument( |
|
43
|
|
|
'environment', |
|
44
|
|
|
InputArgument::OPTIONAL, |
|
45
|
|
|
'Specify a specific campaign environment which is to be tested', |
|
46
|
|
|
'prod' |
|
47
|
|
|
) |
|
48
|
|
|
] |
|
49
|
|
|
) |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function execute( InputInterface $input, OutputInterface $output ): int { |
|
54
|
|
|
$errorLogger = new CampaignErrorCollection(); |
|
55
|
|
|
$validator = new CampaignUtilizationValidator( |
|
56
|
|
|
$this->getCampaigns( $input->getArgument( 'environment' ) ), |
|
|
|
|
|
|
57
|
|
|
[ 'campaigns.skins.test' ], |
|
58
|
|
|
FeatureToggleParser::getFeatureToggleChecks( self::CHOICE_FACTORY_LOCATION ), |
|
59
|
|
|
$errorLogger |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
if ( $validator->isPassing() ) { |
|
63
|
|
|
return self::RETURN_CODE_OK; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
foreach ( $errorLogger->getErrors() as $error ) { |
|
67
|
|
|
$output->writeln( $error ); |
|
68
|
|
|
} |
|
69
|
|
|
$output->writeln( 'Campaign utilization validation failed.' ); |
|
70
|
|
|
return self::RETURN_CODE_ERROR; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function getCampaigns( string $environment ): CampaignCollection { |
|
74
|
|
|
$bootstrapper = new EnvironmentBootstrapper( $environment ); |
|
75
|
|
|
$factory = $bootstrapper->newFunFunFactory(); |
|
76
|
|
|
return $factory->getCampaignCollection(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|