From 3b603687999ce51e3ebec10491f148afa3ff45ed Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Tue, 20 Dec 2016 20:46:36 +0000 Subject: [PATCH] rename split test variation to url redirect variation --- README.md | 2 +- docs/InnoCraft-Experiments-Experiment.md | 16 ++- ...xperiments-Variations-CallableVariation.md | 4 +- ...riments-Variations-UrlRedirectVariation.md | 111 ++++++++++++++++++ docs/README.md | 2 +- docs/generateDocs.sh | 2 +- examples/ab_test.php | 2 +- examples/callable_test.php | 2 +- .../{split_test.php => url_redirect_test.php} | 2 - src/Variations.php | 4 +- src/Variations/CallableVariation.php | 4 + ...Variation.php => UrlRedirectVariation.php} | 5 +- ...nTest.php => UrlRedirectVariationTest.php} | 6 +- tests/VariationsTest.php | 8 +- 14 files changed, 141 insertions(+), 29 deletions(-) create mode 100644 docs/InnoCraft-Experiments-Variations-UrlRedirectVariation.md rename examples/{split_test.php => url_redirect_test.php} (93%) rename src/Variations/{SplitTestVariation.php => UrlRedirectVariation.php} (91%) rename tests/Variations/{SplitTestVariationTest.php => UrlRedirectVariationTest.php} (90%) diff --git a/README.md b/README.md index 793e891..be3cf78 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ $activated = $experiment->getActivatedVariation(); echo $activated->getName(); ``` -Running a split test can be as easy as: +Running a split URL test can be as easy as: ```php $variations = [ diff --git a/docs/InnoCraft-Experiments-Experiment.md b/docs/InnoCraft-Experiments-Experiment.md index b479544..b0d4dfd 100644 --- a/docs/InnoCraft-Experiments-Experiment.md +++ b/docs/InnoCraft-Experiments-Experiment.md @@ -155,7 +155,7 @@ Get the set storage. ### trackVariationActivation - mixed InnoCraft\Experiments\Experiment::trackVariationActivation(\stdClass|\PiwikTracker $tracker, string $experimentName, string $variation) + mixed InnoCraft\Experiments\Experiment::trackVariationActivation(\stdClass|\PiwikTracker $tracker) Tracks the activation of a variation using for example the Piwik Tracker. This lets Piwik know which variation was activated and should be used if you track your application using the Piwik Tracker server side. If you are @@ -164,19 +164,17 @@ usually tracking using the JavaScript Tracker, have a look at {@link getTracking * Visibility: **public** -* This method is **static**. #### Arguments -* $tracker **stdClass|PiwikTracker** -* $experimentName **string** -* $variation **string** +* $tracker **stdClass|PiwikTracker** - <p>The passed object needs to implement a <code>doTrackEvent</code> method accepting +three parameters $category, $action, $name</p> ### getTrackingScript - string InnoCraft\Experiments\Experiment::getTrackingScript(string $experimentName, string $variation) + string InnoCraft\Experiments\Experiment::getTrackingScript(string $experimentName, string $variationName) Returns the JavaScript tracking code that you can echo in your website to let Piwik know which variation was activated server side. @@ -185,11 +183,11 @@ Do not pass variables from $_GET or $_POST etc. Make sure to escape the variable to this method as you would otherwise risk an XSS. * Visibility: **public** -* This method is **static**. #### Arguments -* $experimentName **string** -* $variation **string** +* $experimentName **string** - <p>ExperimentName and VariationName needs to be passed cause we do not yet have a way + here to properly escape it to prevent XSS.</p> +* $variationName **string** diff --git a/docs/InnoCraft-Experiments-Variations-CallableVariation.md b/docs/InnoCraft-Experiments-Variations-CallableVariation.md index a69d281..76f7fa2 100644 --- a/docs/InnoCraft-Experiments-Variations-CallableVariation.md +++ b/docs/InnoCraft-Experiments-Variations-CallableVariation.md @@ -22,9 +22,9 @@ Methods ### getCallable - mixed InnoCraft\Experiments\Variations\CallableVariation::getCallable() - + callable InnoCraft\Experiments\Variations\CallableVariation::getCallable() +Returns a callable if the option was passed. diff --git a/docs/InnoCraft-Experiments-Variations-UrlRedirectVariation.md b/docs/InnoCraft-Experiments-Variations-UrlRedirectVariation.md new file mode 100644 index 0000000..3107131 --- /dev/null +++ b/docs/InnoCraft-Experiments-Variations-UrlRedirectVariation.md @@ -0,0 +1,111 @@ +InnoCraft\Experiments\Variations\UrlRedirectVariation +=============== + + + + + + +* Class name: UrlRedirectVariation +* Namespace: InnoCraft\Experiments\Variations +* Parent class: [InnoCraft\Experiments\Variations\StandardVariation](InnoCraft-Experiments-Variations-StandardVariation.md) + + + + + + + +Methods +------- + + +### __construct + + mixed InnoCraft\Experiments\Variations\StandardVariation::__construct(array $variation) + + + + + +* Visibility: **public** +* This method is defined by [InnoCraft\Experiments\Variations\StandardVariation](InnoCraft-Experiments-Variations-StandardVariation.md) + + +#### Arguments +* $variation **array** - <p>eg array('name' => 'blueColor', 'percentage' => 50). +A name has to be given and can be also an ID, eg "4". Percentage is optional. +If given, it defines how much traffic this variation should get. For example defining +50 means, this variation will be activated in 50% of overall experiment activations.</p> + + + +### getUrl + + mixed InnoCraft\Experiments\Variations\UrlRedirectVariation::getUrl() + + + + + +* Visibility: **public** + + + + +### getUrlWithExperimentParameters + + mixed InnoCraft\Experiments\Variations\UrlRedirectVariation::getUrlWithExperimentParameters() + + + + + +* Visibility: **public** + + + + +### run + + void InnoCraft\Experiments\Variations\VariationInterface::run() + +Runs / executes the given variation. Depending on the variation type a different action may be executed. + +For example a redirect or calling a callable. + +* Visibility: **public** +* This method is defined by [InnoCraft\Experiments\Variations\VariationInterface](InnoCraft-Experiments-Variations-VariationInterface.md) + + + + +### getName + + string InnoCraft\Experiments\Variations\VariationInterface::getName() + +Get the name of the variation. + + + +* Visibility: **public** +* This method is defined by [InnoCraft\Experiments\Variations\VariationInterface](InnoCraft-Experiments-Variations-VariationInterface.md) + + + + +### getPercentage + + string InnoCraft\Experiments\Variations\VariationInterface::getPercentage() + +Get the percentage allocated to this variation. Only returns a percentage if a fixed percentage was allocated +to this variation. If no percentage is allocated, it will use the default percentage of a variation which depends +on the number of set variations within an experiment. + + + +* Visibility: **public** +* This method is defined by [InnoCraft\Experiments\Variations\VariationInterface](InnoCraft-Experiments-Variations-VariationInterface.md) + + + diff --git a/docs/README.md b/docs/README.md index 8032e62..5790637 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,7 +18,7 @@ API Index * [Transient](InnoCraft-Experiments-Storage-Transient.md) * [Variations](InnoCraft-Experiments-Variations.md) * [CallableVariation](InnoCraft-Experiments-Variations-CallableVariation.md) - * [SplitTestVariation](InnoCraft-Experiments-Variations-SplitTestVariation.md) * [StandardVariation](InnoCraft-Experiments-Variations-StandardVariation.md) + * [UrlRedirectVariation](InnoCraft-Experiments-Variations-UrlRedirectVariation.md) * [VariationInterface](InnoCraft-Experiments-Variations-VariationInterface.md) diff --git a/docs/generateDocs.sh b/docs/generateDocs.sh index 50b8678..06a67f4 100755 --- a/docs/generateDocs.sh +++ b/docs/generateDocs.sh @@ -1,3 +1,3 @@ ./vendor/phpdocumentor/phpdocumentor/bin/phpdoc -d ../src/ -t xml/ --visibility="public" --template="xml" -./vendor/evert/phpdoc-md/bin/phpdocmd xml/structure.xml . --index="README.md" +./vendor/evert/phpdoc-md/bin/phpdocmd xml/structure.xml . --index README.md rm -rf xml \ No newline at end of file diff --git a/examples/ab_test.php b/examples/ab_test.php index 56daddc..a48ba4f 100644 --- a/examples/ab_test.php +++ b/examples/ab_test.php @@ -5,7 +5,7 @@ * * To see how to allocate different traffic to variations, how to force a variation and more have a look at * the other examples. If you want to fully customize the behaviour of an experiment, have a look at - * "customize_and_extend.php". If you want to perform a split test, have a look at "split_test.php". + * "customize_and_extend.php". If you want to perform a split test, have a look at "url_redirect_test.php". */ date_default_timezone_set('utc'); diff --git a/examples/callable_test.php b/examples/callable_test.php index e4f4287..c584783 100644 --- a/examples/callable_test.php +++ b/examples/callable_test.php @@ -28,4 +28,4 @@ // and possible other tools to know which variation was activated, 2 url parameters will be appended to the // URL $activated = $experiment->getActivatedVariation(); -$activated->run(); +$activated->run(); \ No newline at end of file diff --git a/examples/split_test.php b/examples/url_redirect_test.php similarity index 93% rename from examples/split_test.php rename to examples/url_redirect_test.php index 8394aa9..20cf0e1 100644 --- a/examples/split_test.php +++ b/examples/url_redirect_test.php @@ -3,8 +3,6 @@ * Example for a very simple split test where we have the original version (added automatically), * a layout1 variation and a layout2 variation. Each variation will be activated in 33.3% of the time * randomly. - * - * To learn more about all the possible configs have a look at "ab_test_withConfig.php". */ date_default_timezone_set('utc'); diff --git a/src/Variations.php b/src/Variations.php index 8fef259..0b6fa9e 100644 --- a/src/Variations.php +++ b/src/Variations.php @@ -10,7 +10,7 @@ use InvalidArgumentException; use InnoCraft\Experiments\Variations\CallableVariation; -use InnoCraft\Experiments\Variations\SplitTestVariation; +use InnoCraft\Experiments\Variations\UrlRedirectVariation; use InnoCraft\Experiments\Variations\StandardVariation; use InnoCraft\Experiments\Variations\VariationInterface; @@ -49,7 +49,7 @@ public function addVariation($variation) if (is_array($variation)) { // could be moved to a factory or so if (isset($variation['url'])) { - $this->variations[] = new SplitTestVariation($this->experimentName, $variation); + $this->variations[] = new UrlRedirectVariation($this->experimentName, $variation); } elseif (isset($variation['callable'])) { $this->variations[] = new CallableVariation($variation); } else { diff --git a/src/Variations/CallableVariation.php b/src/Variations/CallableVariation.php index 6951c6c..fabb7ba 100644 --- a/src/Variations/CallableVariation.php +++ b/src/Variations/CallableVariation.php @@ -10,6 +10,10 @@ class CallableVariation extends StandardVariation { + /** + * Returns a callable if the option was passed. + * @return callable + */ public function getCallable() { if (isset($this->variation['callable'])) { diff --git a/src/Variations/SplitTestVariation.php b/src/Variations/UrlRedirectVariation.php similarity index 91% rename from src/Variations/SplitTestVariation.php rename to src/Variations/UrlRedirectVariation.php index 00af472..d6d8015 100644 --- a/src/Variations/SplitTestVariation.php +++ b/src/Variations/UrlRedirectVariation.php @@ -8,7 +8,7 @@ namespace InnoCraft\Experiments\Variations; -class SplitTestVariation extends StandardVariation { +class UrlRedirectVariation extends StandardVariation { /** * @var string|int @@ -16,7 +16,8 @@ class SplitTestVariation extends StandardVariation { private $experimentName; /** - * SplitTestVariation constructor. + * A variation that can perform a redirect when passing a URL and executing the run method. + * * @param string|int $experimentName * @param array $variation */ diff --git a/tests/Variations/SplitTestVariationTest.php b/tests/Variations/UrlRedirectVariationTest.php similarity index 90% rename from tests/Variations/SplitTestVariationTest.php rename to tests/Variations/UrlRedirectVariationTest.php index 338e2e8..1338a4c 100644 --- a/tests/Variations/SplitTestVariationTest.php +++ b/tests/Variations/UrlRedirectVariationTest.php @@ -1,10 +1,10 @@ experimentName, $variation); + return new UrlRedirectVariation($this->experimentName, $variation); } } \ No newline at end of file diff --git a/tests/VariationsTest.php b/tests/VariationsTest.php index 4462438..590a4f0 100644 --- a/tests/VariationsTest.php +++ b/tests/VariationsTest.php @@ -2,7 +2,7 @@ use InnoCraft\Experiments\Variations; use InnoCraft\Experiments\Variations\StandardVariation; -use InnoCraft\Experiments\Variations\SplitTestVariation; +use InnoCraft\Experiments\Variations\UrlRedirectVariation; use InnoCraft\Experiments\Variations\CallableVariation; class CustomVariations extends Variations { @@ -50,7 +50,7 @@ public function test_shouldConvertVariationsToInstances() $this->assertCount(4, $variations); $this->assertTrue($variations[0] instanceof StandardVariation); $this->assertTrue($variations[1] instanceof StandardVariation); - $this->assertTrue($variations[2] instanceof SplitTestVariation); + $this->assertTrue($variations[2] instanceof UrlRedirectVariation); $this->assertTrue($variations[3] instanceof CallableVariation); } @@ -91,7 +91,7 @@ public function test_setVariations_overwritesExistingVariations_WorksFromArrayOr $this->assertSame(2, $variations->getNumVariations()); $allVariations = $variations->getVariations(); - $this->assertTrue($allVariations[0] instanceof SplitTestVariation); + $this->assertTrue($allVariations[0] instanceof UrlRedirectVariation); $this->assertSame('variation4', $allVariations[0]->getName()); $this->assertTrue($allVariations[1] instanceof StandardVariation); $this->assertSame('variation5', $allVariations[1]->getName()); @@ -112,7 +112,7 @@ public function test_addVariation_canAddNewVariationFromArray() $allVariations = $variations->getVariations(); // verify variation added and converted to VariationInterface - $this->assertTrue($allVariations[1] instanceof SplitTestVariation); + $this->assertTrue($allVariations[1] instanceof UrlRedirectVariation); $this->assertSame('variation4', $allVariations[1]->getName()); // verify old one not removed