2020 * @version $Id: CommonBackendTest.php 23775 2011-03-01 17:25:24Z ralph $
2121 */
2222
23-
24- // backward compatibility (https://stackoverflow.com/a/42828632/187780)
25- if (!class_exists ('\PHPUnit\Framework\TestCase ' ) && class_exists ('\PHPUnit_Framework_TestCase ' )) {
26- class_alias ('\PHPUnit_Framework_TestCase ' , '\PHPUnit\Framework\TestCase ' );
27- }
28-
2923/**
3024 * @category Zend
3125 * @package Zend_Cache
@@ -34,7 +28,7 @@ class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
3428 * @license http://framework.zend.com/license/new-bsd New BSD License
3529 * @group Zend_Cache
3630 */
37- abstract class Zend_Cache_CommonBackendTest extends \PHPUnit \Framework \TestCase
31+ abstract class CommonBackend extends \PHPUnit \Framework \TestCase
3832{
3933 protected $ _instance ;
4034 protected $ _className ;
@@ -105,45 +99,35 @@ public function testConstructorCorrectCall()
10599
106100 public function testConstructorBadOption ()
107101 {
108- try {
109- $ class = $ this ->_className ;
110- $ test = new $ class (array (1 => 'bar ' ));
111- } catch (Zend_Cache_Exception $ e ) {
112- return ;
113- }
114- $ this ->fail ('Zend_Cache_Exception was expected but not thrown ' );
102+ $ this ->expectException ('Zend_Cache_Exception ' );
103+ $ className = $ this ->_className ;
104+ new $ className (array (1 => 'bar ' ));
115105 }
116106
117107 public function testSetDirectivesCorrectCall ()
118108 {
119109 $ this ->_instance ->setDirectives (array ('lifetime ' => 3600 ));
110+ $ this ->assertTrue (true );
120111 }
121112
122113 public function testSetDirectivesBadArgument ()
123114 {
124- try {
125- $ this ->_instance ->setDirectives ('foo ' );
126- } catch (Zend_Cache_Exception $ e ) {
127- return ;
128- }
129- $ this ->fail ('Zend_Cache_Exception was expected but not thrown ' );
115+ $ this ->expectException ('Zend_Cache_Exception ' );
116+ $ this ->_instance ->setDirectives ('foo ' );
130117 }
131118
132119 public function testSetDirectivesBadDirective ()
133120 {
134121 // A bad directive (not known by a specific backend) is possible
135122 // => so no exception here
136123 $ this ->_instance ->setDirectives (array ('foo ' => true , 'lifetime ' => 3600 ));
124+ $ this ->assertTrue (true );
137125 }
138126
139127 public function testSetDirectivesBadDirective2 ()
140128 {
141- try {
142- $ this ->_instance ->setDirectives (array ('foo ' => true , 12 => 3600 ));
143- } catch (Zend_Cache_Exception $ e ) {
144- return ;
145- }
146- $ this ->fail ('Zend_Cache_Exception was expected but not thrown ' );
129+ $ this ->expectException ('Zend_Cache_Exception ' );
130+ $ this ->_instance ->setDirectives (array ('foo ' => true , 12 => 3600 ));
147131 }
148132
149133 public function testSaveCorrectCall ()
@@ -176,14 +160,7 @@ public function testRemoveCorrectCall()
176160
177161 public function testTestWithAnExistingCacheId ()
178162 {
179- $ res = $ this ->_instance ->test ('bar ' );
180- if (!$ res ) {
181- $ this ->fail ('test() return false ' );
182- }
183- if (!($ res > 999999 )) {
184- $ this ->fail ('test() return an incorrect integer ' );
185- }
186- return ;
163+ $ this ->assertGreaterThan (999999 , $ this ->_instance ->test ('bar ' ));
187164 }
188165
189166 public function testTestWithANonExistingCacheId ()
@@ -194,14 +171,7 @@ public function testTestWithANonExistingCacheId()
194171 public function testTestWithAnExistingCacheIdAndANullLifeTime ()
195172 {
196173 $ this ->_instance ->setDirectives (array ('lifetime ' => null ));
197- $ res = $ this ->_instance ->test ('bar ' );
198- if (!$ res ) {
199- $ this ->fail ('test() return false ' );
200- }
201- if (!($ res > 999999 )) {
202- $ this ->fail ('test() return an incorrect integer ' );
203- }
204- return ;
174+ $ this ->assertGreaterThan (999999 , $ this ->_instance ->test ('bar ' ));
205175 }
206176
207177 public function testGetWithANonExistingCacheId ()
0 commit comments