Bladeren bron

[BrowserKit] tagged the guaranteed BC API

Fabien Potencier 14 jaren geleden
bovenliggende
commit
ff3c66753f

+ 37 - 1
src/Symfony/Component/BrowserKit/Client.php

@@ -28,6 +28,8 @@ use Symfony\Component\BrowserKit\Client;
  * you need to also implement the getScript() method.
  *
  * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
  */
 abstract class Client
 {
@@ -47,6 +49,8 @@ abstract class Client
      * @param array     $server    The server parameters (equivalent of $_SERVER)
      * @param History   $history   A History instance to store the browser history
      * @param CookieJar $cookieJar A CookieJar instance to store the cookies
+     *
+     * @api
      */
     public function __construct(array $server = array(), History $history = null, CookieJar $cookieJar = null)
     {
@@ -61,6 +65,8 @@ abstract class Client
      * Sets whether to automatically follow redirects or not.
      *
      * @param Boolean $followRedirect Whether to follow redirects
+     *
+     * @api
      */
     public function followRedirects($followRedirect = true)
     {
@@ -73,6 +79,8 @@ abstract class Client
      * @param Boolean $insulated Whether to insulate the requests or not
      *
      * @throws \RuntimeException When Symfony Process Component is not installed
+     *
+     * @api
      */
     public function insulate($insulated = true)
     {
@@ -89,6 +97,8 @@ abstract class Client
      * Sets server parameters.
      *
      * @param array $server An array of server parameters
+     *
+     * @api
      */
     public function setServerParameters(array $server)
     {
@@ -102,6 +112,8 @@ abstract class Client
      * Returns the History instance.
      *
      * @return History A History instance
+     *
+     * @api
      */
     public function getHistory()
     {
@@ -112,6 +124,8 @@ abstract class Client
      * Returns the CookieJar instance.
      *
      * @return CookieJar A CookieJar instance
+     *
+     * @api
      */
     public function getCookieJar()
     {
@@ -122,6 +136,8 @@ abstract class Client
      * Returns the current Crawler instance.
      *
      * @return Crawler A Crawler instance
+     *
+     * @api
      */
     public function getCrawler()
     {
@@ -132,6 +148,8 @@ abstract class Client
      * Returns the current Response instance.
      *
      * @return Response A Response instance
+     *
+     * @api
      */
     public function getResponse()
     {
@@ -142,6 +160,8 @@ abstract class Client
      * Returns the current Request instance.
      *
      * @return Request A Request instance
+     *
+     * @api
      */
     public function getRequest()
     {
@@ -152,6 +172,8 @@ abstract class Client
      * Clicks on a given link.
      *
      * @param Link $link A Link instance
+     *
+     * @api
      */
     public function click(Link $link)
     {
@@ -163,6 +185,8 @@ abstract class Client
      *
      * @param Form  $form   A Form instance
      * @param array $values An array of form field values
+     *
+     * @api
      */
     public function submit(Form $form, array $values = array())
     {
@@ -183,6 +207,8 @@ abstract class Client
      * @param Boolean $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
      *
      * @return Crawler
+     *
+     * @api
      */
     public function request($method, $uri, array $parameters = array(), array $files = array(), array $server = array(), $content = null, $changeHistory = true)
     {
@@ -195,7 +221,7 @@ abstract class Client
         $server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
         $server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
 
-        $request = new Request($uri, $method, $parameters, $files, $this->cookieJar->getValues($uri), $server, $content);
+        $request = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
 
         $this->request = $this->filterRequest($request);
 
@@ -311,6 +337,8 @@ abstract class Client
      * Goes back in the browser history.
      *
      * @return Crawler
+     *
+     * @api
      */
     public function back()
     {
@@ -321,6 +349,8 @@ abstract class Client
      * Goes forward in the browser history.
      *
      * @return Crawler
+     *
+     * @api
      */
     public function forward()
     {
@@ -331,6 +361,8 @@ abstract class Client
      * Reloads the current browser.
      *
      * @return Crawler
+     *
+     * @api
      */
     public function reload()
     {
@@ -343,6 +375,8 @@ abstract class Client
      * @return Crawler
      *
      * @throws \LogicException If request was not a redirect
+     *
+     * @api
      */
     public function followRedirect()
     {
@@ -357,6 +391,8 @@ abstract class Client
      * Restarts the client.
      *
      * It flushes all cookies.
+     *
+     * @api
      */
     public function restart()
     {

+ 24 - 0
src/Symfony/Component/BrowserKit/Cookie.php

@@ -15,6 +15,8 @@ namespace Symfony\Component\BrowserKit;
  * Cookie represents an HTTP cookie.
  *
  * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
  */
 class Cookie
 {
@@ -38,6 +40,8 @@ class Cookie
      * @param  string  $domain   The domain that the cookie is available
      * @param  bool    $secure   Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
      * @param  bool    $httponly The cookie httponly flag
+     *
+     * @api
      */
     public function __construct($name, $value, $expires = null, $path = '/', $domain = '', $secure = false, $httponly = false)
     {
@@ -54,6 +58,8 @@ class Cookie
      * Returns the HTTP representation of the Cookie.
      *
      * @return string The HTTP representation of the Cookie
+     *
+     * @api
      */
     public function __toString()
     {
@@ -89,6 +95,8 @@ class Cookie
      * @param string $url    The base URL
      *
      * @return Cookie A Cookie instance
+     *
+     * @api
      */
     static public function fromString($cookie, $url = null)
     {
@@ -162,6 +170,8 @@ class Cookie
      * Gets the name of the cookie.
      *
      * @return string The cookie name
+     *
+     * @api
      */
     public function getName()
     {
@@ -172,6 +182,8 @@ class Cookie
      * Gets the value of the cookie.
      *
      * @return string The cookie value
+     *
+     * @api
      */
     public function getValue()
     {
@@ -182,6 +194,8 @@ class Cookie
      * Gets the expires time of the cookie.
      *
      * @return string The cookie expires time
+     *
+     * @api
      */
     public function getExpiresTime()
     {
@@ -192,6 +206,8 @@ class Cookie
      * Gets the path of the cookie.
      *
      * @return string The cookie path
+     *
+     * @api
      */
     public function getPath()
     {
@@ -202,6 +218,8 @@ class Cookie
      * Gets the domain of the cookie.
      *
      * @return string The cookie domain
+     *
+     * @api
      */
     public function getDomain()
     {
@@ -212,6 +230,8 @@ class Cookie
      * Returns the secure flag of the cookie.
      *
      * @return Boolean The cookie secure flag
+     *
+     * @api
      */
     public function isSecure()
     {
@@ -222,6 +242,8 @@ class Cookie
      * Returns the httponly flag of the cookie.
      *
      * @return Boolean The cookie httponly flag
+     *
+     * @api
      */
     public function isHttpOnly()
     {
@@ -232,6 +254,8 @@ class Cookie
      * Returns true if the cookie has expired.
      *
      * @return Boolean true if the cookie has expired, false otherwise
+     *
+     * @api
      */
     public function isExpired()
     {

+ 11 - 1
src/Symfony/Component/BrowserKit/CookieJar.php

@@ -15,6 +15,8 @@ namespace Symfony\Component\BrowserKit;
  * CookieJar.
  *
  * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
  */
 class CookieJar
 {
@@ -24,6 +26,8 @@ class CookieJar
      * Sets a cookie.
      *
      * @param Cookie $cookie A Cookie instance
+     *
+     * @api
      */
     public function set(Cookie $cookie)
     {
@@ -36,6 +40,8 @@ class CookieJar
      * @param string $name The cookie name
      *
      * @return Cookie|null A Cookie instance or null if the cookie does not exist
+     *
+     * @api
      */
     public function get($name)
     {
@@ -48,6 +54,8 @@ class CookieJar
      * Removes a cookie by name.
      *
      * @param string $name The cookie name
+     *
+     * @api
      */
     public function expire($name)
     {
@@ -56,6 +64,8 @@ class CookieJar
 
     /**
      * Removes all the cookies from the jar.
+     *
+     * @api
      */
     public function clear()
     {
@@ -94,7 +104,7 @@ class CookieJar
      *
      * @return array An array of cookie values
      */
-    public function getValues($uri)
+    public function allValues($uri)
     {
         $this->flushExpiredCookies();
 

+ 18 - 0
src/Symfony/Component/BrowserKit/Request.php

@@ -15,6 +15,8 @@ namespace Symfony\Component\BrowserKit;
  * Request object.
  *
  * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
  */
 class Request
 {
@@ -36,6 +38,8 @@ class Request
      * @param array  $cookies    An array of cookies
      * @param array  $server     An array of server parameters
      * @param string $content    The raw body data
+     *
+     * @api
      */
     public function __construct($uri, $method, array $parameters = array(), array $files = array(), array $cookies = array(), array $server = array(), $content = null)
     {
@@ -52,6 +56,8 @@ class Request
      * Gets the request URI.
      *
      * @return string The request URI
+     *
+     * @api
      */
     public function getUri()
     {
@@ -62,6 +68,8 @@ class Request
      * Gets the request HTTP method.
      *
      * @return string The request HTTP method
+     *
+     * @api
      */
     public function getMethod()
     {
@@ -72,6 +80,8 @@ class Request
      * Gets the request parameters.
      *
      * @return array The request parameters
+     *
+     * @api
      */
     public function getParameters()
     {
@@ -82,6 +92,8 @@ class Request
      * Gets the request server files.
      *
      * @return array The request files
+     *
+     * @api
      */
     public function getFiles()
     {
@@ -92,6 +104,8 @@ class Request
      * Gets the request cookies.
      *
      * @return array The request cookies
+     *
+     * @api
      */
     public function getCookies()
     {
@@ -102,6 +116,8 @@ class Request
      * Gets the request server parameters.
      *
      * @return array The request server parameters
+     *
+     * @api
      */
     public function getServer()
     {
@@ -112,6 +128,8 @@ class Request
      * Gets the request raw body data.
      *
      * @return string The request raw body data.
+     *
+     * @api
      */
     public function getContent()
     {

+ 11 - 2
src/Symfony/Component/BrowserKit/Response.php

@@ -15,6 +15,8 @@ namespace Symfony\Component\BrowserKit;
  * Response object.
  *
  * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @api
  */
 class Response
 {
@@ -31,6 +33,8 @@ class Response
      * @param string  $content The content of the response
      * @param integer $status  The response status code
      * @param array   $headers An array of headers
+     *
+     * @api
      */
     public function __construct($content = '', $status = 200, array $headers = array())
     {
@@ -48,7 +52,6 @@ class Response
     {
         $headers = '';
         foreach ($this->headers as $name => $value) {
-            
             if (is_string($value)) {
                 $headers .= $this->buildHeader($name, $value);
             } else {
@@ -78,6 +81,8 @@ class Response
      * Gets the response content.
      *
      * @return string The response content
+     *
+     * @api
      */
     public function getContent()
     {
@@ -88,6 +93,8 @@ class Response
      * Gets the response status code.
      *
      * @return integer The response status code
+     *
+     * @api
      */
     public function getStatus()
     {
@@ -98,6 +105,8 @@ class Response
      * Gets the response headers.
      *
      * @return array The response headers
+     *
+     * @api
      */
     public function getHeaders()
     {
@@ -126,4 +135,4 @@ class Response
 
         return $first ? null : array();
     }
-}
+}

+ 2 - 2
tests/Symfony/Tests/Component/BrowserKit/ClientTest.php

@@ -199,10 +199,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
         $client = new TestClient();
         $client->setNextResponse(new Response('<html><a href="/foo">foo</a></html>', 200, array('Set-Cookie' => 'foo=bar')));
         $client->request('GET', 'http://www.example.com/foo/foobar');
-        $this->assertEquals(array('foo' => 'bar'), $client->getCookieJar()->getValues('http://www.example.com/foo/foobar'), '->request() updates the CookieJar');
+        $this->assertEquals(array('foo' => 'bar'), $client->getCookieJar()->allValues('http://www.example.com/foo/foobar'), '->request() updates the CookieJar');
 
         $client->request('GET', 'bar');
-        $this->assertEquals(array('foo' => 'bar'), $client->getCookieJar()->getValues('http://www.example.com/foo/foobar'), '->request() updates the CookieJar');
+        $this->assertEquals(array('foo' => 'bar'), $client->getCookieJar()->allValues('http://www.example.com/foo/foobar'), '->request() updates the CookieJar');
     }
 
     public function testClick()

+ 4 - 4
tests/Symfony/Tests/Component/BrowserKit/CookieJarTest.php

@@ -71,9 +71,9 @@ class CookieJarTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * @dataProvider provideGetValuesValues
+     * @dataProvider provideAllValuesValues
      */
-    public function testGetValues($uri, $values)
+    public function testAllValues($uri, $values)
     {
         $cookieJar = new CookieJar();
         $cookieJar->set($cookie1 = new Cookie('foo_nothing', 'foo'));
@@ -82,10 +82,10 @@ class CookieJarTest extends \PHPUnit_Framework_TestCase
         $cookieJar->set($cookie4 = new Cookie('foo_domain', 'foo', null, '/', 'example.com'));
         $cookieJar->set($cookie5 = new Cookie('foo_secure', 'foo', null, '/', '', true));
 
-        $this->assertEquals($values, array_keys($cookieJar->getValues($uri)), '->getValues() returns the cookie for a given URI');
+        $this->assertEquals($values, array_keys($cookieJar->allValues($uri)), '->allValues() returns the cookie for a given URI');
     }
 
-    public function provideGetValuesValues()
+    public function provideAllValuesValues()
     {
         return array(
             array('http://www.example.com/', array('foo_nothing', 'foo_domain')),