Skip to content

Commit

Permalink
Added new Mocks for response testing
Browse files Browse the repository at this point in the history
  • Loading branch information
DaGhostman committed May 12, 2015
1 parent 50b5bf2 commit 85945c3
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/Stub/MockQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
namespace Stub;

use Wave\Framework\Interfaces\Http\QueryInterface;

class MockQuery implements QueryInterface
{

private $params = [];
/**
* Allows constructor injection of the query string,
* or already parsed array with parameters.
*
* @param string|array $query
*/
public function __construct($query = null) {}

/**
* Return a parameter with $name
*
* @param string $name
*
* @return mixed
*/
public function get($name)
{
return $this->params[$name];
}

/**
* Add a new parameter
*
* @param string $name
* @param mixed $value
*
* @return mixed
*/
public function set ($name, $value)
{
// TODO: Implement set() method.
}

/**
* Check if a parameter exists
*
* @param string $name
*
* @return mixed
*/
public function has ($name) {}

/**
* Remove a parameter
*
* @param string $name
*/
public function remove ($name) {}

/**
* Import a new set parameters. The new parameters should be
* appended to the current list and not replacing one for the other.
*
* @param array $parameters
*
* @return mixed
*/
public function import (array $parameters)
{
$this->params = $parameters;

return $this;
}

public function __toString ()
{
return http_build_query($this->params);
}
}
165 changes: 165 additions & 0 deletions tests/Stub/MockUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php
namespace Stub;

use Wave\Framework\Interfaces\Http\QueryInterface;
use Wave\Framework\Interfaces\Http\UrlInterface;

class MockUrl implements UrlInterface
{
private $scheme;
private $host;
private $port;
private $path;
private $query;
private $fragment;

/**
* Adds all mandatory fields for the URL, the only needed part is $path,
* as it is always present, others can be safely omitted, although $path
* can be set to default to '/' it is not recommended to make the code
* more self-explanatory.
*
* @param string $path The path of the request
* @param QueryInterface $query Object representing the current query
* @param string $host the host name to use in the URL
* @param int $port A valid port number from 1 - 65535
* @param string $scheme the scheme of the request (in case of 'file://' urls,
* make sure to use a standard http port [80|443])
* @param string $fragment
*/
public function __construct ($path = '/', QueryInterface $query = null, $host = '', $port = 80, $scheme = 'http', $fragment = null)
{
$this->scheme = $scheme;
$this->path = $path;
$this->host = $host;
$this->port = $port;
$this->query = $query;
$this->fragment = $fragment;
}

/**
* @return string|null
*/
public function getScheme ()
{
return $this->scheme;
}

/**
* @return string|null
*/
public function getHost ()
{
return $this->host;
}

/**
* @return int|null
*/
public function getPort ()
{
return $this->port;
}

/**
* @return string
*/
public function getPath ()
{
return $this->path;
}

/**
* @return QueryInterface
*/
public function getQuery ()
{
return $this->query;
}

/**
* @return string|null
*/
public function getFragment ()
{
return $this->fragment;
}

/**
* @param string $scheme
*
* @return mixed
*/
public function setScheme ($scheme)
{
$this->scheme = $scheme;

return $this;
}

/**
* @param string $host
*
* @return mixed
*/
public function setHost ($host)
{
$this->host = $host;

return $this;
}

/**
* @param int $port
*
* @return mixed
*/
public function setPort ($port)
{
$this->port = (int) $port;

return $this;
}

/**
* @param string $path
*
* @return mixed
*/
public function setPath ($path)
{
$this->path = $path;

return $this;
}

/**
* @param QueryInterface $query
*
* @return mixed
*/
public function setQuery (QueryInterface $query)
{
$this->query = $query;

return $this;
}

/**
* @param string $fragment
*
* @return mixed
*/
public function setFragment ($fragment)
{
$this->fragment = $fragment;
}

/**
* @return string
*/
public function __toString ()
{
return $this->scheme . '://' . $this->host . $this->path . '?' . $this->query;
}
}

0 comments on commit 85945c3

Please sign in to comment.