1--TEST-- 2ImagickKernel::fromMatrix exceptions 3--SKIPIF-- 4<?php 5 6$imageMagickRequiredVersion = 0x680; 7require_once(dirname(__FILE__) . '/skipif.inc'); 8 9?> 10--FILE-- 11<?php 12 13 14$kernelArray = array( 15 array(1, 0, -1), 16 array(1, 0, -1), 17 array(1, 0, -1), 18); 19 20$validOrigins = [ 21 [0, 0], 22 [2, 0], 23 [0, 2], 24 [2, 2], 25 [1, 2] 26]; 27 28$invalidOrigins = [ 29 [-1, 0], 30 [3, 0], 31 [0, 3], 32 [3, 3], 33 [1, PHP_INT_MAX - 10], 34]; 35 36 37foreach ($validOrigins as $validOrigin) { 38 try { 39 $kernel = ImagickKernel::fromMatrix($kernelArray, $validOrigin); 40 } 41 catch (\Exception $e) { 42 echo "unexpected exception: " . $e->getMessage(); 43 } 44} 45 46foreach ($invalidOrigins as $invalidOrigin) { 47 try { 48 $kernel = ImagickKernel::fromMatrix($kernelArray, $invalidOrigin); 49 echo "Exception wasn't thrown for case: \n"; 50 var_dump($invalidOrigin); 51 } 52 catch (\ImagickKernelException $e) { 53 $message = $e->getMessage(); 54 if (strpos($message, "origin_y for matrix is outside bounds of rows") === 0) { 55 // this is fine. 56 } 57 else if (strpos($message, "origin_x for matrix is outside bounds of columns") === 0) { 58 // this is fine. 59 } 60 else { 61 echo "Unexpected message: " . $message . "\n"; 62 } 63 } 64} 65 66$flatKernelArray = array( 67 array(1, 0, -2, 0, 1), 68); 69 70try { 71 $kernel = ImagickKernel::fromMatrix($flatKernelArray, [1, 4]); 72 echo "Exception wasn't thrown for case: \n"; 73 var_dump($invalidOrigin); 74} 75catch (\ImagickKernelException $e) { 76 $message = $e->getMessage(); 77 if (strpos($message, "origin_y for matrix is outside bounds of rows") === 0) { 78 // this is fine. 79 } 80 else { 81 echo "Unexpected message: " . $message . "\n"; 82 } 83} 84 85 86$tallKernelArray = array( 87 array(1), 88 array(0), 89 array(-2), 90 array(0), 91 array(1), 92); 93 94 95try { 96 $kernel = ImagickKernel::fromMatrix($tallKernelArray, [4, 1]); 97 echo "Exception wasn't thrown for case: \n"; 98 var_dump($invalidOrigin); 99} 100catch (\ImagickKernelException $e) { 101 $message = $e->getMessage(); 102 if (strpos($message, "origin_x for matrix is outside bounds of columns") === 0) { 103 // this is fine. 104 } 105 else { 106 echo "Unexpected message: " . $message . "\n"; 107 } 108} 109 110 111 112echo "Complete".PHP_EOL; 113?> 114--EXPECTF-- 115Complete 116