diff --git a/application/init.php b/application/init.php index 365b2873a..5e69c1bf4 100755 --- a/application/init.php +++ b/application/init.php @@ -26,6 +26,8 @@ $dotenv->load(); } +Garp_ErrorHandler::registerErrorHandler(); + // Sentry integration if (getenv('SENTRY_API_URL') || (defined('SENTRY_API_URL') && APPLICATION_ENV !== 'development')) { $sentryApiUrl = getenv('SENTRY_API_URL') ?: SENTRY_API_URL; diff --git a/composer.json b/composer.json index c5949a9b2..02946ec98 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "dompdf/dompdf": "^0.7.0", "tedivm/jshrink": "1.1.0", "vlucas/phpdotenv": "2.0.1", - "fzaninotto/faker": "dev-master" + "fzaninotto/faker": "dev-master", + "grrr-amsterdam/garp-functional": "*" }, "require-dev": { "squizlabs/php_codesniffer": "^2.6", diff --git a/composer.lock b/composer.lock index bcf596f92..023f0973e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,32 +4,33 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "9f082e6dce733925cf68303c82bd3495", + "content-hash": "5b6e80d79f9dcd1d65db5b2691c36238", "packages": [ { "name": "dompdf/dompdf", - "version": "v0.7.0", + "version": "dev-develop", "source": { "type": "git", "url": "https://github.com/dompdf/dompdf.git", - "reference": "5c98652b1a5beb7e3cc8ec35419b2828dd63ab14" + "reference": "9d407df97417a99c2af3e47086af1d387767c03b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dompdf/dompdf/zipball/5c98652b1a5beb7e3cc8ec35419b2828dd63ab14", - "reference": "5c98652b1a5beb7e3cc8ec35419b2828dd63ab14", + "url": "https://api.github.com/repos/dompdf/dompdf/zipball/9d407df97417a99c2af3e47086af1d387767c03b", + "reference": "9d407df97417a99c2af3e47086af1d387767c03b", "shasum": "" }, "require": { "ext-dom": "*", "ext-gd": "*", "ext-mbstring": "*", - "phenx/php-font-lib": "0.4.*", - "phenx/php-svg-lib": "0.1.*", + "phenx/php-font-lib": "0.5.*", + "phenx/php-svg-lib": "0.2.*", "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "3.7.*" + "phpunit/phpunit": "4.8.*", + "squizlabs/php_codesniffer": "2.*" }, "type": "library", "extra": { @@ -65,7 +66,7 @@ ], "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter", "homepage": "https://github.com/dompdf/dompdf", - "time": "2016-05-11T00:36:29+00:00" + "time": "2017-06-13 02:54:36" }, { "name": "ezyang/htmlpurifier", @@ -120,12 +121,12 @@ "source": { "type": "git", "url": "https://github.com/fzaninotto/Faker.git", - "reference": "596c62b01eec4ef437ab134a4389fe50365d7320" + "reference": "ff1ce3321922821ec54943a9b1c270e8af365a72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/596c62b01eec4ef437ab134a4389fe50365d7320", - "reference": "596c62b01eec4ef437ab134a4389fe50365d7320", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/ff1ce3321922821ec54943a9b1c270e8af365a72", + "reference": "ff1ce3321922821ec54943a9b1c270e8af365a72", "shasum": "" }, "require": { @@ -162,20 +163,20 @@ "faker", "fixtures" ], - "time": "2017-06-02 07:51:32" + "time": "2017-07-03 15:50:13" }, { "name": "google/apiclient", - "version": "v1.1.8", + "version": "dev-v1-master", "source": { "type": "git", "url": "https://github.com/google/google-api-php-client.git", - "reference": "85309a3520bb5f53368d43e35fd24f43c9556323" + "reference": "107dc7d30fa9c6e5b75ce1200665e4fc3adfba6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/google/google-api-php-client/zipball/85309a3520bb5f53368d43e35fd24f43c9556323", - "reference": "85309a3520bb5f53368d43e35fd24f43c9556323", + "url": "https://api.github.com/repos/google/google-api-php-client/zipball/107dc7d30fa9c6e5b75ce1200665e4fc3adfba6e", + "reference": "107dc7d30fa9c6e5b75ce1200665e4fc3adfba6e", "shasum": "" }, "require": { @@ -205,11 +206,114 @@ "keywords": [ "google" ], - "time": "2016-06-06T21:22:48+00:00" + "time": "2017-01-09 19:33:08" + }, + { + "name": "grrr-amsterdam/garp-functional", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/grrr-amsterdam/garp-functional.git", + "reference": "b4aaeb65e1673e9f80c39156069132f4d232f3c0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/grrr-amsterdam/garp-functional/zipball/b4aaeb65e1673e9f80c39156069132f4d232f3c0", + "reference": "b4aaeb65e1673e9f80c39156069132f4d232f3c0", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7", + "squizlabs/php_codesniffer": "^2.7" + }, + "type": "library", + "autoload": { + "psr-4": { + "Garp\\": "library/" + }, + "files": [ + "library/Garp/Functional/Add.php", + "library/Garp/Functional/Always.php", + "library/Garp/Functional/Both.php", + "library/Garp/Functional/Call.php", + "library/Garp/Functional/Compose.php", + "library/Garp/Functional/Concat.php", + "library/Garp/Functional/ConcatRight.php", + "library/Garp/Functional/Divide.php", + "library/Garp/Functional/Drop.php", + "library/Garp/Functional/DropWhile.php", + "library/Garp/Functional/Either.php", + "library/Garp/Functional/Equals.php", + "library/Garp/Functional/Every.php", + "library/Garp/Functional/Filter.php", + "library/Garp/Functional/Find.php", + "library/Garp/Functional/FindIndex.php", + "library/Garp/Functional/Flatten.php", + "library/Garp/Functional/Flip.php", + "library/Garp/Functional/GroupBy.php", + "library/Garp/Functional/Gt.php", + "library/Garp/Functional/Gte.php", + "library/Garp/Functional/Head.php", + "library/Garp/Functional/Id.php", + "library/Garp/Functional/Instance.php", + "library/Garp/Functional/Join.php", + "library/Garp/Functional/Keys.php", + "library/Garp/Functional/Lt.php", + "library/Garp/Functional/Lte.php", + "library/Garp/Functional/Map.php", + "library/Garp/Functional/Match.php", + "library/Garp/Functional/Modulo.php", + "library/Garp/Functional/Multiply.php", + "library/Garp/Functional/None.php", + "library/Garp/Functional/Not.php", + "library/Garp/Functional/Omit.php", + "library/Garp/Functional/Partial.php", + "library/Garp/Functional/PartialRight.php", + "library/Garp/Functional/Pick.php", + "library/Garp/Functional/Pipe.php", + "library/Garp/Functional/Prop.php", + "library/Garp/Functional/PropEquals.php", + "library/Garp/Functional/PropIn.php", + "library/Garp/Functional/PropOf.php", + "library/Garp/Functional/PropSet.php", + "library/Garp/Functional/Reduce.php", + "library/Garp/Functional/Reindex.php", + "library/Garp/Functional/Replace.php", + "library/Garp/Functional/Some.php", + "library/Garp/Functional/Sort.php", + "library/Garp/Functional/SortBy.php", + "library/Garp/Functional/Split.php", + "library/Garp/Functional/Subtract.php", + "library/Garp/Functional/Tail.php", + "library/Garp/Functional/Take.php", + "library/Garp/Functional/TakeWhile.php", + "library/Garp/Functional/Truthy.php", + "library/Garp/Functional/Unary.php", + "library/Garp/Functional/Unique.php", + "library/Garp/Functional/Usort.php", + "library/Garp/Functional/When.php", + "library/Garp/Functional/Zip.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Harmen Janssen", + "email": "harmen@grrr.nl" + } + ], + "description": "Utility library embracing functional programming paradigms.", + "time": "2017-05-16 07:41:37" }, { "name": "monolog/monolog", - "version": "1.23.0", + "version": "1.x-dev", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", @@ -283,26 +387,29 @@ "logging", "psr-3" ], - "time": "2017-06-19T01:22:40+00:00" + "time": "2017-06-19 01:22:40" }, { "name": "phenx/php-font-lib", - "version": "0.4", + "version": "0.5", "source": { "type": "git", "url": "https://github.com/PhenX/php-font-lib.git", - "reference": "b8af0cacdc3cbf1e41a586fcb78f506f4121a088" + "reference": "19ad2bebc35be028fcc0221025fcbf3d436a3962" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/b8af0cacdc3cbf1e41a586fcb78f506f4121a088", - "reference": "b8af0cacdc3cbf1e41a586fcb78f506f4121a088", + "url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/19ad2bebc35be028fcc0221025fcbf3d436a3962", + "reference": "19ad2bebc35be028fcc0221025fcbf3d436a3962", "shasum": "" }, + "require-dev": { + "phpunit/phpunit": "^4.8" + }, "type": "library", "autoload": { - "psr-0": { - "FontLib\\": "src/" + "psr-4": { + "FontLib\\": "src/FontLib" } }, "notification-url": "https://packagist.org/downloads/", @@ -317,22 +424,25 @@ ], "description": "A library to read, parse, export and make subsets of different types of font files.", "homepage": "https://github.com/PhenX/php-font-lib", - "time": "2015-05-06T20:02:39+00:00" + "time": "2017-02-11T10:58:43+00:00" }, { "name": "phenx/php-svg-lib", - "version": "0.1", + "version": "v0.2", "source": { "type": "git", "url": "https://github.com/PhenX/php-svg-lib.git", - "reference": "b419766515b3426c6da74b0e29e93d71c4f17099" + "reference": "de291bec8449b89acfe85691b5c71434797959dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhenX/php-svg-lib/zipball/b419766515b3426c6da74b0e29e93d71c4f17099", - "reference": "b419766515b3426c6da74b0e29e93d71c4f17099", + "url": "https://api.github.com/repos/PhenX/php-svg-lib/zipball/de291bec8449b89acfe85691b5c71434797959dc", + "reference": "de291bec8449b89acfe85691b5c71434797959dc", "shasum": "" }, + "require": { + "sabberworm/php-css-parser": "6.0.*" + }, "type": "library", "autoload": { "psr-0": { @@ -351,26 +461,30 @@ ], "description": "A library to read, parse and export to PDF SVG files.", "homepage": "https://github.com/PhenX/php-svg-lib", - "time": "2015-05-06T18:49:49+00:00" + "time": "2016-12-13T20:25:45+00:00" }, { "name": "phpoffice/phpexcel", - "version": "1.8.1", + "version": "1.8.x-dev", "source": { "type": "git", "url": "https://github.com/PHPOffice/PHPExcel.git", - "reference": "372c7cbb695a6f6f1e62649381aeaa37e7e70b32" + "reference": "185bf412339526c97a98d959c3c0ecf4b7c80016" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPOffice/PHPExcel/zipball/372c7cbb695a6f6f1e62649381aeaa37e7e70b32", - "reference": "372c7cbb695a6f6f1e62649381aeaa37e7e70b32", + "url": "https://api.github.com/repos/PHPOffice/PHPExcel/zipball/185bf412339526c97a98d959c3c0ecf4b7c80016", + "reference": "185bf412339526c97a98d959c3c0ecf4b7c80016", "shasum": "" }, "require": { + "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "php": ">=5.2.0" + "php": "^5.2|^7.0" + }, + "require-dev": { + "squizlabs/php_codesniffer": "2.*" }, "type": "library", "autoload": { @@ -380,7 +494,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL" + "LGPL-2.1" ], "authors": [ { @@ -388,18 +502,19 @@ "homepage": "http://blog.maartenballiauw.be" }, { - "name": "Mark Baker" + "name": "Erik Tilt" }, { "name": "Franck Lefevre", - "homepage": "http://blog.rootslabs.net" + "homepage": "http://rootslabs.net" }, { - "name": "Erik Tilt" + "name": "Mark Baker", + "homepage": "http://markbakeruk.net" } ], "description": "PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine", - "homepage": "http://phpexcel.codeplex.com", + "homepage": "https://github.com/PHPOffice/PHPExcel", "keywords": [ "OpenXML", "excel", @@ -408,11 +523,11 @@ "xls", "xlsx" ], - "time": "2015-05-01T07:00:55+00:00" + "time": "2017-03-02 00:38:00" }, { "name": "psr/log", - "version": "1.0.2", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", @@ -455,20 +570,61 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2016-10-10 12:19:37" + }, + { + "name": "sabberworm/php-css-parser", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sabberworm/PHP-CSS-Parser.git", + "reference": "9ea4b00c569b19f731d0c2e0e802055877ff40c2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabberworm/PHP-CSS-Parser/zipball/9ea4b00c569b19f731d0c2e0e802055877ff40c2", + "reference": "9ea4b00c569b19f731d0c2e0e802055877ff40c2", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "autoload": { + "psr-0": { + "Sabberworm\\CSS": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Raphael Schweikert" + } + ], + "description": "Parser for CSS Files written in PHP", + "homepage": "http://www.sabberworm.com/blog/2010/6/10/php-css-parser", + "keywords": [ + "css", + "parser", + "stylesheet" + ], + "time": "2015-08-24T08:48:52+00:00" }, { "name": "sentry/sentry", - "version": "1.7.0", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/getsentry/sentry-php.git", - "reference": "f92d30467d9696606352aa06afeac0a60c4458ef" + "reference": "95bf8c3ca10f734aa2b29e48c7af8ba5d4a60e01" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/f92d30467d9696606352aa06afeac0a60c4458ef", - "reference": "f92d30467d9696606352aa06afeac0a60c4458ef", + "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/95bf8c3ca10f734aa2b29e48c7af8ba5d4a60e01", + "reference": "95bf8c3ca10f734aa2b29e48c7af8ba5d4a60e01", "shasum": "" }, "require": { @@ -496,7 +652,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.8.x-dev" } }, "autoload": { @@ -520,7 +676,7 @@ "log", "logging" ], - "time": "2017-06-07T18:13:17+00:00" + "time": "2017-06-26 11:18:02" }, { "name": "tedivm/jshrink", @@ -616,16 +772,16 @@ }, { "name": "zendframework/zendframework1", - "version": "1.12.20", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/zendframework/zf1.git", - "reference": "737ef159654fbbef37cf9af742b2c8f9690c2ece" + "reference": "a90f3a8d71e0788020f730da83674b7312bd3b16" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zf1/zipball/737ef159654fbbef37cf9af742b2c8f9690c2ece", - "reference": "737ef159654fbbef37cf9af742b2c8f9690c2ece", + "url": "https://api.github.com/repos/zendframework/zf1/zipball/a90f3a8d71e0788020f730da83674b7312bd3b16", + "reference": "a90f3a8d71e0788020f730da83674b7312bd3b16", "shasum": "" }, "require": { @@ -659,13 +815,13 @@ "ZF1", "framework" ], - "time": "2016-09-08T14:50:34+00:00" + "time": "2016-09-08 14:54:20" } ], "packages-dev": [ { "name": "phpunit/php-code-coverage", - "version": "1.2.18", + "version": "1.2.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", @@ -726,7 +882,7 @@ }, { "name": "phpunit/php-file-iterator", - "version": "1.4.2", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", @@ -814,16 +970,16 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.9", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + "reference": "d107f347d368dd8a384601398280c7c608390ab7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/d107f347d368dd8a384601398280c7c608390ab7", + "reference": "d107f347d368dd8a384601398280c7c608390ab7", "shasum": "" }, "require": { @@ -859,7 +1015,7 @@ "keywords": [ "timer" ], - "time": "2017-02-26T11:10:40+00:00" + "time": "2017-03-07T15:42:04+00:00" }, { "name": "phpunit/php-token-stream", @@ -913,7 +1069,7 @@ }, { "name": "phpunit/phpunit", - "version": "3.7.38", + "version": "3.7.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", @@ -986,26 +1142,34 @@ }, { "name": "phpunit/phpunit-mock-objects", - "version": "1.2.3", + "version": "1.2.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875" + "reference": "c39c4511c3b007539eb170c32cbc2af49a07351a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5794e3c5c5ba0fb037b11d8151add2a07fa82875", - "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c39c4511c3b007539eb170c32cbc2af49a07351a", + "reference": "c39c4511c3b007539eb170c32cbc2af49a07351a", "shasum": "" }, "require": { "php": ">=5.3.3", "phpunit/php-text-template": ">=1.1.1@stable" }, + "require-dev": { + "phpunit/phpunit": "3.7.*@dev" + }, "suggest": { "ext-soap": "*" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, "autoload": { "classmap": [ "PHPUnit/" @@ -1031,11 +1195,11 @@ "mock", "xunit" ], - "time": "2013-01-13T10:24:48+00:00" + "time": "2014-02-16T12:43:56+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "2.9.1", + "version": "2.9.x-dev", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", @@ -1113,35 +1277,34 @@ }, { "name": "symfony/yaml", - "version": "v2.6.13", - "target-dir": "Symfony/Component/Yaml", + "version": "2.8.x-dev", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "c044d1744b8e91aaaa0d9bac683ab87ec7cbf359" + "reference": "4c29dec8d489c4e37cf87ccd7166cd0b0e6a45c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/c044d1744b8e91aaaa0d9bac683ab87ec7cbf359", - "reference": "c044d1744b8e91aaaa0d9bac683ab87ec7cbf359", + "url": "https://api.github.com/repos/symfony/yaml/zipball/4c29dec8d489c4e37cf87ccd7166cd0b0e6a45c5", + "reference": "4c29dec8d489c4e37cf87ccd7166cd0b0e6a45c5", "shasum": "" }, "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" + "php": ">=5.3.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.8-dev" } }, "autoload": { - "psr-0": { + "psr-4": { "Symfony\\Component\\Yaml\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1159,7 +1322,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-07-26T08:59:42+00:00" + "time": "2017-06-01T20:52:29+00:00" } ], "aliases": [], @@ -1167,13 +1330,10 @@ "stability-flags": { "fzaninotto/faker": 20 }, - "prefer-stable": true, + "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=5.3.3" }, - "platform-dev": [], - "platform-overrides": { - "php": "5.3.3" - } + "platform-dev": [] } diff --git a/library/Garp/ErrorHandler.php b/library/Garp/ErrorHandler.php index 220c47d13..800eaf0ab 100644 --- a/library/Garp/ErrorHandler.php +++ b/library/Garp/ErrorHandler.php @@ -1,4 +1,6 @@ 'Garp_Exception_RuntimeException_Warning', + E_NOTICE => 'Garp_Exception_RuntimeException_Notice', + E_USER_ERROR => 'Garp_Exception_RuntimeException_UserError', + E_USER_WARNING => 'Garp_Exception_RuntimeException_UserWarning', + E_USER_NOTICE => 'Garp_Exception_RuntimeException_UserNotice', + E_STRICT => 'Garp_Exception_RuntimeException_Strict', + E_RECOVERABLE_ERROR => 'Garp_Exception_RuntimeException_RecoverableError', + E_DEPRECATED => 'Garp_Exception_RuntimeException_Deprecated', + E_USER_DEPRECATED => 'Garp_Exception_RuntimeException_UserDeprecated', + ); + + /** + * Handle all PHP errors and convert them to exceptions. + * + * @return void + */ + public static function registerErrorHandler() { + set_error_handler( + function ($severity, $msg, $file, $line, array $context) { + // error was suppressed with the @-operator + //if (0 === error_reporting()) { + //return false; + //} + $exceptionClass = f\either( + f\prop($severity, Garp_ErrorHandler::$severityToExceptionMap), + 'ErrorException' + ); + throw new $exceptionClass($msg, 0, $severity, $file, $line); + } + ); + } + /** * Handles premature exceptions thrown before the MVC ErrorHandler is initialized. * Exceptions of that kind will result in a blank page if displayErrors is off, instead of diff --git a/library/Garp/Exception.php b/library/Garp/Exception.php index 9612af25b..066f7ee23 100755 --- a/library/Garp/Exception.php +++ b/library/Garp/Exception.php @@ -1,11 +1,7 @@ */ class Garp_Exception extends Exception { } diff --git a/library/Garp/Exception/RuntimeException.php b/library/Garp/Exception/RuntimeException.php new file mode 100644 index 000000000..80fab51aa --- /dev/null +++ b/library/Garp/Exception/RuntimeException.php @@ -0,0 +1,12 @@ + + */ +class Garp_Exception_RuntimeException extends ErrorException { + +} diff --git a/library/Garp/Exception/RuntimeException/Deprecated.php b/library/Garp/Exception/RuntimeException/Deprecated.php new file mode 100644 index 000000000..7723daf95 --- /dev/null +++ b/library/Garp/Exception/RuntimeException/Deprecated.php @@ -0,0 +1,7 @@ + + */ +class Garp_Exception_RuntimeException_Deprecated extends Garp_Exception_RuntimeException { +} diff --git a/library/Garp/Exception/RuntimeException/Notice.php b/library/Garp/Exception/RuntimeException/Notice.php new file mode 100644 index 000000000..2c1d66d3c --- /dev/null +++ b/library/Garp/Exception/RuntimeException/Notice.php @@ -0,0 +1,7 @@ + + */ +class Garp_Exception_RuntimeException_Notice extends Garp_Exception_RuntimeException { +} diff --git a/library/Garp/Exception/RuntimeException/RecoverableError.php b/library/Garp/Exception/RuntimeException/RecoverableError.php new file mode 100644 index 000000000..50117d1c8 --- /dev/null +++ b/library/Garp/Exception/RuntimeException/RecoverableError.php @@ -0,0 +1,7 @@ + + */ +class Garp_Exception_RuntimeException_RecoverableError extends Garp_Exception_RuntimeException { +} diff --git a/library/Garp/Exception/RuntimeException/Strict.php b/library/Garp/Exception/RuntimeException/Strict.php new file mode 100644 index 000000000..735c7ef24 --- /dev/null +++ b/library/Garp/Exception/RuntimeException/Strict.php @@ -0,0 +1,7 @@ + + */ +class Garp_Exception_RuntimeException_Strict extends Garp_Exception_RuntimeException { +} diff --git a/library/Garp/Exception/RuntimeException/UserDeprecated.php b/library/Garp/Exception/RuntimeException/UserDeprecated.php new file mode 100644 index 000000000..daf7d8c9f --- /dev/null +++ b/library/Garp/Exception/RuntimeException/UserDeprecated.php @@ -0,0 +1,7 @@ + + */ +class Garp_Exception_RuntimeException_UserDeprecated extends Garp_Exception_RuntimeException { +} diff --git a/library/Garp/Exception/RuntimeException/UserError.php b/library/Garp/Exception/RuntimeException/UserError.php new file mode 100644 index 000000000..bcbd396c2 --- /dev/null +++ b/library/Garp/Exception/RuntimeException/UserError.php @@ -0,0 +1,7 @@ + + */ +class Garp_Exception_RuntimeException_UserError extends Garp_Exception_RuntimeException { +} diff --git a/library/Garp/Exception/RuntimeException/UserNotice.php b/library/Garp/Exception/RuntimeException/UserNotice.php new file mode 100644 index 000000000..7bc604ef8 --- /dev/null +++ b/library/Garp/Exception/RuntimeException/UserNotice.php @@ -0,0 +1,7 @@ + + */ +class Garp_Exception_RuntimeException_UserNotice extends Garp_Exception_RuntimeException { +} diff --git a/library/Garp/Exception/RuntimeException/UserWarning.php b/library/Garp/Exception/RuntimeException/UserWarning.php new file mode 100644 index 000000000..b829a94ff --- /dev/null +++ b/library/Garp/Exception/RuntimeException/UserWarning.php @@ -0,0 +1,7 @@ + + */ +class Garp_Exception_RuntimeException_UserWarning extends Garp_Exception_RuntimeException { +} diff --git a/library/Garp/Exception/RuntimeException/Warning.php b/library/Garp/Exception/RuntimeException/Warning.php new file mode 100644 index 000000000..bdb94aae4 --- /dev/null +++ b/library/Garp/Exception/RuntimeException/Warning.php @@ -0,0 +1,7 @@ + + */ +class Garp_Exception_RuntimeException_Warning extends Garp_Exception_RuntimeException { +} diff --git a/tests/library/Garp/ErrorHandlerTest.php b/tests/library/Garp/ErrorHandlerTest.php new file mode 100644 index 000000000..70e111195 --- /dev/null +++ b/tests/library/Garp/ErrorHandlerTest.php @@ -0,0 +1,121 @@ + + */ +class Garp_ErrorHandlerTest extends Garp_Test_PHPUnit_TestCase { + protected $_oldErrorReporting; + + public function setUp() { + $this->_oldErrorReporting = error_reporting(E_ALL); + } + + public function tearDown() { + error_reporting($this->_oldErrorReporting); + } + + /** + * @expectedException Garp_Exception_RuntimeException_Warning + */ + public function test_warning_exception() { + array_key_exists(array(), 'banana'); + } + + /** + * Tests E_STRICT warning. + * + * @deprecated Forget it. This does not work with PHP5.3 (it tries to load an instance + * of the Garp_Exception_RuntimeException_Strict class but cannot find it somehow. + * @return void + public function test_strict_exception() { + try { + eval( + 'class A { function foo($abc) {} } class B extends A { function foo() {} }' + ); + } catch (Exception $e) { + // Apparently both of these are possible and it differs per PHP version + $this->assertTrue( + $e instanceof Garp_Exception_RuntimeException_Strict || + $e instanceof Garp_Exception_RuntimeException_Warning + ); + } + } + */ + + /** + * @expectedException Garp_Exception_RuntimeException_Notice + */ + public function test_notice_exception() { + $a = array(); + $a['foo']; + } + + public function test_another_notice_exception() { + function change(&$var) { + $var += 10; + } + try { + $var = 1; + change(++$var); + } catch (Exception $e) { + // Note: the type of exception differs between PHP versions + $this->assertTrue( + $e instanceof Garp_Exception_RuntimeException_Notice + || $e instanceof Garp_Exception_RuntimeException_Strict + ); + } + } + + /** + * @expectedException Garp_Exception_RuntimeException_UserError + */ + public function test_user_error_exception() { + trigger_error('Well darn.', E_USER_ERROR); + } + + /** + * @expectedException Garp_Exception_RuntimeException_RecoverableError + */ + public function test_recoverable_exception() { + $recoverable = new stdClass(); + (string)$recoverable; + } + + public function test_deprecated_exception() { + try { + Foo::bar(); + } catch (Exception $e) { + // Note: the type of exception differs between PHP versions + $this->assertTrue( + $e instanceof Garp_Exception_RuntimeException_Strict + || $e instanceof Garp_Exception_RuntimeException_Deprecated + ); + } + } + + /** + * @expectedException Garp_Exception_RuntimeException_Notice + */ + public function test_with_at_suppressor() { + $a = array(); + @$a['foo']; + } + + /** + * @expectedException Garp_Exception_RuntimeException_Warning + */ + public function test_when_error_reporting_is_off() { + error_reporting(0); + array_key_exists(array(), 'banana'); + } + +} + +/** + * @package Tests + * @author Harmen Janssen + */ +class Foo { + function bar() { + } +}