Best Mockery code snippet using must.setConstantsMap
CloudStacksTest.php
Source:CloudStacksTest.php
...31 ->assertExitCode(0);32 }33 public function testCreate()34 {35 Mockery::getConfiguration()->setConstantsMap([36 AcmClient::class => [37 'VALIDATION_METHOD_DNS' => 'DNS',38 ],39 CloudFormationClient::class => [40 'STACK_STATUS_CREATE_COMPLETE' => 'CREATE_COMPLETE',41 'STACK_STATUS_UPDATE_COMPLETE' => 'UPDATE_COMPLETE',42 ]43 ]);44 $this->createMockCloudformationTemplate();45 $this->createGitHead('main');46 $this->createValidLaraSurfConfig('local-stage-production');47 $this->createGitCurrentCommit('main', Str::random());48 $ecr = $this->mockLaraSurfEcrClient();49 $ecr->shouldReceive('imageTagExists')->twice()->andReturn(true);50 $ecr->shouldReceive('repositoryUri')->twice()->andReturn($this->faker->url);51 $cloudformation = $this->mockLaraSurfCloudFormationClient();52 $cloudformation->shouldReceive('templatePath')->once()->andReturn(base_path('.cloudformation/infrastructure.yml'));53 $cloudformation->shouldReceive('stackStatus')->once()->andReturn(false);54 $cloudformation->shouldReceive('createStack')->once()->andReturn();55 $cloudformation->shouldReceive('waitForStackInfoPanel')->twice()->andReturn([56 'success' => true,57 'status' => 'CREATE_COMPLETE',58 ], [59 'success' => true,60 'status' => 'CREATE_COMPLETE',61 ]);62 $cloudformation->shouldReceive('stackOutput')->twice()->andReturn([63 'DomainName' => $this->faker->domainName,64 'DBHost' => $this->faker->domainName,65 'DBPort' => $this->faker->numerify('####'),66 'DBAdminAccessPrefixListId' => Str::random(),67 'AppAccessPrefixListId' => Str::random(),68 'CacheEndpointAddress' => $this->faker->url,69 'CacheEndpointPort' => $this->faker->numerify('####'),70 'QueueUrl' => $this->faker->url,71 'BucketName' => $this->faker->word,72 'DBSecurityGroupId' => Str::random(),73 'ContainersSecurityGroupId' => Str::random(),74 'CacheSecurityGroupId' => Str::random(),75 'ArtisanTaskDefinitionArn' => Str::random(),76 'Subnet1Id' => Str::random(),77 ], [78 'ArtisanTaskDefinitionArn' => Str::random(),79 'ContainerClusterArn' => Str::random(),80 ]);81 $cloudformation->shouldReceive('updateStack')->once()->andReturn();82 $existing_parameters = [83 $this->faker->word,84 $this->faker->word,85 ];86 $domain = $this->faker->domainName;87 $ssm = $this->mockLaraSurfSsmClient();88 $ssm->shouldReceive('listParameters')->once()->andReturn($existing_parameters);89 $ssm->shouldReceive('deleteParameter')->twice()->andReturn();90 $ssm->shouldReceive('putParameter')->times(19)->andReturn();91 $ssm->shouldReceive('listParameterArns')->once()->andReturn([92 'APP_ENV' => 'production',93 'APP_KEY' => 'base64:' . base64_encode(Str::random()),94 'APP_URL' => "https://$domain",95 'CACHE_DRIVER' => 'redis',96 'DB_CONNECTION' => 'mysql',97 'DB_HOST' => $this->faker->domainName,98 'DB_PORT' => $this->faker->numerify('####'),99 'DB_DATABASE' => $this->faker->word,100 'DB_USERNAME' => Str::random(),101 'DB_PASSWORD' => Str::random(),102 'LOG_CHANNEL' => 'errorlog',103 'QUEUE_CONNECTION' => 'sqs',104 'MAIL_MAILER' => 'ses',105 'AWS_DEFAULT_REGION' => 'us-east-1',106 'REDIS_HOST' => $this->faker->url,107 'REDIS_PORT' => $this->faker->numerify('####'),108 'SESSION_DRIVER' => 'redis',109 'SQS_QUEUE' => $this->faker->url,110 'AWS_BUCKET' => $this->faker->word,111 ]);112 $hosted_zone_id = Str::random();113 $route53 = $this->mockLaraSurfRoute53Client();114 $route53->shouldReceive('hostedZoneIdFromRootDomain')->once()->andReturn($hosted_zone_id);115 $route53->shouldReceive('upsertDnsRecords')->once()->andReturn(Str::random());116 $route53->shouldReceive('waitForChange')->once()->andReturn();117 $acm = $this->mockLaraSurfAcmClient();118 $acm->shouldReceive('requestCertificate')->once()->andReturn([119 'dns_record' => (new DnsRecord())120 ->setType(DnsRecord::TYPE_CNAME)121 ->setValue(Str::random())122 ->setName(Str::random())123 ->setTtl(random_int(100, 1000)),124 'certificate_arn' => Str::random(),125 ]);126 $acm->shouldReceive('waitForPendingValidation')->once()->andReturn();127 $ec2 = $this->mockLaraSurfEc2Client();128 $ec2->shouldReceive('createPrefixList')->twice()->andReturn(Str::random());129 $database_name = $this->faker->word;130 $this->mock(SchemaCreator::class, function (Mockery\MockInterface $mock) use ($database_name) {131 $mock->shouldReceive('createSchema')->once()->andReturn($database_name);132 });133 $ecs = $this->mockLaraSurfEcsClient();134 $ecs->shouldReceive('runTask')->once()->andReturn(Str::random());135 $ecs->shouldReceive('waitForTaskFinish')->once()->andReturn();136 $this->artisan('larasurf:cloud-stacks create --environment production')137 ->expectsOutput('Checking if application and webserver images exist...')138 ->expectsOutput('Checking if stack exists...')139 ->expectsOutput("The following variables exist for the 'production' environment:")140 ->expectsOutput(implode(PHP_EOL, $existing_parameters))141 ->expectsQuestion('Are you sure you\'d like to delete these variables?', true)142 ->expectsOutput('Deleting cloud variables...')143 ->expectsQuestion('Database instance type?', 'db.t2.small')144 ->expectsOutput('Minimum database storage (GB): 20')145 ->expectsOutput('Maximum database storage (GB): 70368')146 ->expectsQuestion('Database storage (GB)?', '25')147 ->expectsQuestion('Cache node type?', 'cache.t2.micro')148 ->expectsQuestion('Task definition CPU?', '256')149 ->expectsQuestion('Task definition memory?', '512')150 ->expectsQuestion('Auto Scaling min number of Tasks?', '5')151 ->expectsQuestion('Auto Scaling max number of Tasks?', '15')152 ->expectsQuestion('Auto Scaling target CPU percent?', '50')153 ->expectsQuestion('Auto Scaling scale out cooldown (seconds)?', '10')154 ->expectsQuestion('Auto Scaling scale in cooldown (seconds)?', '10')155 ->expectsQuestion('Number of Queue Worker Tasks?', '3')156 ->expectsQuestion('Fully qualified domain name?', $domain)157 ->expectsOutput('Finding hosted zone from domain...')158 ->expectsOutput("Hosted zone found with ID: $hosted_zone_id")159 ->expectsQuestion('Is there a preexisting ACM certificate you\'d like to use?', false)160 ->expectsOutput('Creating ACM certificate...')161 ->expectsOutput('Verifying ACM certificate via DNS record...')162 ->expectsOutput("Verified ACM certificate for domain '$domain' successfully")163 ->expectsOutput('Creating prefix lists...')164 ->expectsOutput('Created database prefix list successfully')165 ->expectsOutput('Created application prefix list successfully')166 ->expectsOutput("Creating stack for 'production' environment...")167 ->expectsOutput('Stack creation completed successfully')168 ->expectsOutput('Creating database schema...')169 ->expectsOutput("Created database schema '$database_name' successfully")170 ->expectsOutput('Creating cloud variables...')171 ->expectsOutput('Successfully created cloud variable: APP_ENV')172 ->expectsOutput('Successfully created cloud variable: APP_KEY')173 ->expectsOutput('Successfully created cloud variable: APP_URL')174 ->expectsOutput('Successfully created cloud variable: CACHE_DRIVER')175 ->expectsOutput('Successfully created cloud variable: DB_CONNECTION')176 ->expectsOutput('Successfully created cloud variable: DB_HOST')177 ->expectsOutput('Successfully created cloud variable: DB_PORT')178 ->expectsOutput('Successfully created cloud variable: DB_DATABASE')179 ->expectsOutput('Successfully created cloud variable: DB_USERNAME')180 ->expectsOutput('Successfully created cloud variable: DB_PASSWORD')181 ->expectsOutput('Successfully created cloud variable: LOG_CHANNEL')182 ->expectsOutput('Successfully created cloud variable: QUEUE_CONNECTION')183 ->expectsOutput('Successfully created cloud variable: MAIL_MAILER')184 ->expectsOutput('Successfully created cloud variable: AWS_DEFAULT_REGION')185 ->expectsOutput('Successfully created cloud variable: REDIS_HOST')186 ->expectsOutput('Successfully created cloud variable: REDIS_PORT')187 ->expectsOutput('Successfully created cloud variable: SESSION_DRIVER')188 ->expectsOutput('Successfully created cloud variable: SQS_QUEUE')189 ->expectsOutput('Successfully created cloud variable: AWS_BUCKET')190 ->expectsOutput('Waiting to list cloud variables...')191 ->expectsOutput('Updating stack with cloud variables...')192 ->expectsOutput('Stack update completed successfully')193 ->expectsOutput('Starting ECS task to run migrations...')194 ->expectsOutput('Started ECS task to run migrations successfully')195 ->expectsOutput("Visit https://$domain to see your application")196 ->assertExitCode(0);197 }198 public function testCreateExistingCertificate()199 {200 Mockery::getConfiguration()->setConstantsMap([201 AcmClient::class => [202 'VALIDATION_METHOD_DNS' => 'DNS',203 ],204 CloudFormationClient::class => [205 'STACK_STATUS_CREATE_COMPLETE' => 'CREATE_COMPLETE',206 'STACK_STATUS_UPDATE_COMPLETE' => 'UPDATE_COMPLETE',207 ]208 ]);209 $this->createMockCloudformationTemplate();210 $this->createGitHead('main');211 $this->createValidLaraSurfConfig('local-stage-production');212 $this->createGitCurrentCommit('main', Str::random());213 $ecr = $this->mockLaraSurfEcrClient();214 $ecr->shouldReceive('imageTagExists')->twice()->andReturn(true);215 $ecr->shouldReceive('repositoryUri')->twice()->andReturn($this->faker->url);216 $cloudformation = $this->mockLaraSurfCloudFormationClient();217 $cloudformation->shouldReceive('templatePath')->once()->andReturn(base_path('.cloudformation/infrastructure.yml'));218 $cloudformation->shouldReceive('stackStatus')->once()->andReturn(false);219 $cloudformation->shouldReceive('createStack')->once()->andReturn();220 $cloudformation->shouldReceive('waitForStackInfoPanel')->twice()->andReturn([221 'success' => true,222 'status' => 'CREATE_COMPLETE',223 ], [224 'success' => true,225 'status' => 'CREATE_COMPLETE',226 ]);227 $cloudformation->shouldReceive('stackOutput')->twice()->andReturn([228 'DomainName' => $this->faker->domainName,229 'DBHost' => $this->faker->domainName,230 'DBPort' => $this->faker->numerify('####'),231 'DBAdminAccessPrefixListId' => Str::random(),232 'AppAccessPrefixListId' => Str::random(),233 'CacheEndpointAddress' => $this->faker->url,234 'CacheEndpointPort' => $this->faker->numerify('####'),235 'QueueUrl' => $this->faker->url,236 'BucketName' => $this->faker->word,237 'DBSecurityGroupId' => Str::random(),238 'ContainersSecurityGroupId' => Str::random(),239 'CacheSecurityGroupId' => Str::random(),240 'ArtisanTaskDefinitionArn' => Str::random(),241 'Subnet1Id' => Str::random(),242 ], [243 'ArtisanTaskDefinitionArn' => Str::random(),244 'ContainerClusterArn' => Str::random(),245 ]);246 $cloudformation->shouldReceive('updateStack')->once()->andReturn();247 $existing_parameters = [248 $this->faker->word,249 $this->faker->word,250 ];251 $domain = $this->faker->domainName;252 $ssm = $this->mockLaraSurfSsmClient();253 $ssm->shouldReceive('listParameters')->once()->andReturn($existing_parameters);254 $ssm->shouldReceive('deleteParameter')->twice()->andReturn();255 $ssm->shouldReceive('putParameter')->times(19)->andReturn();256 $ssm->shouldReceive('listParameterArns')->once()->andReturn([257 'APP_ENV' => 'production',258 'APP_KEY' => 'base64:' . base64_encode(Str::random()),259 'APP_URL' => "https://$domain",260 'CACHE_DRIVER' => 'redis',261 'DB_CONNECTION' => 'mysql',262 'DB_HOST' => $this->faker->domainName,263 'DB_PORT' => $this->faker->numerify('####'),264 'DB_DATABASE' => $this->faker->word,265 'DB_USERNAME' => Str::random(),266 'DB_PASSWORD' => Str::random(),267 'LOG_CHANNEL' => 'errorlog',268 'QUEUE_CONNECTION' => 'sqs',269 'MAIL_MAILER' => 'ses',270 'AWS_DEFAULT_REGION' => 'us-east-1',271 'REDIS_HOST' => $this->faker->url,272 'REDIS_PORT' => $this->faker->numerify('####'),273 'SESSION_DRIVER' => 'redis',274 'SQS_QUEUE' => $this->faker->url,275 'AWS_BUCKET' => $this->faker->word,276 ]);277 $hosted_zone_id = Str::random();278 $route53 = $this->mockLaraSurfRoute53Client();279 $route53->shouldReceive('hostedZoneIdFromRootDomain')->once()->andReturn($hosted_zone_id);280 $ec2 = $this->mockLaraSurfEc2Client();281 $ec2->shouldReceive('createPrefixList')->twice()->andReturn(Str::random());282 $database_name = $this->faker->word;283 $this->mock(SchemaCreator::class, function (Mockery\MockInterface $mock) use ($database_name) {284 $mock->shouldReceive('createSchema')->once()->andReturn($database_name);285 });286 $ecs = $this->mockLaraSurfEcsClient();287 $ecs->shouldReceive('runTask')->once()->andReturn(Str::random());288 $ecs->shouldReceive('waitForTaskFinish')->once()->andReturn();289 $this->artisan('larasurf:cloud-stacks create --environment production')290 ->expectsOutput('Checking if application and webserver images exist...')291 ->expectsOutput('Checking if stack exists...')292 ->expectsOutput("The following variables exist for the 'production' environment:")293 ->expectsOutput(implode(PHP_EOL, $existing_parameters))294 ->expectsQuestion('Are you sure you\'d like to delete these variables?', true)295 ->expectsOutput('Deleting cloud variables...')296 ->expectsQuestion('Database instance type?', 'db.t2.small')297 ->expectsOutput('Minimum database storage (GB): 20')298 ->expectsOutput('Maximum database storage (GB): 70368')299 ->expectsQuestion('Database storage (GB)?', '25')300 ->expectsQuestion('Cache node type?', 'cache.t2.micro')301 ->expectsQuestion('Task definition CPU?', '256')302 ->expectsQuestion('Task definition memory?', '512')303 ->expectsQuestion('Auto Scaling min number of Tasks?', '5')304 ->expectsQuestion('Auto Scaling max number of Tasks?', '15')305 ->expectsQuestion('Auto Scaling target CPU percent?', '50')306 ->expectsQuestion('Auto Scaling scale out cooldown (seconds)?', '10')307 ->expectsQuestion('Auto Scaling scale in cooldown (seconds)?', '10')308 ->expectsQuestion('Number of Queue Worker Tasks?', '3')309 ->expectsQuestion('Fully qualified domain name?', $domain)310 ->expectsOutput('Finding hosted zone from domain...')311 ->expectsOutput("Hosted zone found with ID: $hosted_zone_id")312 ->expectsQuestion('Is there a preexisting ACM certificate you\'d like to use?', true)313 ->expectsQuestion('ACM certificate ARN?', 'arn:aws:acm:us-east-1:certificate/' . Str::random())314 ->expectsOutput('Creating prefix lists...')315 ->expectsOutput('Created database prefix list successfully')316 ->expectsOutput('Created application prefix list successfully')317 ->expectsOutput("Creating stack for 'production' environment...")318 ->expectsOutput('Stack creation completed successfully')319 ->expectsOutput('Creating database schema...')320 ->expectsOutput("Created database schema '$database_name' successfully")321 ->expectsOutput('Creating cloud variables...')322 ->expectsOutput('Successfully created cloud variable: APP_ENV')323 ->expectsOutput('Successfully created cloud variable: APP_KEY')324 ->expectsOutput('Successfully created cloud variable: APP_URL')325 ->expectsOutput('Successfully created cloud variable: CACHE_DRIVER')326 ->expectsOutput('Successfully created cloud variable: DB_CONNECTION')327 ->expectsOutput('Successfully created cloud variable: DB_HOST')328 ->expectsOutput('Successfully created cloud variable: DB_PORT')329 ->expectsOutput('Successfully created cloud variable: DB_DATABASE')330 ->expectsOutput('Successfully created cloud variable: DB_USERNAME')331 ->expectsOutput('Successfully created cloud variable: DB_PASSWORD')332 ->expectsOutput('Successfully created cloud variable: LOG_CHANNEL')333 ->expectsOutput('Successfully created cloud variable: QUEUE_CONNECTION')334 ->expectsOutput('Successfully created cloud variable: MAIL_MAILER')335 ->expectsOutput('Successfully created cloud variable: AWS_DEFAULT_REGION')336 ->expectsOutput('Successfully created cloud variable: REDIS_HOST')337 ->expectsOutput('Successfully created cloud variable: REDIS_PORT')338 ->expectsOutput('Successfully created cloud variable: SQS_QUEUE')339 ->expectsOutput('Successfully created cloud variable: AWS_BUCKET')340 ->expectsOutput('Waiting to list cloud variables...')341 ->expectsOutput('Updating stack with cloud variables...')342 ->expectsOutput('Stack update completed successfully')343 ->expectsOutput('Starting ECS task to run migrations...')344 ->expectsOutput('Started ECS task to run migrations successfully')345 ->expectsOutput("Visit https://$domain to see your application")346 ->assertExitCode(0);347 }348 public function testCreateNotOnCorrectBranch()349 {350 $this->createGitHead('stage');351 $this->artisan('larasurf:cloud-stacks create --environment production')352 ->expectsOutput('Must be on the \'main\' branch to create a stack for this environment')353 ->assertExitCode(1);354 }355 public function testCreateNoCurrentCommit()356 {357 $this->createMockCloudformationTemplate();358 if (File::isDirectory(base_path('.git/refs/heads'))) {359 File::deleteDirectory(base_path('.git/refs/heads'));360 }361 $this->createGitHead('main');362 $this->createValidLaraSurfConfig('local-stage-production');363 $this->mockAwsCloudFormationClient();364 $this->artisan('larasurf:cloud-stacks create --environment production')365 ->expectsOutput('Failed to find current commit, is this a git repository?')366 ->assertExitCode(1);367 }368 public function testCreateImageDoesntExist()369 {370 $this->createMockCloudformationTemplate();371 $current_commit = Str::random();372 $this->createGitHead('main');373 $this->createValidLaraSurfConfig('local-stage-production');374 $this->createGitCurrentCommit('main', $current_commit);375 $ecr = $this->mockLaraSurfEcrClient();376 $ecr->shouldReceive('imageTagExists')->once()->andReturn(false);377 $image_tag = 'commit-' . $current_commit;378 $application_repo_name = "{$this->project_name}-{$this->project_id}/production/application";379 $cloudformation = $this->mockLaraSurfCloudFormationClient();380 $cloudformation->shouldReceive('templatePath')->once()->andReturn(base_path('.cloudformation/infrastructure.yml'));381 $this->artisan('larasurf:cloud-stacks create --environment production')382 ->expectsOutput('Checking if application and webserver images exist...')383 ->expectsOutput("Failed to find tag '$image_tag' in ECR repository '$application_repo_name'")384 ->expectsOutput('Is CircleCI finished building and publishing the images?')385 ->assertExitCode(1);386 }387 public function testCreateStackExists()388 {389 $this->createMockCloudformationTemplate();390 $this->createGitHead('main');391 $this->createValidLaraSurfConfig('local-stage-production');392 $this->createGitCurrentCommit('main', Str::random());393 $ecr = $this->mockLaraSurfEcrClient();394 $ecr->shouldReceive('imageTagExists')->twice()->andReturn(true);395 $cloudformation = $this->mockLaraSurfCloudFormationClient();396 $cloudformation->shouldReceive('templatePath')->once()->andReturn(base_path('.cloudformation/infrastructure.yml'));397 $cloudformation->shouldReceive('stackStatus')->once()->andReturn('CREATE_COMPLETE');398 $this->artisan('larasurf:cloud-stacks create --environment production')399 ->expectsOutput('Checking if application and webserver images exist...')400 ->expectsOutput('Checking if stack exists...')401 ->expectsOutput('Stack already exists for \'production\' environment')402 ->assertExitCode(1);403 }404 public function testCreateHostedZoneNotFound()405 {406 $this->createMockCloudformationTemplate();407 $this->createGitHead('main');408 $this->createValidLaraSurfConfig('local-stage-production');409 $this->createGitCurrentCommit('main', Str::random());410 $ecr = $this->mockLaraSurfEcrClient();411 $ecr->shouldReceive('imageTagExists')->twice()->andReturn(true);412 $cloudformation = $this->mockLaraSurfCloudFormationClient();413 $cloudformation->shouldReceive('templatePath')->once()->andReturn(base_path('.cloudformation/infrastructure.yml'));414 $cloudformation->shouldReceive('stackStatus')->once()->andReturn(false);415 $existing_parameters = [416 $this->faker->word,417 $this->faker->word,418 ];419 $domain = $this->faker->domainName;420 $ssm = $this->mockLaraSurfSsmClient();421 $ssm->shouldReceive('listParameters')->once()->andReturn($existing_parameters);422 $ssm->shouldReceive('deleteParameter')->twice()->andReturn();423 $route53 = $this->mockLaraSurfRoute53Client();424 $route53->shouldReceive('hostedZoneIdFromRootDomain')->once()->andReturn(false);425 $this->artisan('larasurf:cloud-stacks create --environment production')426 ->expectsOutput('Checking if application and webserver images exist...')427 ->expectsOutput('Checking if stack exists...')428 ->expectsOutput("The following variables exist for the 'production' environment:")429 ->expectsOutput(implode(PHP_EOL, $existing_parameters))430 ->expectsQuestion('Are you sure you\'d like to delete these variables?', true)431 ->expectsOutput('Deleting cloud variables...')432 ->expectsQuestion('Database instance type?', 'db.t2.small')433 ->expectsOutput('Minimum database storage (GB): 20')434 ->expectsOutput('Maximum database storage (GB): 70368')435 ->expectsQuestion('Database storage (GB)?', '25')436 ->expectsQuestion('Cache node type?', 'cache.t2.micro')437 ->expectsQuestion('Task definition CPU?', '256')438 ->expectsQuestion('Task definition memory?', '512')439 ->expectsQuestion('Auto Scaling min number of Tasks?', '5')440 ->expectsQuestion('Auto Scaling max number of Tasks?', '15')441 ->expectsQuestion('Auto Scaling target CPU percent?', '50')442 ->expectsQuestion('Auto Scaling scale out cooldown (seconds)?', '10')443 ->expectsQuestion('Auto Scaling scale in cooldown (seconds)?', '10')444 ->expectsQuestion('Number of Queue Worker Tasks?', '3')445 ->expectsQuestion('Fully qualified domain name?', $domain)446 ->expectsOutput('Finding hosted zone from domain...')447 ->expectsOutput("Hosted zone for domain '$domain' could not be found")448 ->assertExitCode(1);449 }450 public function testUpdateNone()451 {452 Mockery::getConfiguration()->setConstantsMap([453 CloudFormationClient::class => [454 'STACK_STATUS_UPDATE_COMPLETE' => 'UPDATE_COMPLETE',455 ]456 ]);457 $this->createMockCloudformationTemplate();458 $cloudformation = $this->mockLaraSurfCloudFormationClient();459 $cloudformation->shouldReceive('templatePath')->once()->andReturn(base_path('.cloudformation/infrastructure.yml'));460 $cloudformation->shouldReceive('stackStatus')->once()->andReturn('CREATE_COMPLETE');461 $cloudformation->shouldReceive('updateStack')->once()->andReturn();462 $cloudformation->shouldReceive('waitForStackInfoPanel')->once()->andReturn([463 'success' => true,464 'status' => 'UPDATE_COMPLETE',465 ]);466 $ssm = $this->mockLaraSurfSsmClient();467 $ssm->shouldReceive('listParameterArns')->once()->andReturn([468 Str::random() => Str::random(),469 Str::random() => Str::random(),470 ]);471 $this->mockLaraSurfRoute53Client();472 $this->artisan('larasurf:cloud-stacks update --environment production')473 ->expectsChoice('Which options would you like to change?', ['(None)'], [474 '(None)',475 'Domain + ACM certificate ARN',476 'ACM certificate ARN',477 'Database instance type',478 'Database storage size',479 'Cache node type',480 'Task definition CPU + Memory',481 'AutoScaling Min + Max number of Tasks',482 'AutoScaling target CPU percent',483 'AutoScaling scale out cooldown',484 'AutoScaling scale in cooldown',485 'Queue Worker number of Tasks',486 ])487 ->expectsOutput('Gathering cloud variables...')488 ->expectsOutput('Updating stack...')489 ->expectsOutput('Stack update completed successfully')490 ->assertExitCode(0);491 }492 public function testUpdateAll()493 {494 Mockery::getConfiguration()->setConstantsMap([495 AcmClient::class => [496 'VALIDATION_METHOD_DNS' => 'DNS',497 ],498 CloudFormationClient::class => [499 'STACK_STATUS_UPDATE_COMPLETE' => 'UPDATE_COMPLETE',500 ]501 ]);502 $this->createMockCloudformationTemplate();503 $cloudformation = $this->mockLaraSurfCloudFormationClient();504 $cloudformation->shouldReceive('templatePath')->once()->andReturn(base_path('.cloudformation/infrastructure.yml'));505 $cloudformation->shouldReceive('stackStatus')->once()->andReturn('CREATE_COMPLETE');506 $cloudformation->shouldReceive('updateStack')->once()->andReturn();507 $cloudformation->shouldReceive('waitForStackInfoPanel')->once()->andReturn([508 'success' => true,509 'status' => 'UPDATE_COMPLETE',510 ]);511 $route53 = $this->mockLaraSurfRoute53Client();512 $route53->shouldReceive('hostedZoneIdFromRootDomain')->once()->andReturn(Str::random());513 $route53->shouldReceive('upsertDnsRecords')->once()->andReturn(Str::random());514 $route53->shouldReceive('waitForChange')->once()->andReturn();515 $acm = $this->mockLaraSurfAcmClient();516 $acm->shouldReceive('requestCertificate')->once()->andReturn([517 'dns_record' => (new DnsRecord())518 ->setType(DnsRecord::TYPE_CNAME)519 ->setValue(Str::random())520 ->setName(Str::random())521 ->setTtl(random_int(100, 1000)),522 'certificate_arn' => Str::random(),523 ]);524 $acm->shouldReceive('waitForPendingValidation')->once()->andReturn();525 $ssm = $this->mockLaraSurfSsmClient();526 $ssm->shouldReceive('listParameterArns')->once()->andReturn([527 Str::random() => Str::random(),528 Str::random() => Str::random(),529 ]);530 $domain = $this->faker->domainName;531 $this->artisan('larasurf:cloud-stacks update --environment production')532 ->expectsChoice('Which options would you like to change?', [533 'Domain + ACM certificate ARN',534 'Database instance type',535 'Database storage size',536 'Cache node type',537 'Task definition CPU + Memory',538 'AutoScaling Min + Max number of Tasks',539 'AutoScaling target CPU percent',540 'AutoScaling scale out cooldown',541 'AutoScaling scale in cooldown',542 'Queue Worker number of Tasks',543 ], [544 '(None)',545 'Domain + ACM certificate ARN',546 'ACM certificate ARN',547 'Database instance type',548 'Database storage size',549 'Cache node type',550 'Task definition CPU + Memory',551 'AutoScaling Min + Max number of Tasks',552 'AutoScaling target CPU percent',553 'AutoScaling scale out cooldown',554 'AutoScaling scale in cooldown',555 'Queue Worker number of Tasks',556 ])557 ->expectsQuestion('Fully qualified domain name?', $domain)558 ->expectsQuestion('Is there a preexisting ACM certificate you\'d like to use?', false)559 ->expectsOutput('Creating ACM certificate...')560 ->expectsOutput('Verifying ACM certificate via DNS record...')561 ->expectsOutput("Verified ACM certificate for domain '$domain' successfully")562 ->expectsQuestion('Database instance type?', 'db.t2.small')563 ->expectsOutput('Minimum database storage (GB): 20')564 ->expectsOutput('Maximum database storage (GB): 70368')565 ->expectsQuestion('Database storage (GB)?', '25')566 ->expectsQuestion('Cache node type?', 'cache.t2.micro')567 ->expectsQuestion('Task definition CPU?', '256')568 ->expectsQuestion('Task definition memory?', '512')569 ->expectsQuestion('Auto Scaling min number of Tasks?', '5')570 ->expectsQuestion('Auto Scaling max number of Tasks?', '15')571 ->expectsQuestion('Auto Scaling target CPU percent?', '50')572 ->expectsQuestion('Auto Scaling scale out cooldown (seconds)?', '10')573 ->expectsQuestion('Auto Scaling scale in cooldown (seconds)?', '10')574 ->expectsQuestion('Number of Queue Worker Tasks?', '3')575 ->expectsOutput('Gathering cloud variables...')576 ->expectsOutput('Updating stack...')577 ->expectsOutput('Stack update completed successfully')578 ->assertExitCode(0);579 }580 public function testUpdateStackDoesntExist()581 {582 $cloudformation = $this->mockLaraSurfCloudFormationClient();583 $cloudformation->shouldReceive('templatePath')->once()->andReturn(base_path('.cloudformation/infrastructure.yml'));584 $cloudformation->shouldReceive('stackStatus')->once()->andReturn(false);585 $this->artisan('larasurf:cloud-stacks update --environment production')586 ->expectsOutput("Stack does not exist for the 'production' environment")587 ->assertExitCode(1);588 }589 public function testDelete()590 {591 Mockery::getConfiguration()->setConstantsMap([592 CloudFormationClient::class => [593 'STACK_STATUS_DELETED' => 'DELETED',594 ]595 ]);596 $cloudformation = $this->mockLaraSurfCloudFormationClient();597 $cloudformation->shouldReceive('stackOutput')->once()->andReturn([598 'DBId' => Str::random(),599 'DBAdminAccessPrefixListId' => Str::random(),600 'AppAccessPrefixListId' => Str::random(),601 ]);602 $cloudformation->shouldReceive('stackStatus')->once()->andReturn('UPDATE_COMPLETE');603 $cloudformation->shouldReceive('deleteStack')->once()->andReturn();604 $cloudformation->shouldReceive('waitForStackInfoPanel')->once()->andReturn([605 'success' => true,606 'status' => 'DELETED',607 ]);608 $rds = $this->mockLaraSurfRdsClient();609 $rds->shouldReceive('checkDeletionProtection')->once()->andReturn(true);610 $rds->shouldReceive('modifyDeletionProtection')->once()->andReturn();611 $ec2 = $this->mockLaraSurfEc2Client();612 $ec2->shouldReceive('deletePrefixList')->twice()->andReturn(true);613 $this->artisan('larasurf:cloud-stacks delete --environment production')614 ->expectsConfirmation("Are you sure you want to delete the stack for the 'production' environment?", 'yes')615 ->expectsOutput('Getting stack outputs...')616 ->expectsOutput('Checking database for deletion protection...')617 ->expectsOutput("Deletion protection is enabled for the 'production' environment's database")618 ->expectsConfirmation('Would you like to disable deletion protection and proceed?', 'yes')619 ->expectsOutput('Disabling database deletion protection...')620 ->expectsOutput('Deletion protection disabled successfully')621 ->expectsOutput('Deleting prefix lists...')622 ->expectsOutput('Deleted database prefix list successfully')623 ->expectsOutput('Deleted application prefix list successfully')624 ->expectsOutput('Deleting stack...')625 ->expectsOutput('Stack deletion completed successfully')626 ->assertExitCode(0);627 }628 public function testDeleteNoDatabaseProtection()629 {630 Mockery::getConfiguration()->setConstantsMap([631 CloudFormationClient::class => [632 'STACK_STATUS_DELETED' => 'DELETED',633 ]634 ]);635 $cloudformation = $this->mockLaraSurfCloudFormationClient();636 $cloudformation->shouldReceive('stackOutput')->once()->andReturn([637 'DBId' => Str::random(),638 'DBAdminAccessPrefixListId' => Str::random(),639 'AppAccessPrefixListId' => Str::random(),640 ]);641 $cloudformation->shouldReceive('stackStatus')->once()->andReturn('UPDATE_COMPLETE');642 $cloudformation->shouldReceive('deleteStack')->once()->andReturn();643 $cloudformation->shouldReceive('waitForStackInfoPanel')->once()->andReturn([644 'success' => true,645 'status' => 'DELETED',646 ]);647 $rds = $this->mockLaraSurfRdsClient();648 $rds->shouldReceive('checkDeletionProtection')->once()->andReturn(false);649 $ec2 = $this->mockLaraSurfEc2Client();650 $ec2->shouldReceive('deletePrefixList')->twice()->andReturn(true);651 $this->artisan('larasurf:cloud-stacks delete --environment production')652 ->expectsConfirmation("Are you sure you want to delete the stack for the 'production' environment?", 'yes')653 ->expectsOutput('Getting stack outputs...')654 ->expectsOutput('Checking database for deletion protection...')655 ->expectsOutput('Deleting prefix lists...')656 ->expectsOutput('Deleted database prefix list successfully')657 ->expectsOutput('Deleted application prefix list successfully')658 ->expectsOutput('Deleting stack...')659 ->expectsOutput('Stack deletion completed successfully')660 ->assertExitCode(0);661 }662 public function testDeleteStackDoesntExist()663 {664 $cloudformation = $this->mockLaraSurfCloudFormationClient();665 $cloudformation->shouldReceive('stackStatus')->once()->andReturn(false);666 $this->artisan('larasurf:cloud-stacks delete --environment production')667 ->expectsQuestion("Are you sure you want to delete the stack for the 'production' environment?", true)668 ->expectsOutput("Stack does not exist for the 'production' environment")669 ->assertExitCode(1);670 }671 public function testWait()672 {673 Mockery::getConfiguration()->setConstantsMap([674 CloudFormationClient::class => [675 'STACK_STATUS_UPDATE_COMPLETE' => 'UPDATE_COMPLETE',676 ]677 ]);678 $status = 'UPDATE_COMPLETE';679 $this->mockLaraSurfCloudFormationClient()->shouldReceive('waitForStackInfoPanel')->once()->andReturn([680 'success' => true,681 'status' => $status,682 ]);683 $this->artisan('larasurf:cloud-stacks wait --environment production')684 ->expectsOutput("Stack operation finished with status: $status")685 ->assertExitCode(0);686 }687}...
Configuration.php
Source:Configuration.php
...151 public function getInternalClassMethodParamMaps()152 {153 return $this->_internalClassParamMap;154 }155 public function setConstantsMap(array $map)156 {157 $this->_constantsMap = $map;158 }159 public function getConstantsMap()160 {161 return $this->_constantsMap;162 }163 /**164 * Returns the quick definitions configuration165 */166 public function getQuickDefinitions(): QuickDefinitionsConfiguration167 {168 return $this->_quickDefinitionsConfiguration;169 }...
setConstantsMap
Using AI Code Generation
1require 'must.php';2$must = new Must();3$must->setConstantsMap(array(4));5require 'must.php';6$must = new Must();7$must->setConstantsMap(array(8));9require 'must.php';10$must = new Must();11$must->setConstantsMap(array(12));13require 'must.php';14$must = new Must();15$must->setConstantsMap(array(
setConstantsMap
Using AI Code Generation
1require 'must.php';2$must = new Must();3$must->setConstantsMap(array(4));5echo $must->render('1.mustache', array(6));7require 'must.php';8$must = new Must();9$must->setConstantsMap(array(10));11echo $must->render('2.mustache', array(12));13require 'must.php';14$must = new Must();15$must->setConstantsMap(array(16));17echo $must->render('3.mustache', array(18));19require 'must.php';20$must = new Must();21$must->setConstantsMap(array(22));23echo $must->render('4.mustache', array(24));25require 'must.php';26$must = new Must();27$must->setConstantsMap(array(28));29echo $must->render('5.mustache', array(
setConstantsMap
Using AI Code Generation
1$must = new must();2$must->setConstantsMap(array("MUST" => "MUST", "MUST_NOT" => "MUST_NOT", "SHOULD" => "SHOULD", "SHOULD_NOT" => "SHOULD_NOT", "MAY" => "MAY"));3echo MUST;4echo MUST_NOT;5echo SHOULD;6echo SHOULD_NOT;7echo MAY;8$must = new must();9$must->setConstantsMap(array("MUST" => "MUST", "MUST_NOT" => "MUST_NOT", "SHOULD" => "SHOULD", "SHOULD_NOT" => "SHOULD_NOT", "MAY" => "MAY"));10echo MUST;11echo MUST_NOT;12echo SHOULD;13echo SHOULD_NOT;14echo MAY;15$must = new must();16$must->setConstantsMap(array("MUST" => "MUST", "MUST_NOT" => "MUST_NOT", "SHOULD" => "SHOULD", "SHOULD_NOT" => "SHOULD_NOT", "MAY" => "MAY"));17echo MUST;18echo MUST_NOT;19echo SHOULD;20echo SHOULD_NOT;21echo MAY;22$must = new must();23$must->setConstantsMap(array("MUST" => "MUST", "MUST_NOT" => "MUST_NOT", "SHOULD" => "SHOULD", "SHOULD_NOT" => "SHOULD_NOT", "MAY" => "MAY"));24echo MUST;25echo MUST_NOT;26echo SHOULD;27echo SHOULD_NOT;28echo MAY;29$must = new must();30$must->setConstantsMap(array("MUST" => "MUST", "MUST_NOT" => "MUST_NOT", "SHOULD" => "SHOULD", "SHOULD_NOT" => "SHOULD_NOT", "MAY" => "MAY"));31echo MUST;32echo MUST_NOT;33echo SHOULD;34echo SHOULD_NOT;35echo MAY;36$must = new must();
setConstantsMap
Using AI Code Generation
1require 'must.php';2$must = new Must();3$must->setConstantsMap(array(4));5echo $must->render('2.php');6echo 'FOO is ' . FOO . ' and BAR is ' . BAR;7require 'must.php';8$must = new Must();9$must->setConstantsMap(array(10));11echo $must->render('2.php');12echo 'FOO is ' . FOO . ' and BAR is ' . BAR;13require 'must.php';14$must = new Must();15$must->setConstantsMap(array(16));17echo $must->render('2.php');18echo 'FOO is ' . FOO . ' and BAR is ' . BAR;19require 'must.php';20$must = new Must();21$must->setConstantsMap(array(22));23echo $must->render('2.php');24echo 'FOO is ' . FOO . ' and BAR is ' . BAR;25require 'must.php';26$must = new Must();27$must->setConstantsMap(array(
setConstantsMap
Using AI Code Generation
1$must = new Must();2$must->setConstantsMap(array(3));4$must = new Must();5$must->setConstantsMap(array(6));7$must = new Must();8$must->setConstantsMap(array(9));10$must = new Must();11$must->setConstantsMap(array(12));13$must = new Must();14$must->setConstantsMap(array(15));16$must = new Must();17$must->setConstantsMap(array(18));19$must = new Must();20$must->setConstantsMap(array(21));22$must = new Must();23$must->setConstantsMap(array(24));25$must = new Must();26$must->setConstantsMap(array(27));
setConstantsMap
Using AI Code Generation
1require_once 'must.php';2$must = new must;3$must->setConstantsMap(array('test' => 'test'));4echo $must->render('1.mustache');5require_once 'must.php';6$must = new must;7$must->setConstantsMap(array('test' => 'test'));8echo $must->render('1.mustache');9require_once 'must.php';10$must = new must;11$must->setConstantsMap(array('test' => 'test'));12echo $must->render('1.mustache');13require_once 'must.php';14$must = new must;15$must->setConstantsMap(array('test' => 'test'));16echo $must->render('1.mustache');17require_once 'must.php';18$must = new must;19$must->setConstantsMap(array('test' => 'test'));20echo $must->render('1.mustache');21require_once 'must.php';22$must = new must;23$must->setConstantsMap(array('test' => 'test'));24echo $must->render('1.mustache');25require_once 'must.php';26$must = new must;27$must->setConstantsMap(array('test' => 'test'));28echo $must->render('1.mustache');29require_once 'must.php';30$must = new must;31$must->setConstantsMap(array('test' => 'test'));32echo $must->render('1.mustache');33require_once 'must.php';34$must = new must;35$must->setConstantsMap(array('test' => 'test'));36echo $must->render('1.mustache');
setConstantsMap
Using AI Code Generation
1require_once 'Must.php';2$must = new Must();3$must->setConstantsMap(array('title' => 'hello world'));4$must->render('1.mustache');5require_once 'Mustache/Autoloader.php';6Mustache_Autoloader::register();7$mustache = new Mustache_Engine;8$template = $mustache->loadTemplate('Hello {{planet}}!');9echo $template->render(array('planet' => 'World!'));10require_once 'Twig/Autoloader.php';11Twig_Autoloader::register();12$loader = new Twig_Loader_Filesystem('path/to/templates');13$twig = new Twig_Environment($loader, array(14));
setConstantsMap
Using AI Code Generation
1require_once('must.php');2$must = new Must();3$must->setConstantsMap('MYCONSTANTS', array('const1'=>'value1', 'const2'=>'value2'));4$must->render('1.php');5require_once('must.php');6$must = new Must();7$must->setConstantsMap('MYCONSTANTS', array('const1'=>'value1', 'const2'=>'value2'));8$must->setConstantsMap('MYCONSTANTS', array('const1'=>'value1', 'const2'=>'value2', 'const3'=>'value3'));9$must->render('2.php');10require_once('must.php');11$must = new Must();12$must->setConstantsMap('MYCONSTANTS', array('const1'=>'value1', 'const2'=>'value2'));13$must->setConstantsMap('MYCONSTANTS', array('const3'=>'value3', 'const4'=>'value4'));14$must->render('3.php');15require_once('must.php');16$must = new Must();17$must->setConstantsMap('MYCONSTANTS', array('const1'=>'value1', 'const2'=>'value2'));18$must->setConstantsMap('MYCONSTANTS', array('const2'=>'value2', 'const1'=>'value1'));19$must->render('4.php');20require_once('must.php');21$must = new Must();22$must->setConstantsMap('MYCONSTANTS', array('const1'=>'value1', 'const2'=>'value2'));23$must->setConstantsMap('MYCONSTANTS', array('const2'=>'value2', 'const1'=>'value1'));24$must->setConstantsMap('MYCONSTANTS', array('const1'=>'value1', 'const2'=>'value2'));25$must->render('5.php');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with setConstantsMap on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!