function test_replace_word_partially() { //arrange $test_FindAndReplace = new FindAndReplace(); $inputString = "habitual"; $wordToReplace = "habit"; $replacementWord = "routine"; //act $result = $test_FindAndReplace->replaceWord($inputString, $wordToReplace, $replacementWord); //assert $this->assertEquals("routineual", $result); }
function test_FindAndReplace_multipleWords() { //Arrange $test_FindAndReplace = new FindAndReplace(); $string = "If I were an apple hanging on an tree"; $find = "an"; $change = "a"; //Act $result = $test_FindAndReplace->swapWords($string, $find, $change); //Assert $this->assertEquals("If I were a apple hanging on a tree", $result); }
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/FindAndReplace.php"; session_start(); $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . "/../views")); $app->get("/", function () use($app) { return $app["twig"]->render("home.html.twig"); }); $app->get("/results", function () use($app) { $new_FindAndReplace = new FindAndReplace($_GET["input_string"], $_GET["word_to_replace"], $_GET["replacement_word"]); $result = $new_FindAndReplace->replaceWord($_GET["input_string"], $_GET["word_to_replace"], $_GET["replacement_word"]); return $app["twig"]->render("home.html.twig", array("newresult" => $result, "originalinput" => $new_FindAndReplace)); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/FindAndReplace.php"; $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig', array('form' => true)); }); $app->get("/action", function () use($app) { $my_FindAndReplace = new FindAndReplace(); if ($_GET['button'] == 'whole') { // use the method for replacing whole words $message_text = $my_FindAndReplace->replaceWords($_GET['phrase'], $_GET['word-to-replace'], $_GET['replacement']); } else { // use the method for any letters $message_text = $my_FindAndReplace->replaceAnyMatch($_GET['phrase'], $_GET['word-to-replace'], $_GET['replacement']); } return $app['twig']->render('index.html.twig', array('form' => true, 'message' => array('text' => $message_text, 'type' => 'info'))); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/FindAndReplace.php"; $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); // End busy code -----------^ // Render Home Page $app->get("/", function () use($app) { return $app['twig']->render('findandreplace.html.twig'); // }); // User Input from form $app->get("/userInput", function () use($app) { $new_phrase = new FindAndReplace(); $result = $new_phrase->swapWords($_GET['sentence'], $_GET['find'], $_GET['change']); return $app['twig']->render('findandreplace.html.twig', array('result' => $result)); // }); return $app;
function test_replaceAnyMatch_sentenceMultipleMatch() { // Arrange $test_FindAndReplace = new FindAndReplace(); $phrase = 'The cat in the hat laughed at the catalogue.'; $word_to_replace = 'cat'; $replace_with = 'hotdog'; // Act $result = $test_FindAndReplace->replaceAnyMatch($phrase, $word_to_replace, $replace_with); // Assert $this->assertEquals('The hotdog in the hat laughed at the hotdogalogue.', $result); }