3
3
include __DIR__ .'/../lib/ImageResize.php ' ;
4
4
5
5
use \Eventviva \ImageResize ;
6
+ use \Eventviva \ImageResizeException ;
6
7
7
- if (version_compare (PHP_VERSION , '7.0.0 ' ) >= 0 ) {
8
+ if (version_compare (PHP_VERSION , '7.0.0 ' ) >= 0 && ! class_exists ( ' PHPUnit_Framework_TestCase ' ) ) {
8
9
class_alias ('PHPUnit\Framework\TestCase ' , 'PHPUnit_Framework_TestCase ' );
9
10
}
10
11
@@ -60,13 +61,12 @@ public function testLoadString()
60
61
$ this ->assertInstanceOf ('\Eventviva\ImageResize ' , $ resize );
61
62
}
62
63
63
-
64
64
/**
65
65
* Bad load tests
66
66
*/
67
67
68
68
/**
69
- * @expectedException Exception
69
+ * @expectedException \Eventviva\ImageResizeException
70
70
* @expectedExceptionMessage Could not read file
71
71
*/
72
72
public function testLoadNoFile ()
@@ -75,7 +75,7 @@ public function testLoadNoFile()
75
75
}
76
76
77
77
/**
78
- * @expectedException Exception
78
+ * @expectedException \Eventviva\ImageResizeException
79
79
* @expectedExceptionMessage Could not read file
80
80
*/
81
81
public function testLoadUnsupportedFile ()
@@ -84,7 +84,7 @@ public function testLoadUnsupportedFile()
84
84
}
85
85
86
86
/**
87
- * @expectedException Exception
87
+ * @expectedException \Eventviva\ImageResizeException
88
88
* @expectedExceptionMessage Could not read file
89
89
*/
90
90
public function testLoadUnsupportedFileString ()
@@ -93,7 +93,7 @@ public function testLoadUnsupportedFileString()
93
93
}
94
94
95
95
/**
96
- * @expectedException Exception
96
+ * @expectedException \Eventviva\ImageResizeException
97
97
* @expectedExceptionMessage Unsupported image type
98
98
*/
99
99
public function testLoadUnsupportedImage ()
@@ -108,7 +108,7 @@ public function testLoadUnsupportedImage()
108
108
}
109
109
110
110
/**
111
- * @expectedException Exception
111
+ * @expectedException \Eventviva\ImageResizeException
112
112
* @expectedExceptionMessage Unsupported image type
113
113
*/
114
114
public function testInvalidString ()
@@ -398,7 +398,7 @@ public function testOutputPng()
398
398
private function createImage ($ width , $ height , $ type )
399
399
{
400
400
if (!in_array ($ type , $ this ->image_types )) {
401
- throw new \ Exception ('Unsupported image type ' );
401
+ throw new ImageResizeException ('Unsupported image type ' );
402
402
}
403
403
404
404
$ image = imagecreatetruecolor ($ width , $ height );
@@ -417,4 +417,42 @@ private function getTempFile()
417
417
}
418
418
419
419
}
420
+
421
+ class ImageResizeExceptionTest extends PHPUnit_Framework_TestCase
422
+ {
423
+ public function testExceptionEmpty ()
424
+ {
425
+ $ e = new ImageResizeException ();
426
+
427
+ $ this ->assertEquals ("" , $ e ->getMessage ());
428
+ $ this ->assertInstanceOf ('\Eventviva\ImageResizeException ' , $ e );
429
+ }
430
+
431
+ public function testExceptionMessage ()
432
+ {
433
+ $ e = new ImageResizeException ("General error " );
434
+
435
+ $ this ->assertEquals ("General error " , $ e ->getMessage ());
436
+ $ this ->assertInstanceOf ('\Eventviva\ImageResizeException ' , $ e );
437
+ }
438
+
439
+ public function testExceptionExtending ()
440
+ {
441
+ $ e = new ImageResizeException ("General error " );
442
+
443
+ $ this ->assertInstanceOf ('\Exception ' , $ e );
444
+ }
445
+
446
+ public function testExceptionThrown ()
447
+ {
448
+ try {
449
+ throw new ImageResizeException ("General error " );
450
+ } catch (\Exception $ e ) {
451
+ $ this ->assertEquals ("General error " , $ e ->getMessage ());
452
+ $ this ->assertInstanceOf ('\Eventviva\ImageResizeException ' , $ e );
453
+ return ;
454
+ }
455
+ $ this ->fail ();
456
+ }
457
+ }
420
458
// It's pretty easy to get your attention these days, isn't it? :D
0 commit comments