Skip to content

Commit

Permalink
added deprecated helper
Browse files Browse the repository at this point in the history
  • Loading branch information
saeideng committed Sep 27, 2017
1 parent d503d19 commit fbaf969
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/TestSuite/TestCase.php
Expand Up @@ -87,6 +87,20 @@ public function skipIf($shouldSkip, $message = '')
return $shouldSkip;
}

/**
* Helper method for check deprecation methods
*
* @param callable $callable callable function that will receive asserts
* @return void
*/
public function deprecated($callable)
{
$errorLevel = error_reporting();
error_reporting(E_ALL ^ E_USER_DEPRECATED);
$callable();
error_reporting($errorLevel);
}

/**
* Setup the test case, backup the static object values so they can be restored.
* Specifically backs up the contents of Configure and paths in App if they have
Expand Down
39 changes: 39 additions & 0 deletions tests/TestCase/TestSuite/TestCaseTest.php
Expand Up @@ -175,6 +175,45 @@ public function testSkipIf()
$this->assertEquals(0, $result->skippedCount());
}

/**
* testDeprecated
*
* @return void
*/
public function testDeprecated()
{
$value = 'custom';
$setter = 'setLayout';
$getter = 'getLayout';
$property = 'layout';
$controller = new \Cake\Controller\Controller();
$controller->viewBuilder()->{$setter}($value);
$this->deprecated(function () use ($value, $getter, $controller, $property) {
$this->assertSame($value, $controller->$property);
$this->assertSame($value, $controller->viewBuilder()->{$getter}());
});
}

/**
* testDeprecated
*
* @expectedException \PHPUnit\Framework\AssertionFailedError
* @return void
*/
public function testDeprecatedWithException()
{
$value = 'custom';
$setter = 'setLayout';
$getter = 'getLayout';
$property = 'layout';
$controller = new \Cake\Controller\Controller();
$controller->viewBuilder()->{$setter}($value);
$this->deprecated(function () use ($value, $getter, $controller, $property) {
$this->assertSame($value, $controller->$property);
$this->assertSame('Derp', $controller->viewBuilder()->{$getter}());
});
}

/**
* Test that TestCase::setUp() backs up values.
*
Expand Down

0 comments on commit fbaf969

Please sign in to comment.