diff --git a/RoboFile.php b/RoboFile.php index 93c9444..e47c8fc 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -126,7 +126,7 @@ class RoboFile extends \Robo\Tasks { $execpath = norm(BASE."vendor-bin/phpunit/vendor/phpunit/phpunit/phpunit"); $confpath = realpath(BASE_TEST."phpunit.dist.xml") ?: norm(BASE_TEST."phpunit.xml"); $this->taskServer(8000)->host("localhost")->dir(BASE_TEST."docroot")->rawArg("-n")->arg(BASE_TEST."server.php")->rawArg($this->blackhole())->background()->run(); - return $this->taskExec($executor)->arg($execpath)->option("-c", $confpath)->args(array_merge($set, $args))->run(); + return $this->taskExec($executor)->option("-d", "zend.assertions=1")->arg($execpath)->option("-c", $confpath)->args(array_merge($set, $args))->run(); } /** Packages a given commit of the software into a release tarball diff --git a/lib/Database.php b/lib/Database.php index 71febcc..3752403 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -198,13 +198,11 @@ class Database { * @param boolean $matchAny Whether the search is successful when it matches any (true) or all (false) terms */ protected function generateSearch(array $terms, array $cols, bool $matchAny = false): array { - if (!$cols) { - throw new Exception("arrayEmpty", "cols"); // @codeCoverageIgnore - } $clause = []; $types = []; $values = []; $like = $this->db->sqlToken("like"); + assert(sizeof($cols) > 0, new Exception("arrayEmpty", "cols")); $embedSet = sizeof($terms) > ((int) (self::LIMIT_SET_SIZE / sizeof($cols))); foreach ($terms as $term) { $embedTerm = ($embedSet && strlen($term) <= self::LIMIT_SET_STRING_LENGTH); @@ -2081,9 +2079,7 @@ class Database { * @param boolean $byName Whether to interpret the $id parameter as the label's name (true) or identifier (false) */ public function labelArticlesSet(string $user, $id, Context $context, int $mode = self::ASSOC_ADD, bool $byName = false): int { - if (!in_array($mode, [self::ASSOC_ADD, self::ASSOC_REMOVE, self::ASSOC_REPLACE])) { - throw new Exception("constantUnknown", $mode); // @codeCoverageIgnore - } + assert(in_array($mode, [self::ASSOC_ADD, self::ASSOC_REMOVE, self::ASSOC_REPLACE]), new Exception("constantUnknown", $mode)); if (!Arsse::$user->authorize($user, __FUNCTION__)) { throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]); } @@ -2386,9 +2382,7 @@ class Database { * @param boolean $byName Whether to interpret the $id parameter as the tag's name (true) or identifier (false) */ public function tagSubscriptionsSet(string $user, $id, array $subscriptions, int $mode = self::ASSOC_ADD, bool $byName = false): int { - if (!in_array($mode, [self::ASSOC_ADD, self::ASSOC_REMOVE, self::ASSOC_REPLACE])) { - throw new Exception("constantUnknown", $mode); // @codeCoverageIgnore - } + assert(in_array($mode, [self::ASSOC_ADD, self::ASSOC_REMOVE, self::ASSOC_REPLACE]), new Exception("constantUnknown", $mode)); if (!Arsse::$user->authorize($user, __FUNCTION__)) { throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]); } diff --git a/lib/Db/AbstractStatement.php b/lib/Db/AbstractStatement.php index abf9f77..cc8ce42 100644 --- a/lib/Db/AbstractStatement.php +++ b/lib/Db/AbstractStatement.php @@ -56,9 +56,7 @@ abstract class AbstractStatement implements Statement { $this->retypeArray($binding, true); } else { $bindId = self::TYPES[trim(strtolower($binding))] ?? 0; - if (!$bindId) { - throw new Exception("paramTypeInvalid", $binding); // @codeCoverageIgnore - } + assert($bindId, new Exception("paramTypeInvalid", $binding)); $this->types[] = $bindId; } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 68c7ea8..33dac91 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -10,5 +10,7 @@ const NS_BASE = __NAMESPACE__."\\"; define(NS_BASE."BASE", dirname(__DIR__).DIRECTORY_SEPARATOR); const DOCROOT = BASE."tests".DIRECTORY_SEPARATOR."docroot".DIRECTORY_SEPARATOR; ini_set("memory_limit", "-1"); +ini_set("zend.assertions", "1"); +ini_set("assert.exception", "true"); error_reporting(\E_ALL); require_once BASE."vendor".DIRECTORY_SEPARATOR."autoload.php";