From 98f6fca7e3d2ef88b8246e93514297b2d7c41a60 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Tue, 2 Apr 2019 18:37:46 -0400 Subject: [PATCH] Enforce minimum array size (for now) --- lib/Database.php | 3 +++ tests/cases/Database/SeriesArticle.php | 29 ++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index 49f32e8b..404f451f 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -1418,6 +1418,9 @@ class Database { $col = $opt['cte_cols'][$named ? 2 : 1]; if ($context->$m()) { $seen = true; + if (!$context->$m) { + throw new Db\ExceptionInput("tooShort", ['field' => $m, 'action' => $this->caller(), 'min' => 1]); // must have at least one array element + } if ($multi) { list($test, $types, $values) = $this->generateIn($context->$m, $named ? "str" : "int"); $test = "in ($test)"; diff --git a/tests/cases/Database/SeriesArticle.php b/tests/cases/Database/SeriesArticle.php index 51d9da53..694aec56 100644 --- a/tests/cases/Database/SeriesArticle.php +++ b/tests/cases/Database/SeriesArticle.php @@ -789,11 +789,6 @@ trait SeriesArticle { $this->compareExpectations($state); } - public function testMarkTooFewMultipleArticles() { - $this->assertException("tooShort", "Db", "ExceptionInput"); - Arsse::$db->articleMark($this->user, ['read'=>false,'starred'=>true], (new Context)->articles([])); - } - public function testMarkTooManyMultipleArticles() { $this->assertSame(7, Arsse::$db->articleMark($this->user, ['read'=>false,'starred'=>true], (new Context)->articles(range(1, Database::LIMIT_SET_SIZE * 3)))); } @@ -860,11 +855,6 @@ trait SeriesArticle { $this->compareExpectations($state); } - public function testMarkTooFewMultipleEditions() { - $this->assertException("tooShort", "Db", "ExceptionInput"); - Arsse::$db->articleMark($this->user, ['read'=>false,'starred'=>true], (new Context)->editions([])); - } - public function testMarkTooManyMultipleEditions() { $this->assertSame(7, Arsse::$db->articleMark($this->user, ['read'=>false,'starred'=>true], (new Context)->editions(range(1, 51)))); } @@ -1036,13 +1026,20 @@ trait SeriesArticle { Arsse::$db->articleCategoriesGet($this->user, 19); } - public function testSearchTooFewTerms() { - $this->assertException("tooShort", "Db", "ExceptionInput"); - Arsse::$db->articleList($this->user, (new Context)->searchTerms([])); - } - - public function testSearchTooFewTermsInNote() { + /** @dataProvider provideArrayContextOptions */ + public function testUseTooFewValuesInArrayContext(string $option) { $this->assertException("tooShort", "Db", "ExceptionInput"); Arsse::$db->articleList($this->user, (new Context)->annotationTerms([])); } + + public function provideArrayContextOptions() { + foreach([ + "articles", "editions", + "subscriptions", "foldersShallow", //"folders", + "tags", "tagNames", "labels", "labelNames", + "searchTerms", "authorTerms", "annotationTerms", + ] as $method) { + yield [$method]; + } + } }