How to use setContent method of vfsStreamFile class

Best VfsStream code snippet using vfsStreamFile.setContent

SetupTest.php

Source:SetupTest.php Github

copy

Full Screen

...80 question: first var value?81 default: 2382 message: Var value is \$first83YAML;84 $configFile->setContent($configFileContent);85 $dir->addChild($configFile);86 $application = new Application();87 $application->add(new Setup());88 $command = $application->find('setup');89 $commandTester = new CommandTester($command);90 $helper = $command->getHelper('question');91 $helper->setInputStream($this->getInputStream("Test\n"));92 $commandTester->execute([93 'command' => $command->getName(),94 'config' => $dir->url() . '/conf.yaml'95 ]);96 $display = $commandTester->getDisplay();97 $this->assertContains('Configuring "foo"', $display);98 $this->assertContains('first var value? (23)', $display);99 $this->assertContains('Var value is Test', $display);100 }101 /**102 * @test103 * it should allow running commands from the configuration file104 */105 public function it_should_allow_running_commands_from_the_configuration_file()106 {107 $dir = vfsStream::setup();108 $sourceFile = new vfsStreamFile('source.txt');109 $outputFile = new vfsStreamFile('out.txt');110 $sourceFile->setContent('foo baz bar');111 $sourceFilePath = $dir->url() . '/source.txt';112 $outputFilePath = $dir->url() . '/out.txt';113 $configFile = new vfsStreamFile('conf.yaml');114 $configFileContent = <<< YAML115foo:116 var:117 name: first118 question: first var value?119 default: 23120 command: search-replace foo \$first $sourceFilePath $outputFilePath121YAML;122 $configFile->setContent($configFileContent);123 $dir->addChild($configFile);124 $dir->addChild($sourceFile);125 $dir->addChild($outputFile);126 $application = new Application();127 $application->add(new Setup());128 $command = $application->find('setup');129 $application->add(new SearchReplace());130 $commandTester = new CommandTester($command);131 $helper = $command->getHelper('question');132 $helper->setInputStream($this->getInputStream("hello\n"));133 $commandTester->execute([134 'command' => $command->getName(),135 'config' => $dir->url() . '/conf.yaml'136 ]);137 $display = $commandTester->getDisplay();138 $this->assertContains('Configuring "foo"', $display);139 $this->assertContains('first var value? (23)', $display);140 $this->assertStringEqualsFile($outputFilePath, 'hello baz bar');141 }142 /**143 * @test144 * it should allow executing scripts145 */146 public function it_should_allow_executing_scripts()147 {148 $dir = vfsStream::setup();149 $configFile = new vfsStreamFile('conf.yaml');150 $outputFile = __DIR__ . DIRECTORY_SEPARATOR . 'out.txt';151 $configFileContent = <<< YAML152foo:153 exec: touch {$outputFile}154YAML;155 $configFile->setContent($configFileContent);156 $dir->addChild($configFile);157 $application = new Application();158 $application->add(new Setup());159 $command = $application->find('setup');160 $commandTester = new CommandTester($command);161 $commandTester->execute([162 'command' => $command->getName(),163 'config' => $dir->url() . '/conf.yaml'164 ]);165 $this->assertFileExists($outputFile);166 unlink($outputFile);167 }168 /**169 * @test170 * it should allow for vars in scripts171 */172 public function it_should_allow_for_vars_in_scripts()173 {174 $dir = vfsStream::setup();175 $configFile = new vfsStreamFile('conf.yaml');176 $outputFile = __DIR__ . DIRECTORY_SEPARATOR . 'out.txt';177 $configFileContent = <<< YAML178foo:179 var:180 name: first181 question: first var value?182 default: 12183 exec: touch {$outputFile} && echo "\$first" > {$outputFile}184YAML;185 $configFile->setContent($configFileContent);186 $dir->addChild($configFile);187 $application = new Application();188 $application->add(new Setup());189 $command = $application->find('setup');190 $commandTester = new CommandTester($command);191 $helper = $command->getHelper('question');192 $helper->setInputStream($this->getInputStream("hello\n"));193 $commandTester->execute([194 'command' => $command->getName(),195 'config' => $dir->url() . '/conf.yaml'196 ]);197 $this->assertFileExists($outputFile);198 // let's take the simulated input aberration into account199 $this->assertStringEqualsFile($outputFile, "hello\n");200 unlink($outputFile);201 }202 /**203 * @test204 * it should allow displaying messages conditionally205 */206 public function it_should_allow_displaying_messages_conditionally()207 {208 $dir = vfsStream::setup();209 $configFile = new vfsStreamFile('conf.yaml');210 $configFileContent = <<< YAML211foo:212 var:213 name: display214 question: mode?215 default: on216 message:217 if: display is on218 value: Now you see me219YAML;220 $configFile->setContent($configFileContent);221 $dir->addChild($configFile);222 $application = new Application();223 $application->add(new Setup());224 $command = $application->find('setup');225 $commandTester = new CommandTester($command);226 $helper = $command->getHelper('question');227 $helper->setInputStream($this->getInputStream("on\n"));228 $commandTester->execute([229 'command' => $command->getName(),230 'config' => $dir->url() . '/conf.yaml'231 ]);232 $display = $commandTester->getDisplay();233 $this->assertContains('mode?', $display);234 $this->assertContains('Now you see me', $display);235 }236 /**237 * @test238 * it should allow not displaying messages conditionally239 */240 public function it_should_allow_not_displaying_messages_conditionally()241 {242 $dir = vfsStream::setup();243 $configFile = new vfsStreamFile('conf.yaml');244 $configFileContent = <<< YAML245foo:246 var:247 name: display248 question: mode?249 default: on250 message:251 if: display is on252 value: Now you see me253YAML;254 $configFile->setContent($configFileContent);255 $dir->addChild($configFile);256 $application = new Application();257 $application->add(new Setup());258 $command = $application->find('setup');259 $commandTester = new CommandTester($command);260 $helper = $command->getHelper('question');261 $helper->setInputStream($this->getInputStream("off\n"));262 $commandTester->execute([263 'command' => $command->getName(),264 'config' => $dir->url() . '/conf.yaml'265 ]);266 $display = $commandTester->getDisplay();267 $this->assertContains('mode?', $display);268 $this->assertNotContains('Now you see me', $display);269 }270 /**271 * @test272 * it should allow to conditionally request a var273 */274 public function it_should_allow_to_conditionally_request_a_var()275 {276 $dir = vfsStream::setup();277 $configFile = new vfsStreamFile('conf.yaml');278 $configFileContent = <<< YAML279foo:280 var:281 name: display282 question: mode?283 default: on284 var:285 if: display is on286 name: foo287 question: foo var value?288 default: some value289YAML;290 $configFile->setContent($configFileContent);291 $dir->addChild($configFile);292 $application = new Application();293 $application->add(new Setup());294 $command = $application->find('setup');295 $commandTester = new CommandTester($command);296 $helper = $command->getHelper('question');297 $helper->setInputStream($this->getInputStream("on\n23\n"));298 $commandTester->execute([299 'command' => $command->getName(),300 'config' => $dir->url() . '/conf.yaml'301 ]);302 $display = $commandTester->getDisplay();303 $this->assertContains('foo var value?', $display);304 }305 /**306 * @test307 * it should allow to conditionally not ask for a var308 */309 public function it_should_allow_to_conditionally_not_ask_for_a_var()310 {311 $dir = vfsStream::setup();312 $configFile = new vfsStreamFile('conf.yaml');313 $configFileContent = <<< YAML314foo:315 var:316 name: display317 question: mode?318 default: on319 var:320 unless: display is on321 name: foo322 question: foo var value?323 default: some value324YAML;325 $configFile->setContent($configFileContent);326 $dir->addChild($configFile);327 $application = new Application();328 $application->add(new Setup());329 $command = $application->find('setup');330 $commandTester = new CommandTester($command);331 $helper = $command->getHelper('question');332 $helper->setInputStream($this->getInputStream("on\n"));333 $commandTester->execute([334 'command' => $command->getName(),335 'config' => $dir->url() . '/conf.yaml'336 ]);337 $display = $commandTester->getDisplay();338 $this->assertNotContains('foo var value?', $display);339 }340 /**341 * @test342 * it should allow to conditionally run a command343 */344 public function it_should_allow_to_conditionally_run_a_command()345 {346 $dir = vfsStream::setup();347 $sourceFile = new vfsStreamFile('source.txt');348 $outputFile = new vfsStreamFile('out.txt');349 $sourceFile->setContent('foo baz bar');350 $sourceFilePath = $dir->url() . '/source.txt';351 $outputFilePath = $dir->url() . '/out.txt';352 $configFile = new vfsStreamFile('conf.yaml');353 $configFileContent = <<< YAML354foo:355 var:356 name: first357 question: first var value?358 default: 23359 command: 360 if: first is hello361 value: search-replace foo \$first $sourceFilePath $outputFilePath362YAML;363 $configFile->setContent($configFileContent);364 $dir->addChild($configFile);365 $dir->addChild($sourceFile);366 $dir->addChild($outputFile);367 $application = new Application();368 $application->add(new Setup());369 $command = $application->find('setup');370 $application->add(new SearchReplace());371 $commandTester = new CommandTester($command);372 $helper = $command->getHelper('question');373 $helper->setInputStream($this->getInputStream("hello\n"));374 $commandTester->execute([375 'command' => $command->getName(),376 'config' => $dir->url() . '/conf.yaml'377 ]);378 $display = $commandTester->getDisplay();379 $this->assertContains('Configuring "foo"', $display);380 $this->assertContains('first var value? (23)', $display);381 $this->assertStringEqualsFile($outputFilePath, 'hello baz bar');382 }383 /**384 * @test385 * it should allow to conditionally not run a command386 */387 public function it_should_allow_to_conditionally_not_run_a_command()388 {389 $dir = vfsStream::setup();390 $sourceFile = new vfsStreamFile('source.txt');391 $outputFile = new vfsStreamFile('out.txt');392 $sourceFile->setContent('foo baz bar');393 $sourceFilePath = $dir->url() . '/source.txt';394 $outputFilePath = $dir->url() . '/out.txt';395 $configFile = new vfsStreamFile('conf.yaml');396 $configFileContent = <<< YAML397foo:398 var:399 name: first400 question: first var value?401 default: 23402 command: 403 unless: first is hello404 value: search-replace foo \$first $sourceFilePath $outputFilePath405YAML;406 $configFile->setContent($configFileContent);407 $dir->addChild($configFile);408 $dir->addChild($sourceFile);409 $dir->addChild($outputFile);410 $application = new Application();411 $application->add(new Setup());412 $command = $application->find('setup');413 $application->add(new SearchReplace());414 $commandTester = new CommandTester($command);415 $helper = $command->getHelper('question');416 $helper->setInputStream($this->getInputStream("hello\n"));417 $commandTester->execute([418 'command' => $command->getName(),419 'config' => $dir->url() . '/conf.yaml'420 ]);421 $display = $commandTester->getDisplay();422 $this->assertContains('Configuring "foo"', $display);423 $this->assertContains('first var value? (23)', $display);424 $this->assertStringNotEqualsFile($outputFilePath, 'hello baz bar');425 }426 /**427 * @test428 * it should allow to conditionally execute a script429 */430 public function it_should_allow_to_conditionally_execute_a_script()431 {432 $dir = vfsStream::setup();433 $configFile = new vfsStreamFile('conf.yaml');434 $outputFile = __DIR__ . DIRECTORY_SEPARATOR . 'out.txt';435 $configFileContent = <<< YAML436foo:437 var:438 name: first439 question: foo var value?440 default: 23441 exec: 442 if: first is hello443 value: touch {$outputFile}444YAML;445 $configFile->setContent($configFileContent);446 $dir->addChild($configFile);447 $application = new Application();448 $application->add(new Setup());449 $command = $application->find('setup');450 $commandTester = new CommandTester($command);451 $helper = $command->getHelper('question');452 $helper->setInputStream($this->getInputStream("hello\n"));453 $commandTester->execute([454 'command' => $command->getName(),455 'config' => $dir->url() . '/conf.yaml'456 ]);457 $this->assertFileExists($outputFile);458 unlink($outputFile);459 }460 /**461 * @test462 * it should allow to conditionally not execute a script463 */464 public function it_should_allow_to_conditionally_not_execute_a_script()465 {466 $dir = vfsStream::setup();467 $configFile = new vfsStreamFile('conf.yaml');468 $outputFile = __DIR__ . DIRECTORY_SEPARATOR . 'out.txt';469 $configFileContent = <<< YAML470foo:471 var:472 name: first473 question: foo var value?474 default: 23475 exec: 476 unless: first is hello477 value: touch {$outputFile}478YAML;479 $configFile->setContent($configFileContent);480 $dir->addChild($configFile);481 $application = new Application();482 $application->add(new Setup());483 $command = $application->find('setup');484 $commandTester = new CommandTester($command);485 $helper = $command->getHelper('question');486 $helper->setInputStream($this->getInputStream("hello\n"));487 $commandTester->execute([488 'command' => $command->getName(),489 'config' => $dir->url() . '/conf.yaml'490 ]);491 $this->assertFileNotExists($outputFile);492 }493 /**494 * @test495 * it should allow for int variable validation and ask until var validates496 */497 public function it_should_allow_for_int_variable_validation_and_ask_until_var_validates()498 {499 $dir = vfsStream::setup();500 $configFile = new vfsStreamFile('conf.yaml');501 $configFileContent = <<< YAML502foo:503 var:504 name: first505 question: first var value?506 validate: int507 default: 23508 message: Var value is \$first509YAML;510 $configFile->setContent($configFileContent);511 $dir->addChild($configFile);512 $application = new Application();513 $application->add(new Setup());514 $command = $application->find('setup');515 $commandTester = new CommandTester($command);516 $helper = $command->getHelper('question');517 $helper->setInputStream($this->getInputStream("Test\nfoo\n12\n"));518 $commandTester->execute([519 'command' => $command->getName(),520 'config' => $dir->url() . '/conf.yaml'521 ]);522 $display = $commandTester->getDisplay();523 $this->assertContains('Configuring "foo"', $display);524 $this->assertContains('first var value? (23)', $display);525 $this->assertContains('Var value is 12', $display);526 }527 /**528 * @test529 * it should allow for float variable validation and ask until var validates530 */531 public function it_should_allow_for_float_variable_validation_and_ask_until_var_validates()532 {533 $dir = vfsStream::setup();534 $configFile = new vfsStreamFile('conf.yaml');535 $configFileContent = <<< YAML536foo:537 var:538 name: first539 question: first var value?540 validate: float541 default: 23542 message: Var value is \$first543YAML;544 $configFile->setContent($configFileContent);545 $dir->addChild($configFile);546 $application = new Application();547 $application->add(new Setup());548 $command = $application->find('setup');549 $commandTester = new CommandTester($command);550 $helper = $command->getHelper('question');551 $helper->setInputStream($this->getInputStream("Test\nfoo\n12.5\n"));552 $commandTester->execute([553 'command' => $command->getName(),554 'config' => $dir->url() . '/conf.yaml'555 ]);556 $display = $commandTester->getDisplay();557 $this->assertContains('Configuring "foo"', $display);558 $this->assertContains('first var value? (23)', $display);559 $this->assertContains('Var value is 12.5', $display);560 }561 /**562 * @test563 * it should allow for bool variable validation and ask until var validates564 */565 public function it_should_allow_for_bool_variable_validation_and_ask_until_var_validates()566 {567 $dir = vfsStream::setup();568 $configFile = new vfsStreamFile('conf.yaml');569 $configFileContent = <<< YAML570foo:571 var:572 name: first573 question: first var value?574 validate: bool575 default: 23576 message: Var value is \$first577YAML;578 $configFile->setContent($configFileContent);579 $dir->addChild($configFile);580 $application = new Application();581 $application->add(new Setup());582 $command = $application->find('setup');583 $commandTester = new CommandTester($command);584 $helper = $command->getHelper('question');585 $helper->setInputStream($this->getInputStream("Test\nfoo\ntrue\n"));586 $commandTester->execute([587 'command' => $command->getName(),588 'config' => $dir->url() . '/conf.yaml'589 ]);590 $display = $commandTester->getDisplay();591 $this->assertContains('Configuring "foo"', $display);592 $this->assertContains('first var value? (23)', $display);593 $this->assertContains('Var value is true', $display);594 }595 /**596 * @test597 * it should allow for url variable validation and ask until var validates598 */599 public function it_should_allow_for_url_variable_validation_and_ask_until_var_validates()600 {601 $dir = vfsStream::setup();602 $configFile = new vfsStreamFile('conf.yaml');603 $configFileContent = <<< YAML604foo:605 var:606 name: first607 question: first var value?608 validate: url609 default: 23610 message: Var value is \$first611YAML;612 $configFile->setContent($configFileContent);613 $dir->addChild($configFile);614 $application = new Application();615 $application->add(new Setup());616 $command = $application->find('setup');617 $commandTester = new CommandTester($command);618 $helper = $command->getHelper('question');619 $helper->setInputStream($this->getInputStream("Test\nfoo\nhttp://wp.dev\n"));620 $commandTester->execute([621 'command' => $command->getName(),622 'config' => $dir->url() . '/conf.yaml'623 ]);624 $display = $commandTester->getDisplay();625 $this->assertContains('Configuring "foo"', $display);626 $this->assertContains('first var value? (23)', $display);627 $this->assertContains('Var value is http://wp.dev', $display);628 }629 /**630 * @test631 * it should allow for email variable validation and ask until var validates632 */633 public function it_should_allow_for_email_variable_validation_and_ask_until_var_validates()634 {635 $dir = vfsStream::setup();636 $configFile = new vfsStreamFile('conf.yaml');637 $configFileContent = <<< YAML638foo:639 var:640 name: first641 question: first var value?642 validate: email643 default: 23644 message: Var value is \$first645YAML;646 $configFile->setContent($configFileContent);647 $dir->addChild($configFile);648 $application = new Application();649 $application->add(new Setup());650 $command = $application->find('setup');651 $commandTester = new CommandTester($command);652 $helper = $command->getHelper('question');653 $helper->setInputStream($this->getInputStream("Test\nfoo\nluca@email.com\n"));654 $commandTester->execute([655 'command' => $command->getName(),656 'config' => $dir->url() . '/conf.yaml'657 ]);658 $display = $commandTester->getDisplay();659 $this->assertContains('Configuring "foo"', $display);660 $this->assertContains('first var value? (23)', $display);661 $this->assertContains('Var value is luca@email.com', $display);662 }663 public function yesNoUserInputProvider()664 {665 return [666 ["\n", "showMessage value is yes"],667 ["yes\n", "showMessage value is yes"],668 ["y\n", "showMessage value is yes"],669 ["Y\n", "showMessage value is yes"],670 ["YES\n", "showMessage value is yes"],671 ["Yes\n", "showMessage value is yes"],672 ["no\n", ""],673 ["n\n", ""],674 ["N\n", ""],675 ["NO\n", ""],676 ["nO\n", ""],677 ];678 }679 /**680 * @test681 * it should allow validating yes/no values682 * @dataProvider yesNoUserInputProvider683 */684 public function it_should_allow_validating_yes_no_values($userInput, $expectedMessage)685 {686 $dir = vfsStream::setup();687 $configFile = new vfsStreamFile('conf.yaml');688 $configFileContent = <<< YAML689foo:690 var:691 name: showMessage692 question: show the message?693 default: yes694 validate: yesno695 message:696 unless: showMessage is no697 value: showMessage value is \$showMessage698YAML;699 $configFile->setContent($configFileContent);700 $dir->addChild($configFile);701 $application = new Application();702 $application->add(new Setup());703 $command = $application->find('setup');704 $commandTester = new CommandTester($command);705 $helper = $command->getHelper('question');706 $helper->setInputStream($this->getInputStream($userInput));707 $commandTester->execute([708 'command' => $command->getName(),709 'config' => $dir->url() . '/conf.yaml'710 ]);711 $display = $commandTester->getDisplay();712 $this->assertContains('Configuring "foo"', $display);713 $this->assertContains('show the message? (yes)', $display);714 if (!empty($expectedMessage)) {715 $this->assertContains($expectedMessage, $display);716 } else {717 $this->assertNotContains('showMessage value is', $display);718 }719 }720 /**721 * @test722 * it should support the not condition723 */724 public function it_should_support_the_not_condition()725 {726 $dir = vfsStream::setup();727 $configFile = new vfsStreamFile('conf.yaml');728 $configFileContent = <<< YAML729foo:730 var:731 name: showMessage732 question: show the message?733 default: yes734 validate: yesno735 message:736 if: showMessage not no737 value: showMessage value is \$showMessage738YAML;739 $configFile->setContent($configFileContent);740 $dir->addChild($configFile);741 $application = new Application();742 $application->add(new Setup());743 $command = $application->find('setup');744 $commandTester = new CommandTester($command);745 $helper = $command->getHelper('question');746 $helper->setInputStream($this->getInputStream("yes\n"));747 $commandTester->execute([748 'command' => $command->getName(),749 'config' => $dir->url() . '/conf.yaml'750 ]);751 $display = $commandTester->getDisplay();752 $this->assertContains('Configuring "foo"', $display);753 $this->assertContains('show the message? (yes)', $display);754 $this->assertContains('showMessage value is yes', $display);755 }756 /**757 * @test758 * it should allow checking if existence condition759 */760 public function it_should_allow_checking_if_existence_condition()761 {762 $dir = vfsStream::setup();763 $configFile = new vfsStreamFile('conf.yaml');764 $configFileContent = <<< YAML765foo:766 var:767 name: myName768 question: name?769 message:770 if: myName771 value: Hello \$myName!772YAML;773 $configFile->setContent($configFileContent);774 $dir->addChild($configFile);775 $application = new Application();776 $application->add(new Setup());777 $command = $application->find('setup');778 $commandTester = new CommandTester($command);779 $helper = $command->getHelper('question');780 $helper->setInputStream($this->getInputStream("\n"));781 $commandTester->execute([782 'command' => $command->getName(),783 'config' => $dir->url() . '/conf.yaml'784 ]);785 $display = $commandTester->getDisplay();786 $this->assertContains('Configuring "foo"', $display);787 $this->assertContains('name?', $display);788 $this->assertNotContains('Hello', $display);789 }790 /**791 * @test792 * it should allow checking positive existence condition793 */794 public function it_should_allow_checking_positive_existence_condition()795 {796 $dir = vfsStream::setup();797 $configFile = new vfsStreamFile('conf.yaml');798 $configFileContent = <<< YAML799foo:800 var:801 name: myName802 question: name?803 message:804 if: myName805 value: Hello \$myName!806YAML;807 $configFile->setContent($configFileContent);808 $dir->addChild($configFile);809 $application = new Application();810 $application->add(new Setup());811 $command = $application->find('setup');812 $commandTester = new CommandTester($command);813 $helper = $command->getHelper('question');814 $helper->setInputStream($this->getInputStream("Luca\n"));815 $commandTester->execute([816 'command' => $command->getName(),817 'config' => $dir->url() . '/conf.yaml'818 ]);819 $display = $commandTester->getDisplay();820 $this->assertContains('Configuring "foo"', $display);821 $this->assertContains('name?', $display);822 $this->assertContains('Hello Luca!', $display);823 }824 /**825 * @test826 * it should support loops in messages827 */828 public function it_should_support_loops_in_messages()829 {830 $dir = vfsStream::setup();831 $configFile = new vfsStreamFile('conf.yaml');832 $configFileContent = <<< YAML833foo:834 var:835 name: times836 question: times?837 validate: int838 default: 3839 message:840 if: times841 for: time in times842 value: loop \$time843YAML;844 $configFile->setContent($configFileContent);845 $dir->addChild($configFile);846 $application = new Application();847 $application->add(new Setup());848 $command = $application->find('setup');849 $commandTester = new CommandTester($command);850 $helper = $command->getHelper('question');851 $helper->setInputStream($this->getInputStream("3\n"));852 $commandTester->execute([853 'command' => $command->getName(),854 'config' => $dir->url() . '/conf.yaml'855 ]);856 $display = $commandTester->getDisplay();857 $this->assertContains('times?', $display);858 $this->assertContains('loop 1', $display);859 $this->assertContains('loop 2', $display);860 $this->assertContains('loop 3', $display);861 }862 /**863 * @test864 * it should support looping over user defined array of strings865 */866 public function it_should_support_looping_over_user_defined_array_of_strings()867 {868 $dir = vfsStream::setup();869 $configFile = new vfsStreamFile('conf.yaml');870 $configFileContent = <<< YAML871foo:872 message:873 for: var in foo,baz,bar874 value: var value is \$var875YAML;876 $configFile->setContent($configFileContent);877 $dir->addChild($configFile);878 $application = new Application();879 $application->add(new Setup());880 $command = $application->find('setup');881 $commandTester = new CommandTester($command);882 $commandTester->execute([883 'command' => $command->getName(),884 'config' => $dir->url() . '/conf.yaml'885 ]);886 $display = $commandTester->getDisplay();887 $this->assertContains('var value is foo', $display);888 $this->assertContains('var value is bar', $display);889 $this->assertContains('var value is baz', $display);890 }891 /**892 * @test893 * it should allow looping over user defined array of numbers894 */895 public function it_should_allow_looping_over_user_defined_array_of_numbers()896 {897 $dir = vfsStream::setup();898 $configFile = new vfsStreamFile('conf.yaml');899 $configFileContent = <<< YAML900foo:901 message:902 for: var in 12,23,71903 value: var value is \$var904YAML;905 $configFile->setContent($configFileContent);906 $dir->addChild($configFile);907 $application = new Application();908 $application->add(new Setup());909 $command = $application->find('setup');910 $commandTester = new CommandTester($command);911 $commandTester->execute([912 'command' => $command->getName(),913 'config' => $dir->url() . '/conf.yaml'914 ]);915 $display = $commandTester->getDisplay();916 $this->assertContains('var value is 12', $display);917 $this->assertContains('var value is 23', $display);918 $this->assertContains('var value is 71', $display);919 }920 /**921 * @test922 * it should allow looping over user defined array of strings, ints and vars923 */924 public function it_should_allow_looping_over_user_defined_array_of_strings_ints_and_vars()925 {926 $dir = vfsStream::setup();927 $configFile = new vfsStreamFile('conf.yaml');928 $configFileContent = <<< YAML929foo:930 var:931 name: varOne932 question: var one?933 validate: int934 default: 3935 message:936 for: loopVar in 45,foo,\$varOne 937 value: var value is \$loopVar938YAML;939 $configFile->setContent($configFileContent);940 $dir->addChild($configFile);941 $application = new Application();942 $application->add(new Setup());943 $command = $application->find('setup');944 $commandTester = new CommandTester($command);945 $helper = $command->getHelper('question');946 $helper->setInputStream($this->getInputStream("12\n"));947 $commandTester->execute([948 'command' => $command->getName(),949 'config' => $dir->url() . '/conf.yaml'950 ]);951 $display = $commandTester->getDisplay();952 $this->assertContains('var one?', $display);953 $this->assertContains('var value is 45', $display);954 $this->assertContains('var value is foo', $display);955 $this->assertContains('var value is 12', $display);956 }957 /**958 * @test959 * it should support loops in commands960 */961 public function it_should_support_loops_in_commands()962 {963 $dir = vfsStream::setup();964 $configFile = new vfsStreamFile('conf.yaml');965 $files = [966 codecept_root_dir('one.txt'),967 codecept_root_dir('two.txt'),968 codecept_root_dir('three.txt')969 ];970 $configFileContent = <<< YAML971foo:972 command:973 for: loopVar in one,two,three 974 value: search-replace foo bar \$loopVar.txt \$loopVar.foo.txt975YAML;976 foreach ($files as $file) {977 file_put_contents($file, 'Foo is foo');978 }979 $configFile->setContent($configFileContent);980 $dir->addChild($configFile);981 $application = new Application();982 $application->add(new Setup());983 $application->add(new SearchReplace());984 $command = $application->find('setup');985 $commandTester = new CommandTester($command);986 $helper = $command->getHelper('question');987 $helper->setInputStream($this->getInputStream("12\n"));988 $commandTester->execute([989 'command' => $command->getName(),990 'config' => $dir->url() . '/conf.yaml'991 ]);992 $expectedFiles = [993 codecept_root_dir('one.foo.txt'),994 codecept_root_dir('two.foo.txt'),995 codecept_root_dir('three.foo.txt')996 ];997 foreach ($expectedFiles as $expectedFile) {998 $this->assertFileExists($expectedFile);999 $this->assertStringEqualsFile($expectedFile, 'Foo is bar');1000 }1001 foreach (array_merge($files, $expectedFiles) as $file) {1002 unlink($file);1003 }1004 }1005 /**1006 * @test1007 * it should support loops in execs1008 */1009 public function it_should_support_loops_in_execs()1010 {1011 $dir = vfsStream::setup();1012 $configFile = new vfsStreamFile('conf.yaml');1013 $configFileContent = <<< YAML1014foo:1015 exec:1016 for: loopVar in one,two,three 1017 value: touch \$loopVar.txt1018YAML;1019 $configFile->setContent($configFileContent);1020 $dir->addChild($configFile);1021 $application = new Application();1022 $application->add(new Setup());1023 $command = $application->find('setup');1024 $commandTester = new CommandTester($command);1025 $helper = $command->getHelper('question');1026 $helper->setInputStream($this->getInputStream("12\n"));1027 $commandTester->execute([1028 'command' => $command->getName(),1029 'config' => $dir->url() . '/conf.yaml'1030 ]);1031 $expectedFiles = [1032 codecept_root_dir('one.txt'),1033 codecept_root_dir('two.txt'),1034 codecept_root_dir('three.txt')1035 ];1036 foreach ($expectedFiles as $expectedFile) {1037 $this->assertFileExists($expectedFile);1038 }1039 foreach ($expectedFiles as $file) {1040 unlink($file);1041 }1042 }1043 /**1044 * @test1045 * it should support regex validation of vars1046 */1047 public function it_should_support_regex_validation_of_vars()1048 {1049 $dir = vfsStream::setup();1050 $configFile = new vfsStreamFile('conf.yaml');1051 $configFileContent = <<< YAML1052foo:1053 var:1054 name: varOne1055 question: var one?1056 validate: regexp1057 regexp: /^foo/1058 message:1059 value: varOne value is \$varOne1060YAML;1061 $configFile->setContent($configFileContent);1062 $dir->addChild($configFile);1063 $application = new Application();1064 $application->add(new Setup());1065 $command = $application->find('setup');1066 $commandTester = new CommandTester($command);1067 $helper = $command->getHelper('question');1068 $helper->setInputStream($this->getInputStream("12\nbar\nfoobar"));1069 $commandTester->execute([1070 'command' => $command->getName(),1071 'config' => $dir->url() . '/conf.yaml'1072 ]);1073 $display = $commandTester->getDisplay();1074 $this->assertContains('var one?', $display);1075 $this->assertContains('varOne value is foobar', $display);1076 }1077 /**1078 * @test1079 * it should support the break instruction1080 */1081 public function it_should_support_the_break_instruction()1082 {1083 $dir = vfsStream::setup();1084 $configFile = new vfsStreamFile('conf.yaml');1085 $configFileContent = <<< YAML1086foo:1087 var:1088 name: stop1089 question: stop?1090 validate: yesno1091 break:1092 if: stop1093 value: Stopped.1094 message: Should not see me.1095YAML;1096 $configFile->setContent($configFileContent);1097 $dir->addChild($configFile);1098 $application = new Application();1099 $application->add(new Setup());1100 $command = $application->find('setup');1101 $commandTester = new CommandTester($command);1102 $helper = $command->getHelper('question');1103 $helper->setInputStream($this->getInputStream("yes\n"));1104 $commandTester->execute([1105 'command' => $command->getName(),1106 'config' => $dir->url() . '/conf.yaml'1107 ]);1108 $display = $commandTester->getDisplay();1109 $this->assertContains('stop?', $display);1110 $this->assertContains('Stopped', $display);1111 $this->assertNotContains('Should not see me', $display);1112 }1113 /**1114 * @test1115 * it should allow setting var values1116 */1117 public function it_should_allow_setting_var_values()1118 {1119 $dir = vfsStream::setup();1120 $configFile = new vfsStreamFile('conf.yaml');1121 $configFileContent = <<< YAML1122foo:1123 var:1124 name: one1125 value: 231126 message: One is \$one1127YAML;1128 $configFile->setContent($configFileContent);1129 $dir->addChild($configFile);1130 $application = new Application();1131 $application->add(new Setup());1132 $command = $application->find('setup');1133 $commandTester = new CommandTester($command);1134 $helper = $command->getHelper('question');1135 $helper->setInputStream($this->getInputStream("yes\n"));1136 $commandTester->execute([1137 'command' => $command->getName(),1138 'config' => $dir->url() . '/conf.yaml'1139 ]);1140 $display = $commandTester->getDisplay();1141 $this->assertContains('One is 23', $display);1142 }...

Full Screen

Full Screen

GetStringsEndToEndTest.php

Source:GetStringsEndToEndTest.php Github

copy

Full Screen

...23 $dir2 = new vfsStreamDirectory('dir2');24 $this->langDir = new vfsStreamDirectory('lang');25 $this->esDir = new vfsStreamDirectory('es');26 $file1 = new vfsStreamFile('file1.tpl');27 $file1->setContent(file_get_contents(__DIR__ . '/fixtures/test_collecting_strings.tpl'));28 $file2 = new vfsStreamFile('file2.php');29 $file2->setContent(file_get_contents(__DIR__ . '/fixtures/test_collecting_strings.php'));30 $langFile = new vfsStreamFile('language.php');31 $langFile->setContent(file_get_contents(__DIR__ . '/fixtures/language_end_to_end_test_original.php'));32 $dir1->addChild($file1);33 $dir2->addChild($file2);34 $this->langDir->addChild($this->esDir);35 $this->esDir->addChild($langFile);36 $root->addChild($dir1);37 $root->addChild($dir2);38 $root->addChild($this->langDir);39 }40 public function testGetStrings_endToEnd()41 {42 $obj = new Language_GetStrings(43 new Language_CollectFiles,44 new Language_WriteFile_Factory,45 array('baseDir' => vfsStream::url('root'))46 );47 $obj->addFileType(new Language_FileType_Php);48 $obj->addFileType(new Language_FileType_Tpl);49 $obj->run();50 $this->assertEquals(51 file_get_contents(__DIR__ . '/fixtures/language_end_to_end_test_modified.php'),52 file_get_contents(vfsStream::url('root/lang/es/language.php'))53 );54 $this->assertEquals(55 file_get_contents(__DIR__ . '/fixtures/language_end_to_end_test_original.php'),56 file_get_contents(vfsStream::url('root/lang/es/language.php.old'))57 );58 }59 public function testGetStrings_endToEnd_customLanguageFileName()60 {61 $fileName = 'language_r.php';62 $langFile = new vfsStreamFile($fileName);63 $langFile->setContent(file_get_contents(__DIR__ . '/fixtures/language_end_to_end_test_original.php'));64 $this->esDir->addChild($langFile);65 $obj = new Language_GetStrings(66 new Language_CollectFiles,67 new Language_WriteFile_Factory,68 array('baseDir' => vfsStream::url('root'), 'fileName' => 'language_r.php')69 );70 $obj->addFileType(new Language_FileType_Php);71 $obj->addFileType(new Language_FileType_Tpl);72 $obj->run();73 $this->assertEquals(74 file_get_contents(__DIR__ . '/fixtures/language_end_to_end_test_modified.php'),75 file_get_contents(vfsStream::url("root/lang/es/$fileName"))76 );77 $this->assertEquals(78 file_get_contents(__DIR__ . '/fixtures/language_end_to_end_test_original.php'),79 file_get_contents(vfsStream::url("root/lang/es/$fileName.old"))80 );81 }82 public function testGetStrings_endToEnd_severalLanguageFiles()83 {84 $ruDir = new vfsStreamDirectory('ru');85 $faDir = new vfsStreamDirectory('fa');86 $ruFile = new vfsStreamFile('language.php');87 $ruFile->setContent(file_get_contents(__DIR__ . '/fixtures/language_ru_original.php'));88 $ruDir->addChild($ruFile);89 $faFile = new vfsStreamFile('language.php');90 $faFile->setContent(file_get_contents(__DIR__ . '/fixtures/language_fa_original.php'));91 $faDir->addChild($faFile);92 $this->langDir->addChild($ruDir);93 $this->langDir->addChild($faDir);94 $obj = new Language_GetStrings(95 new Language_CollectFiles,96 new Language_WriteFile_Factory,97 array('baseDir' => vfsStream::url('root'))98 );99 $obj->addFileType(new Language_FileType_Php);100 $obj->addFileType(new Language_FileType_Tpl);101 $obj->run();102 $this->assertEquals(103 file_get_contents(__DIR__ . '/fixtures/language_ru_modified.php'),104 file_get_contents(vfsStream::url('root/lang/ru/language.php'))...

Full Screen

Full Screen

setContent

Using AI Code Generation

copy

Full Screen

1$file->setContent($content);2echo $file->getContent();3$file->setContent($content);4echo $file->getContent();5$file->setContent($content);6echo $file->getContent();7$file->setContent($content);8echo $file->getContent();9$file->setContent($content);10echo $file->getContent();11$file->setContent($content);12echo $file->getContent();13$file->setContent($content);14echo $file->getContent();15$file->setContent($content);16echo $file->getContent();17$file->setContent($content);18echo $file->getContent();19$file->setContent($content);20echo $file->getContent();21$file->setContent($content);22echo $file->getContent();23$file->setContent($content);24echo $file->getContent();

Full Screen

Full Screen

setContent

Using AI Code Generation

copy

Full Screen

1$vfs->getChild('test.txt')->setContent('Hello World');2$vfs->getChild('test.txt')->appendContent('Hello World');3echo $vfs->getChild('test.txt')->getContents();4echo $vfs->getChild('test.txt')->getSize();5echo $vfs->getChild('test.txt')->getPermissions();6echo $vfs->getChild('test.txt')->getOwner();7echo $vfs->getChild('test.txt')->getGroup();8echo $vfs->getChild('test.txt')->getLastAccessedTime();9echo $vfs->getChild('test.txt')->getLastModifiedTime();10echo $vfs->getChild('test.txt')->getLastChangedTime();11echo $vfs->getChild('test.txt')->getCreationTime();12$vfs->getChild('test.txt')->setPermissions(0777);13$vfs->getChild('test.txt')->setOwner(1000);14$vfs->getChild('test.txt')->setGroup(1000);15$vfs->getChild('test.txt')->touch();

Full Screen

Full Screen

setContent

Using AI Code Generation

copy

Full Screen

1$root->getChild('test.txt')->setContent('Hello World');2echo $root->getChild('test.txt')->getContent();3$root->getChild('test.txt')->appendContent('Hello World');4echo $root->getChild('test.txt')->getContents();5echo $root->getChild('test.txt')->getSize();6echo $root->getChild('test.txt')->getLastAccessedTime();7echo $root->getChild('test.txt')->getLastModifiedTime();8echo $root->getChild('test.txt')->getCreationTime();9$root->getChild('test.txt')->setLastAccessedTime(123456789);10$root->getChild('test.txt')->setLastModifiedTime(123456789);11$root->getChild('test.txt')->setCreationTime(123456789);12echo $root->getChild('test.txt')->getPermissions();13$root->getChild('test.txt')->setPermissions(0777);14echo $root->getChild('test.txt')->getGroup();15$root->getChild('test.txt')->setGroup(1000);

Full Screen

Full Screen

setContent

Using AI Code Generation

copy

Full Screen

1$root->getChild('file.txt')->setContent('some content');2$root->getChild('file.txt')->appendContent('some more content');3$root->getChild('file.txt')->getContent();4$root->getChild('file.txt')->getContents();5$root->getChild('file.txt')->setContents('some content');6$root->getChild('file.txt')->appendContents('some more content');7$root->getChild('file.txt')->getURL();8$root->getChild('file.txt')->getSize();9$root->getChild('file.txt')->getPermissions();10$root->getChild('file.txt')->getOwner();11$root->getChild('file.txt')->getGroup();12$root->getChild('file.txt')->getATime();13$root->getChild('file.txt')->getMTime();14$root->getChild('file.txt')->getCTime();15$root->getChild('file.txt')->setPermissions(0777);16$root->getChild('file.txt')->setOwner('root');

Full Screen

Full Screen

setContent

Using AI Code Generation

copy

Full Screen

1$root->getChild('test.txt')->setContent('new content');2$root->getChild('test.txt')->appendContent('new content');3echo $root->getChild('test.txt')->getContents();4echo $root->getChild('test.txt')->getURL();5echo $root->getChild('test.txt')->getPermissions();6$root->getChild('test.txt')->setPermissions(0777);7echo $root->getChild('test.txt')->getOwner();8$root->getChild('test.txt')->setOwner('test');9echo $root->getChild('test.txt')->getGroup();10$root->getChild('test.txt')->setGroup('test');11echo $root->getChild('test.txt')->getLinkTarget();12$root->getChild('test.txt')->setLinkTarget('test');13echo $root->getChild('test.txt')->getLastAccessedTime();14$root->getChild('test.txt')->setLastAccessedTime(time());15echo $root->getChild('test.txt')->getLastModifiedTime();16$root->getChild('test.txt')->setLastModifiedTime(time());17echo $root->getChild('test.txt')->getLastChangedTime();18$root->getChild('test.txt')->setLastChangedTime(time());19echo $root->getChild('test.txt')->getIn

Full Screen

Full Screen

setContent

Using AI Code Generation

copy

Full Screen

1$vfs->getChild('2.php')->setContent('<?php echo "Hello World"; ?>');2$vfs->getChild('3.php')->setContent('<?php echo "Hello World"; ?>');3$vfs->getChild('4.php')->setContent('<?php echo "Hello World"; ?>');4$vfs->getChild('5.php')->setContent('<?php echo "Hello World"; ?>');5$vfs->getChild('6.php')->setContent('<?php echo "Hello World"; ?>');6$vfs->getChild('7.php')->setContent('<?php echo "Hello World"; ?>');7$vfs->getChild('8.php')->setContent('<?php echo "Hello World"; ?>');8$vfs->getChild('9.php')->setContent('<?php echo "Hello World"; ?>');9$vfs->getChild('10.php')->setContent('<?php echo "Hello World"; ?>');10$vfs->getChild('11.php')->setContent('<?php echo "Hello World"; ?>');11$vfs->getChild('12.php')->setContent('<?php echo "Hello World"; ?>');12$vfs->getChild('13.php')->setContent('<?php echo "Hello World"; ?>');13$vfs->getChild('14.php')->setContent('<?php echo "Hello World"; ?>');

Full Screen

Full Screen

setContent

Using AI Code Generation

copy

Full Screen

1$root->getChild('file.txt')->setContent('some content');2$root->getChild('file.txt')->getContent();3$root->getChild('file.txt')->setContent('some content');4$root->getChild('file.txt')->getContent();5$root->getChild('file.txt')->setContent('some content');6$root->getChild('file.txt')->getContent();7$root->getChild('file.txt')->setContent('some content');8$root->getChild('file.txt')->getContent();9$root->getChild('file.txt')->setContent('some content');10$root->getChild('file.txt')->getContent();11$root->getChild('file.txt')->setContent('some content');12$root->getChild('file.txt')->getContent();13$root->getChild('file.txt')->setContent('some content');14$root->getChild('file.txt')->getContent();15$root->getChild('file.txt')->setContent('some content');16$root->getChild('file.txt')->getContent();17$root->getChild('file.txt')->setContent('some content');18$root->getChild('file.txt')->getContent();19$root->getChild('file.txt')->setContent('some content

Full Screen

Full Screen

setContent

Using AI Code Generation

copy

Full Screen

1$root->getChild('test.txt')->setContent('Hello World');2echo $root->getChild('test.txt')->getContent();3echo $root->getChild('test.txt')->getURL();4echo $root->getChild('test.txt')->getPermissions();5$root->getChild('test.txt')->setPermissions(0777);6echo $root->getChild('test.txt')->getPermissions();7echo $root->getChild('test.txt')->getGroup();8$root->getChild('test.txt')->setGroup('www-data');9echo $root->getChild('test.txt')->getGroup();10echo $root->getChild('test.txt')->getOwner();11$root->getChild('test.txt')->setOwner('apache');12echo $root->getChild('test.txt')->getOwner();13echo $root->getChild('test.txt')->getLinkTarget();

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run VfsStream automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger setContent code on LambdaTest Cloud Grid

Execute automation tests with setContent on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful