Skip to content

Commit

Permalink
trigger errors for deprecated methods in HttpFoundation component
Browse files Browse the repository at this point in the history
  • Loading branch information
colinfrei committed Dec 3, 2012
1 parent 0e9157a commit f49704b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -466,6 +466,8 @@ public function overrideGlobals()
*/
public static function trustProxyData()
{
trigger_error('trustProxyData() is deprecated since version 2.0 and will be removed in 2.3. Use setTrustedProxies() instead.', E_USER_DEPRECATED);

self::$trustProxy = true;
}

Expand Down Expand Up @@ -1414,6 +1416,8 @@ public function isXmlHttpRequest()
*/
public function splitHttpAcceptHeader($header)
{
trigger_error('splitHttpAcceptHeader() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);

$headers = array();
foreach (AcceptHeader::fromString($header)->all() as $item) {
$key = $item->getValue();
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/HttpFoundation/Session/Session.php
Expand Up @@ -259,6 +259,8 @@ public function getFlashBag()
*/
public function getFlashes()
{
trigger_error('getFlashes() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

$all = $this->getBag($this->flashName)->all();

$return = array();
Expand All @@ -282,6 +284,8 @@ public function getFlashes()
*/
public function setFlashes($values)
{
trigger_error('setFlashes() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

foreach ($values as $name => $value) {
$this->getBag($this->flashName)->set($name, $value);
}
Expand All @@ -297,6 +301,8 @@ public function setFlashes($values)
*/
public function getFlash($name, $default = null)
{
trigger_error('getFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

$return = $this->getBag($this->flashName)->get($name);

return empty($return) ? $default : reset($return);
Expand All @@ -310,6 +316,8 @@ public function getFlash($name, $default = null)
*/
public function setFlash($name, $value)
{
trigger_error('setFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

$this->getBag($this->flashName)->set($name, $value);
}

Expand All @@ -322,6 +330,8 @@ public function setFlash($name, $value)
*/
public function hasFlash($name)
{
trigger_error('hasFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

return $this->getBag($this->flashName)->has($name);
}

Expand All @@ -332,6 +342,8 @@ public function hasFlash($name)
*/
public function removeFlash($name)
{
trigger_error('removeFlash() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

$this->getBag($this->flashName)->get($name);
}

Expand All @@ -342,6 +354,8 @@ public function removeFlash($name)
*/
public function clearFlashes()
{
trigger_error('clearFlashes() is deprecated since version 2.1 and will be removed in 2.3. Use the FlashBag instead.', E_USER_DEPRECATED);

return $this->getBag($this->flashName)->clear();
}
}
9 changes: 9 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -706,6 +706,8 @@ public function testGetClientIp($expected, $proxy, $remoteAddr, $httpForwardedFo

$request->initialize(array(), array(), array(), array(), array(), $server);
if ($proxy) {
$this->setExpectedException('PHPUnit_Framework_Error_Deprecated');

$this->startTrustingProxyData();
}
$this->assertEquals($expected, $request->getClientIp($proxy));
Expand Down Expand Up @@ -821,6 +823,9 @@ public function testCreateFromGlobals($method)
$this->disableHttpMethodParameterOverride();
}

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testOverrideGlobals()
{
$request = new Request();
Expand Down Expand Up @@ -1095,6 +1100,7 @@ public function testToString()

/**
* @dataProvider splitHttpAcceptHeaderData
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testSplitHttpAcceptHeader($acceptHeader, $expected)
{
Expand Down Expand Up @@ -1248,6 +1254,9 @@ private function disableHttpMethodParameterOverride()
$property->setValue(false);
}

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testTrustedProxies()
{
$request = Request::create('http://example.com/');
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php
Expand Up @@ -191,6 +191,9 @@ public function testGetFlashBag()

// deprecated since 2.1, will be removed from 2.3

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testGetSetFlashes()
{
$array = array('notice' => 'hello', 'error' => 'none');
Expand All @@ -205,6 +208,9 @@ public function testGetSetFlashes()
$this->assertEquals(array('notice' => 'foo'), $this->session->getFlashes());
}

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testGetFlashesWithArray()
{
$array = array('notice' => 'hello', 'error' => 'none');
Expand All @@ -220,6 +226,9 @@ public function testGetFlashesWithArray()
$this->assertEquals(array(), $this->session->getFlashes());
}

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testGetSetFlash()
{
$this->assertNull($this->session->getFlash('notice'));
Expand All @@ -232,13 +241,19 @@ public function testGetSetFlash()
$this->assertNull($this->session->getFlash('notice'));
}

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testHasFlash()
{
$this->assertFalse($this->session->hasFlash('notice'));
$this->session->setFlash('notice', 'foo');
$this->assertTrue($this->session->hasFlash('notice'));
}

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testRemoveFlash()
{
$this->session->setFlash('notice', 'foo');
Expand All @@ -249,6 +264,9 @@ public function testRemoveFlash()
$this->assertFalse($this->session->hasFlash('error'));
}

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testClearFlashes()
{
$this->assertFalse($this->session->hasFlash('notice'));
Expand Down

0 comments on commit f49704b

Please sign in to comment.