Ver Fonte

Undoing some automatic formatting by scrutinizer

Jonny Wenmoth há 11 anos atrás
pai
commit
6c92d3502d

+ 36 - 41
src/JonnyW/PhantomJs/Client.php

@@ -8,7 +8,6 @@
  */
 namespace JonnyW\PhantomJs;
 
-use JonnyW\PhantomJs\ClientInterface;
 use JonnyW\PhantomJs\Exception\NoPhantomJsException;
 use JonnyW\PhantomJs\Exception\CommandFailedException;
 use JonnyW\PhantomJs\Exception\NotWriteableException;
@@ -27,14 +26,14 @@ class Client implements ClientInterface
     /**
      * Client instance
      *
-     * @var JonnyW\PhantomJs\ClientInterface
+     * @var \JonnyW\PhantomJs\ClientInterface
      */
     private static $instance;
 
     /**
      * Message factory instance
      *
-     * @var JonnyW\PhantomJs\Message\FactoryInterface
+     * @var \JonnyW\PhantomJs\Message\FactoryInterface
      */
     protected $factory;
 
@@ -55,7 +54,7 @@ class Client implements ClientInterface
     /**
      * Internal constructor
      *
-     * @param  FactoryInterface $factory
+     * @param  \JonnyW\PhantomJs\Message\FactoryInterface $factory
      * @return void
      */
     public function __construct(FactoryInterface $factory = null)
@@ -64,16 +63,16 @@ class Client implements ClientInterface
             $factory = Factory::getInstance();
         }
 
-        $this->factory  = $factory;
-        $this->phantomJS  = 'bin/phantomjs';
+        $this->factory   = $factory;
+        $this->phantomJS = 'bin/phantomjs';
         $this->timeout   = 5000;
     }
 
     /**
      * Get singleton instance
      *
-     * @param  FactoryInterface $factory
-     * @return Client
+     * @param  \JonnyW\PhantomJs\Message\FactoryInterface $factory
+     * @return \JonnyW\PhantomJs\Client
      */
     public static function getInstance(FactoryInterface $factory = null)
     {
@@ -87,7 +86,7 @@ class Client implements ClientInterface
     /**
      * Get message factory instance
      *
-     * @return JonnyW\PhantomJs\Message\FactoryInterface
+     * @return \JonnyW\PhantomJs\Message\FactoryInterface
      */
     public function getMessageFactory()
     {
@@ -97,10 +96,10 @@ class Client implements ClientInterface
     /**
      * Send request
      *
-     * @param  RequestInterface  $request
-     * @param  ResponseInterface $response
-     * @param  string            $file
-     * @return ResponseInterface
+     * @param  \JonnyW\PhantomJs\Message\RequestInterface  $request
+     * @param  \JonnyW\PhantomJs\Message\ResponseInterface $response
+     * @param  string                                      $file
+     * @return \JonnyW\PhantomJs\Message\ResponseInterface
      */
     public function send(RequestInterface $request, ResponseInterface $response, $file = null)
     {
@@ -114,14 +113,14 @@ class Client implements ClientInterface
     /**
      * Open page
      *
-     * @param  RequestInterface  $request
-     * @param  ResponseInterface $response
-     * @return ResponseInterface
+     * @param  \JonnyW\PhantomJs\Message\RequestInterface  $request
+     * @param  \JonnyW\PhantomJs\Message\ResponseInterface $response
+     * @return \JonnyW\PhantomJs\Message\ResponseInterface
      */
     public function open(RequestInterface $request, ResponseInterface $response, $delay = 0)
     {
         if ($delay) {
-            $cmd = sprintf($this->openCmdWithDelay, $delay);   
+            $cmd = sprintf($this->openCmdWithDelay, $delay);
         } else {
             $cmd = $this->openCmd;
         }
@@ -132,10 +131,10 @@ class Client implements ClientInterface
     /**
      * Screen capture
      *
-     * @param  RequestInterface  $request
-     * @param  ResponseInterface $response
-     * @param  string            $file
-     * @return ResponseInterface
+     * @param  \JonnyW\PhantomJs\Message\RequestInterface  $request
+     * @param  \JonnyW\PhantomJs\Message\ResponseInterface $response
+     * @param  string                                      $file
+     * @return \JonnyW\PhantomJs\Message\ResponseInterface
      */
     public function capture(RequestInterface $request, ResponseInterface $response, $file)
     {
@@ -151,8 +150,8 @@ class Client implements ClientInterface
     /**
      * Set new PhantomJs path
      *
-     * @param  string $path
-     * @return Client
+     * @param  string                   $path
+     * @return \JonnyW\PhantomJs\Client
      */
     public function setPhantomJs($path)
     {
@@ -168,8 +167,8 @@ class Client implements ClientInterface
     /**
      * Set timeout period (in milliseconds)
      *
-     * @param  int    $period
-     * @return Client
+     * @param  int                      $period
+     * @return \JonnyW\PhantomJs\Client
      */
     public function setTimeout($period)
     {
@@ -181,10 +180,10 @@ class Client implements ClientInterface
     /**
      * Make PhantomJS request
      *
-     * @param  RequestInterface  $request
-     * @param  ResponseInterface $response
-     * @param  string            $cmd
-     * @return ResponseInterface
+     * @param  \JonnyW\PhantomJs\Message\RequestInterface  $request
+     * @param  \JonnyW\PhantomJs\Message\ResponseInterface $response
+     * @param  string                                      $cmd
+     * @return \JonnyW\PhantomJs\Message\ResponseInterface
      */
     protected function request(RequestInterface $request, ResponseInterface $response, $cmd)
     {
@@ -207,8 +206,6 @@ class Client implements ClientInterface
                 $request->getBody(),
                 $cmd
             );
-            
-
 
             $script = $this->writeScript($data);
             $cmd  = escapeshellcmd(sprintf("%s %s", $this->phantomJS, $script));
@@ -261,8 +258,8 @@ class Client implements ClientInterface
     /**
      * Remove temporary script file
      *
-     * @param  string|boolean $file
-     * @return Client
+     * @param  string|boolean           $file
+     * @return \JonnyW\PhantomJs\Client
      */
     protected function removeScript($file)
     {
@@ -326,7 +323,7 @@ class Client implements ClientInterface
         } else {
             console.log(JSON.stringify(response, undefined, 4));
             phantom.exit();
-        }        
+        }
     });
 EOF;
 
@@ -364,26 +361,24 @@ EOF;
             phantom.exit();
 EOF;
 
- /**
+    /**
      * PhantomJs page open
-     * command template
+     * command template with
+     * delay
      *
      * @var string
      */
     protected $openCmdWithDelay = <<<EOF
 
-        window.setTimeout(function(){
-
+        window.setTimeout(function () {
 
             response.content = page.evaluate(function () {
                 return document.getElementsByTagName('html')[0].innerHTML
             });
 
-            
             console.log(JSON.stringify(response, undefined, 4));
-            phantom.exit();            
+            phantom.exit();
 
         }, %s);
-
 EOF;
 }

+ 13 - 13
src/JonnyW/PhantomJs/ClientInterface.php

@@ -21,37 +21,37 @@ interface ClientInterface
     /**
      * Send request
      *
-     * @param  RequestInterface  $request
-     * @param  ResponseInterface $response
-     * @param  string            $file
-     * @return ResponseInterface
+     * @param  \JonnyW\PhantomJs\Message\RequestInterface  $request
+     * @param  \JonnyW\PhantomJs\Message\ResponseInterface $response
+     * @param  string                                      $file
+     * @return \JonnyW\PhantomJs\Message\ResponseInterface
      */
     public function send(RequestInterface $request, ResponseInterface $response, $file = null);
 
     /**
      * Open page
      *
-     * @param  RequestInterface  $request
-     * @param  ResponseInterface $response
-     * @return ResponseInterface
+     * @param  \JonnyW\PhantomJs\Message\RequestInterface  $request
+     * @param  \JonnyW\PhantomJs\Message\ResponseInterface $response
+     * @return \JonnyW\PhantomJs\Message\ResponseInterface
      */
     public function open(RequestInterface $request, ResponseInterface $response);
 
     /**
      * Screen capture
      *
-     * @param  RequestInterface  $request
-     * @param  ResponseInterface $response
-     * @param  string            $file
-     * @return ResponseInterface
+     * @param  \JonnyW\PhantomJs\Message\RequestInterface  $request
+     * @param  \JonnyW\PhantomJs\Message\ResponseInterface $response
+     * @param  string                                      $file
+     * @return \JonnyW\PhantomJs\Message\ResponseInterface
      */
     public function capture(RequestInterface $request, ResponseInterface $response, $file);
 
     /**
      * Set new PhantomJs path
      *
-     * @param  string $path
-     * @return Client
+     * @param  string                   $path
+     * @return \JonnyW\PhantomJs\Client
      */
     public function setPhantomJs($path);
 }

+ 6 - 11
src/JonnyW/PhantomJs/Message/Factory.php

@@ -8,11 +8,6 @@
  */
 namespace JonnyW\PhantomJs\Message;
 
-use JonnyW\PhantomJs\Message\FactoryInterface;
-use JonnyW\PhantomJs\Message\RequestInterface;
-use JonnyW\PhantomJs\Message\Request;
-use JonnyW\PhantomJs\Message\Response;
-
 /**
  * PHP PhantomJs
  *
@@ -23,14 +18,14 @@ class Factory implements FactoryInterface
     /**
      * Client instance
      *
-     * @var JonnyW\PhantomJs\Message\FactoryInterface
+     * @var \JonnyW\PhantomJs\Message\FactoryInterface
      */
     private static $instance;
 
     /**
      * Get singleton instance
      *
-     * @return Factory
+     * @return \JonnyW\PhantomJs\Message\Factory
      */
     public static function getInstance()
     {
@@ -44,9 +39,9 @@ class Factory implements FactoryInterface
     /**
      * Create request instance
      *
-     * @param  string  $method
-     * @param  string  $url
-     * @return Request
+     * @param  string                            $method
+     * @param  string                            $url
+     * @return \JonnyW\PhantomJs\Message\Request
      */
     public function createRequest($method = RequestInterface::METHOD_GET, $url = null)
     {
@@ -56,7 +51,7 @@ class Factory implements FactoryInterface
     /**
      * Create response instance
      *
-     * @return Response
+     * @return \JonnyW\PhantomJs\Message\Response
      */
     public function createResponse()
     {

+ 4 - 6
src/JonnyW/PhantomJs/Message/FactoryInterface.php

@@ -8,8 +8,6 @@
  */
 namespace JonnyW\PhantomJs\Message;
 
-use JonnyW\PhantomJs\Message\RequestInterface;
-
 /**
  * PHP PhantomJs
  *
@@ -27,16 +25,16 @@ interface FactoryInterface
     /**
      * Create request instance
      *
-     * @param  string  $url
-     * @param  string  $method
-     * @return Request
+     * @param  string                                     $url
+     * @param  string                                     $method
+     * @return \JonnyW\PhantomJs\Message\RequestInterface
      */
     public function createRequest($url, $method = RequestInterface::METHOD_GET);
 
     /**
      * Create response instance
      *
-     * @return Response
+     * @return \JonnyW\PhantomJs\Message\ResoibseInterface
      */
     public function createResponse();
 }

+ 13 - 14
src/JonnyW/PhantomJs/Message/Request.php

@@ -9,7 +9,6 @@
 
 namespace JonnyW\PhantomJs\Message;
 
-use JonnyW\PhantomJs\Message\RequestInterface;
 use JonnyW\PhantomJs\Exception\InvalidUrlException;
 use JonnyW\PhantomJs\Exception\InvalidMethodException;
 
@@ -70,8 +69,8 @@ class Request implements RequestInterface
     /**
      * Set request method
      *
-     * @param  string  $method
-     * @return Request
+     * @param  string                            $method
+     * @return \JonnyW\PhantomJs\Message\Request
      */
     public function setMethod($method)
     {
@@ -101,8 +100,8 @@ class Request implements RequestInterface
     /**
      * Set request URL
      *
-     * @param  string  $url
-     * @return Request
+     * @param  string                            $url
+     * @return \JonnyW\PhantomJs\Message\Request
      */
     public function setUrl($url)
     {
@@ -159,8 +158,8 @@ class Request implements RequestInterface
     /**
      * Set request data
      *
-     * @param  array   $data
-     * @return Request
+     * @param  array                             $data
+     * @return \JonnyW\PhantomJs\Message\Request
      */
     public function setRequestData(array $data)
     {
@@ -216,8 +215,8 @@ class Request implements RequestInterface
     /**
      * Set headers
      *
-     * @param  array                            $headers
-     * @return JonnyW\PhantomJs\Message\Request
+     * @param  array                             $headers
+     * @return \JonnyW\PhantomJs\Message\Request
      */
     public function setHeaders(array $headers)
     {
@@ -227,9 +226,9 @@ class Request implements RequestInterface
     /**
      * Add single header
      *
-     * @param  string  $header
-     * @param  string  $value
-     * @return Request
+     * @param  string                            $header
+     * @param  string                            $value
+     * @return \JonnyW\PhantomJs\Message\Request
      */
     public function addHeader($header, $value)
     {
@@ -241,8 +240,8 @@ class Request implements RequestInterface
     /**
      * Merge headers with existing
      *
-     * @param  array   $headers
-     * @return Request
+     * @param  array                             $headers
+     * @return \JonnyW\PhantomJs\Message\Request
      */
     public function addHeaders(array $headers)
     {

+ 13 - 13
src/JonnyW/PhantomJs/Message/RequestInterface.php

@@ -27,8 +27,8 @@ interface RequestInterface
     /**
      * Set request method
      *
-     * @param  string  $method
-     * @return Request
+     * @param  string                                     $method
+     * @return \JonnyW\PhantomJs\Message\RequestInterface
      */
     public function setMethod($method);
 
@@ -42,8 +42,8 @@ interface RequestInterface
     /**
      * Set request URL
      *
-     * @param  string  $url
-     * @return Request
+     * @param  string                                     $url
+     * @return \JonnyW\PhantomJs\Message\RequestInterface
      */
     public function setUrl($url);
 
@@ -67,8 +67,8 @@ interface RequestInterface
     /**
      * Set request data
      *
-     * @param  array   $data
-     * @return Request
+     * @param  array                                      $data
+     * @return \JonnyW\PhantomJs\Message\RequestInterface
      */
     public function setRequestData(array $data);
 
@@ -83,25 +83,25 @@ interface RequestInterface
     /**
      * Set headers
      *
-     * @param  array                                 $headers
-     * @return JonnyW\PhantomJs\Message\Request|null
+     * @param  array                                      $headers
+     * @return \JonnyW\PhantomJs\Message\RequestInterface
      */
     public function setHeaders(array $headers);
 
     /**
      * Add single header
      *
-     * @param  string  $header
-     * @param  string  $value
-     * @return Request
+     * @param  string                                     $header
+     * @param  string                                     $value
+     * @return \JonnyW\PhantomJs\Message\RequestInterface
      */
     public function addHeader($header, $value);
 
     /**
      * Merge headers with existing
      *
-     * @param  array   $headers
-     * @return Request
+     * @param  array                                      $headers
+     * @return \JonnyW\PhantomJs\Message\RequestInterface
      */
     public function addHeaders(array $headers);
 

+ 3 - 5
src/JonnyW/PhantomJs/Message/Response.php

@@ -8,8 +8,6 @@
  */
 namespace JonnyW\PhantomJs\Message;
 
-use JonnyW\PhantomJs\Message\ResponseInterface;
-
 /**
  * PHP PhantomJs
  *
@@ -69,7 +67,7 @@ class Response implements ResponseInterface
     /**
      * Set response data
      *
-     * @return Response
+     * @return \JonnyW\PhantomJs\Message\Response
      */
     public function setData(array $data)
     {
@@ -116,8 +114,8 @@ class Response implements ResponseInterface
     /**
      * Set headers array
      *
-     * @param array $headers
-     *                       @return
+     * @param  array                              $headers
+     * @return \JonnyW\PhantomJs\Message\Response
      */
     protected function setHeaders(array $headers)
     {

+ 1 - 1
src/JonnyW/PhantomJs/Message/ResponseInterface.php

@@ -19,7 +19,7 @@ interface ResponseInterface
     /**
      * Set response data
      *
-     * @return Response
+     * @return \JonnyW\PhantomJs\Message\ResponseInterface
      */
     public function setData(array $data);
 

+ 124 - 124
test/JonnyW/PhantomJs/Test/ClientTest.php

@@ -17,127 +17,127 @@ use JonnyW\PhantomJs\Client;
  */
 class ClientTest extends \PHPUnit_Framework_TestCase
 {
-	/**
-	 * Client instance
-	 *
-	 * @var JonnyW\PhantomJs\Client
-	 */
-	protected $client;
-
-	/**
-	 * Setup tests
-	 *
-	 * @return void
-	 */
-	protected function setUp()
-	{
-		parent::setUp();
-
-		$this->client = Client::getInstance();
-	}
-
-	/**
-	 * Test get factory instance
-	 *
-	 * @return void
-	 */
-	public function testMessageFactoryInstance()
-	{
-		$factory = $this->client->getMessageFactory();
-
-		$this->assertInstanceOf('JonnyW\PhantomJs\Message\FactoryInterface', $factory);
-	}
-
-	/**
-	 * Test exception is thrown when
-	 * PhantomJS executable cannot be run
-	 *
-	 * @return void
-	 */
-	public function testBinNotExecutable()
-	{
-		$this->setExpectedException('JonnyW\PhantomJs\Exception\NoPhantomJsException');
-
-		$this->client->setPhantomJs('/path/does/not/exist/phantomjs');
-	}
-
-	/**
-	 * Test exception is thrown when capture
-	 * path is not writeable
-	 *
-	 * @return void
-	 */
-	public function testPathNotWriteable()
-	{
-		$this->setExpectedException('JonnyW\PhantomJs\Exception\NotWriteableException');
-
-		$request  = $this->getMock('JonnyW\PhantomJs\Message\Request', null, array('method' => 'GET', 'url' => 'http://jonnyw.me'));
-		$response  = $this->getMock('JonnyW\PhantomJs\Message\Response', null);
-
-		$this->client->send($request, $response, 'path/does/not/exist/phantoms.png');
-	}
-
-	/**
-	 * Test open page
-	 *
-	 * @return void
-	 */
-	public function testOpenPage()
-	{
-		$client  = $this->getMock('JonnyW\PhantomJs\Client', array('request'));
-		$request  = $this->getMock('JonnyW\PhantomJs\Message\Request', null, array('method' => 'GET', 'url' => 'http://jonnyw.me'));
-		$response  = $this->getMock('JonnyW\PhantomJs\Message\Response', null);
-
-		$client->expects($this->once())
-		->method('request')
-		->will($this->returnValue($response));
-
-		$actual = $client->send($request, $response);
-
-		$this->assertSame($response, $actual);
-	}
-
-	/**
-	 * Test screen capture page
-	 *
-	 * @return void
-	 */
-	public function testCapturePage()
-	{
-		$client  = $this->getMock('JonnyW\PhantomJs\Client', array('request'));
-		$request  = $this->getMock('JonnyW\PhantomJs\Message\Request', null, array('method' => 'GET', 'url' => 'http://jonnyw.me'));
-		$response  = $this->getMock('JonnyW\PhantomJs\Message\Response', null);
-
-		$client->expects($this->once())
-		->method('request')
-		->will($this->returnValue($response));
-
-		$actual = $client->send($request, $response, '/tmp/testing.png');
-
-		$this->assertSame($response, $actual);
-	}
-
-	/**
-	 * Test page is redirect
-	 *
-	 * @return void
-	 */
-	public function testRedirectPage()
-	{
-		$client  = $this->getMock('JonnyW\PhantomJs\Client', array('request'));
-		$request  = $this->getMock('JonnyW\PhantomJs\Message\Request', null, array('method' => 'GET', 'url' => 'http://jonnyw.me'));
-		$response  = $this->getMock('JonnyW\PhantomJs\Message\Response', array('getStatus'));
-
-		$client->expects($this->once())
-		->method('request')
-		->will($this->returnValue($response));
-
-		$response->expects($this->once())
-		->method('getStatus')
-		->will($this->returnValue(301));
-
-		$actual = $client->send($request, $response);
-
-		$this->assertTrue($actual->isRedirect());
-	}
-}
+    /**
+     * Client instance
+     *
+     * @var \JonnyW\PhantomJs\Client
+     */
+    protected $client;
+
+    /**
+     * Setup tests
+     *
+     * @return void
+     */
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $this->client = Client::getInstance();
+    }
+
+    /**
+     * Test get factory instance
+     *
+     * @return void
+     */
+    public function testMessageFactoryInstance()
+    {
+        $factory = $this->client->getMessageFactory();
+
+        $this->assertInstanceOf('JonnyW\PhantomJs\Message\FactoryInterface', $factory);
+    }
+
+    /**
+     * Test exception is thrown when
+     * PhantomJS executable cannot be run
+     *
+     * @return void
+     */
+    public function testBinNotExecutable()
+    {
+        $this->setExpectedException('JonnyW\PhantomJs\Exception\NoPhantomJsException');
+
+        $this->client->setPhantomJs('/path/does/not/exist/phantomjs');
+    }
+
+    /**
+     * Test exception is thrown when capture
+     * path is not writeable
+     *
+     * @return void
+     */
+    public function testPathNotWriteable()
+    {
+        $this->setExpectedException('JonnyW\PhantomJs\Exception\NotWriteableException');
+
+        $request  = $this->getMock('JonnyW\PhantomJs\Message\Request', null, array('method' => 'GET', 'url' => 'http://jonnyw.me'));
+        $response  = $this->getMock('JonnyW\PhantomJs\Message\Response', null);
+
+        $this->client->send($request, $response, 'path/does/not/exist/phantoms.png');
+    }
+
+    /**
+     * Test open page
+     *
+     * @return void
+     */
+    public function testOpenPage()
+    {
+        $client  = $this->getMock('JonnyW\PhantomJs\Client', array('request'));
+        $request  = $this->getMock('JonnyW\PhantomJs\Message\Request', null, array('method' => 'GET', 'url' => 'http://jonnyw.me'));
+        $response  = $this->getMock('JonnyW\PhantomJs\Message\Response', null);
+
+        $client->expects($this->once())
+        ->method('request')
+        ->will($this->returnValue($response));
+
+        $actual = $client->send($request, $response);
+
+        $this->assertSame($response, $actual);
+    }
+
+    /**
+     * Test screen capture page
+     *
+     * @return void
+     */
+    public function testCapturePage()
+    {
+        $client  = $this->getMock('JonnyW\PhantomJs\Client', array('request'));
+        $request  = $this->getMock('JonnyW\PhantomJs\Message\Request', null, array('method' => 'GET', 'url' => 'http://jonnyw.me'));
+        $response  = $this->getMock('JonnyW\PhantomJs\Message\Response', null);
+
+        $client->expects($this->once())
+        ->method('request')
+        ->will($this->returnValue($response));
+
+        $actual = $client->send($request, $response, '/tmp/testing.png');
+
+        $this->assertSame($response, $actual);
+    }
+
+    /**
+     * Test page is redirect
+     *
+     * @return void
+     */
+    public function testRedirectPage()
+    {
+        $client  = $this->getMock('JonnyW\PhantomJs\Client', array('request'));
+        $request  = $this->getMock('JonnyW\PhantomJs\Message\Request', null, array('method' => 'GET', 'url' => 'http://jonnyw.me'));
+        $response  = $this->getMock('JonnyW\PhantomJs\Message\Response', array('getStatus'));
+
+        $client->expects($this->once())
+        ->method('request')
+        ->will($this->returnValue($response));
+
+        $response->expects($this->once())
+        ->method('getStatus')
+        ->will($this->returnValue(301));
+
+        $actual = $client->send($request, $response);
+
+        $this->assertTrue($actual->isRedirect());
+    }
+}

+ 43 - 43
test/JonnyW/PhantomJs/Test/Message/FactoryTest.php

@@ -17,46 +17,46 @@ use JonnyW\PhantomJs\Message\Factory;
  */
 class FactoryTest extends \PHPUnit_Framework_TestCase
 {
-	/**
-	 * Factory instance
-	 *
-	 * @var JonnyW\PhantomJs\Message\Factory
-	 */
-	protected $factory;
-
-	/**
-	 * Setup tests
-	 *
-	 * @return void
-	 */
-	protected function setUp()
-	{
-		parent::setUp();
-
-		$this->factory = Factory::getInstance();
-	}
-
-	/**
-	 * Test create request instance
-	 *
-	 * @return void
-	 */
-	public function testRequestInstance()
-	{
-		$request = $this->factory->createRequest();
-
-		$this->assertInstanceOf('JonnyW\PhantomJs\Message\RequestInterface', $request);
-	}
-
-	/**
-	 * Test create response instance
-	 *
-	 * @return void
-	 */
-	public function testResponseInstance()
-	{
-		$response = $this->factory->createResponse();
-
-		$this->assertInstanceOf('JonnyW\PhantomJs\Message\ResponseInterface', $response);
-	}
-}
+    /**
+     * Factory instance
+     *
+     * @var \JonnyW\PhantomJs\Message\Factory
+     */
+    protected $factory;
+
+    /**
+     * Setup tests
+     *
+     * @return void
+     */
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $this->factory = Factory::getInstance();
+    }
+
+    /**
+     * Test create request instance
+     *
+     * @return void
+     */
+    public function testRequestInstance()
+    {
+        $request = $this->factory->createRequest();
+
+        $this->assertInstanceOf('JonnyW\PhantomJs\Message\RequestInterface', $request);
+    }
+
+    /**
+     * Test create response instance
+     *
+     * @return void
+     */
+    public function testResponseInstance()
+    {
+        $response = $this->factory->createResponse();
+
+        $this->assertInstanceOf('JonnyW\PhantomJs\Message\ResponseInterface', $response);
+    }
+}

+ 120 - 120
test/JonnyW/PhantomJs/Test/Message/RequestTest.php

@@ -17,123 +17,123 @@ use JonnyW\PhantomJs\Message\Request;
  */
 class RequestTest extends \PHPUnit_Framework_TestCase
 {
-	/**
-	 * Test invalid URL's throw exception
-	 *
-	 * @dataProvider provideInvalidHosts
-	 *
-	 * @param string $url
-	 * @return void
-	 */
-	public function testInvalidUrl($url)
-	{
-		$this->setExpectedException('JonnyW\\PhantomJs\\Exception\\InvalidUrlException');
-
-		$request = new Request();
-		$request->setUrl($url);
-	}
-
-	/**
-	 * Invalid host data providers
-	 *
-	 * @return array
-	 */
-	public function provideInvalidHosts()
-	{
-		return array(
-			array('invalid_url'),
-			array('invalid_url.test')
-		);
-	}
-
-	/**
-	 * Test invalid methods throw exception
-	 *
-	 * @dataProvider provideInvalidMethods
-	 *
-	 * @param string $method
-	 * @return void
-	 */
-	public function testInvalidMethod($method)
-	{
-		$this->setExpectedException('JonnyW\\PhantomJs\\Exception\\InvalidMethodException');
-
-		$request = new Request();
-		$request->setMethod($method);
-	}
-
-	/**
-	 * Invalid method data providers
-	 *
-	 * @return array
-	 */
-	public function provideInvalidMethods()
-	{
-		return array(
-			array('GOT'),
-			array('FIND')
-		);
-	}
-
-	/**
-	 * Test invalid methods throw exception
-	 *
-	 * @return void
-	 */
-	public function testGetRequestBody()
-	{
-		$data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
-
-		$request = new Request('GET', 'http://jonnyw.me');
-		$request->setRequestData($data);
-
-		$this->assertEmpty($request->getBody());
-	}
-
-	/**
-	 * Test GET URL parameters when URL
-	 * does not have existing parameters
-	 *
-	 * @return void
-	 */
-	public function testGetUrlQuery()
-	{
-		$data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
-
-		$request = new Request('GET', 'http://jonnyw.me?query=true');
-		$request->setRequestData($data);
-
-		$this->assertEquals($request->getUrl(), 'http://jonnyw.me?query=true&' . urldecode(http_build_query($data)));
-	}
-
-	/**
-	 * Test GET URL parameters when URL
-	 * does not have existing parameters
-	 *
-	 * @return void
-	 */
-	public function testGetUrlQueryClean()
-	{
-		$data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
-
-		$request = new Request('GET', 'http://jonnyw.me');
-		$request->setRequestData($data);
-
-		$this->assertEquals($request->getUrl(), 'http://jonnyw.me?' . urldecode(http_build_query($data)));
-	}
-
-	/**
-	 * Test invalid methods throw exception
-	 *
-	 * @return void
-	 */
-	public function testPostRequestBody()
-	{
-		$data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
-
-		$request = new Request('POST', 'http://jonnyw.me');
-		$request->setRequestData($data);
-
-		$this->assertEquals($request->getBody(), urldecode(http_build_query($data)));
-	}
-}
+    /**
+     * Test invalid URL's throw exception
+     *
+     * @dataProvider provideInvalidHosts
+     *
+     * @param  string $url
+     * @return void
+     */
+    public function testInvalidUrl($url)
+    {
+        $this->setExpectedException('JonnyW\\PhantomJs\\Exception\\InvalidUrlException');
+
+        $request = new Request();
+        $request->setUrl($url);
+    }
+
+    /**
+     * Invalid host data providers
+     *
+     * @return array
+     */
+    public function provideInvalidHosts()
+    {
+        return array(
+            array('invalid_url'),
+            array('invalid_url.test')
+        );
+    }
+
+    /**
+     * Test invalid methods throw exception
+     *
+     * @dataProvider provideInvalidMethods
+     *
+     * @param  string $method
+     * @return void
+     */
+    public function testInvalidMethod($method)
+    {
+        $this->setExpectedException('JonnyW\\PhantomJs\\Exception\\InvalidMethodException');
+
+        $request = new Request();
+        $request->setMethod($method);
+    }
+
+    /**
+     * Invalid method data providers
+     *
+     * @return array
+     */
+    public function provideInvalidMethods()
+    {
+        return array(
+            array('GOT'),
+            array('FIND')
+        );
+    }
+
+    /**
+     * Test invalid methods throw exception
+     *
+     * @return void
+     */
+    public function testGetRequestBody()
+    {
+        $data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
+
+        $request = new Request('GET', 'http://jonnyw.me');
+        $request->setRequestData($data);
+
+        $this->assertEmpty($request->getBody());
+    }
+
+    /**
+     * Test GET URL parameters when URL
+     * does not have existing parameters
+     *
+     * @return void
+     */
+    public function testGetUrlQuery()
+    {
+        $data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
+
+        $request = new Request('GET', 'http://jonnyw.me?query=true');
+        $request->setRequestData($data);
+
+        $this->assertEquals($request->getUrl(), 'http://jonnyw.me?query=true&' . urldecode(http_build_query($data)));
+    }
+
+    /**
+     * Test GET URL parameters when URL
+     * does not have existing parameters
+     *
+     * @return void
+     */
+    public function testGetUrlQueryClean()
+    {
+        $data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
+
+        $request = new Request('GET', 'http://jonnyw.me');
+        $request->setRequestData($data);
+
+        $this->assertEquals($request->getUrl(), 'http://jonnyw.me?' . urldecode(http_build_query($data)));
+    }
+
+    /**
+     * Test invalid methods throw exception
+     *
+     * @return void
+     */
+    public function testPostRequestBody()
+    {
+        $data = array('name' => 'jonnyw', 'email' => 'contact@jonnyw.me');
+
+        $request = new Request('POST', 'http://jonnyw.me');
+        $request->setRequestData($data);
+
+        $this->assertEquals($request->getBody(), urldecode(http_build_query($data)));
+    }
+}

+ 4 - 4
test/bootstrap.php

@@ -1,7 +1,7 @@
 <?php
 
-if(!$loader = @include __DIR__.'/../vendor/autoload.php') {
-	echo <<<EOM
+if (!$loader = @include __DIR__.'/../vendor/autoload.php') {
+    echo <<<EOM
 You must set up the project dependencies by running the following commands:
 
     curl -s http://getcomposer.org/installer | php
@@ -9,7 +9,7 @@ You must set up the project dependencies by running the following commands:
 
 EOM;
 
-	exit(1);
+    exit(1);
 }
 
-$loader->add('JonnyW\PhantomJs\Test', __DIR__);
+$loader->add('JonnyW\PhantomJs\Test', __DIR__);