Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2015-04-13 03:30:19 +0300
committerThomas Steur <thomas.steur@gmail.com>2015-04-13 05:56:44 +0300
commit2945b1cd43d8baeea61d70475e121bfc920e72e0 (patch)
tree13bd82a4bc3cff43f6f6ff977b397d6bc02c71b6 /tests/PHPUnit/Framework/Constraint
parentbd9efbb7341f0d6b1d650949c3de82f82f81e165 (diff)
refs piwik/piwik-log-analytics#57 return a http 400 if no request is set
Diffstat (limited to 'tests/PHPUnit/Framework/Constraint')
-rw-r--r--tests/PHPUnit/Framework/Constraint/HttpResponseText.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/PHPUnit/Framework/Constraint/HttpResponseText.php b/tests/PHPUnit/Framework/Constraint/HttpResponseText.php
new file mode 100644
index 0000000000..54d7098262
--- /dev/null
+++ b/tests/PHPUnit/Framework/Constraint/HttpResponseText.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+namespace Piwik\Tests\Framework\Constraint;
+
+class HttpResponseText extends \PHPUnit_Framework_Constraint
+{
+ private $actualCode;
+
+ /**
+ * @param string $value Expected response text.
+ */
+ public function __construct($value)
+ {
+ parent::__construct();
+ $this->value = $value;
+ }
+
+ /**
+ * Evaluates the constraint for parameter $other. Returns TRUE if the
+ * constraint is met, FALSE otherwise.
+ *
+ * @param mixed $other Value or object to evaluate.
+ * @return bool
+ */
+ public function matches($other)
+ {
+ $options = array(
+ CURLOPT_URL => $other,
+ CURLOPT_HEADER => false,
+ CURLOPT_TIMEOUT => 1,
+ CURLOPT_RETURNTRANSFER => true
+ );
+
+ $ch = curl_init();
+ curl_setopt_array($ch, $options);
+ $response = @curl_exec($ch);
+ curl_close($ch);
+
+ $this->actualCode = $response;
+
+ return $this->value === $this->actualCode;
+ }
+
+ /**
+ * Returns a string representation of the constraint.
+ *
+ * @return string
+ */
+ public function toString()
+ {
+ return 'does not return response text ' . $this->exporter->export($this->value) . ' it is ' . $this->actualCode;
+ }
+}?> \ No newline at end of file