aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark/BookmarkTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-02 17:50:59 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-13 13:50:11 +0200
commitefb7d21b52eb033530e80e5e49d175e6e3b031f4 (patch)
tree4f34052788a08be1a30cb88c3339ae14e0b7c4da /tests/bookmark/BookmarkTest.php
parent29c31b7ec6ca48ba37b7eb6da650931fd0cb7164 (diff)
downloadShaarli-efb7d21b52eb033530e80e5e49d175e6e3b031f4.tar.gz
Shaarli-efb7d21b52eb033530e80e5e49d175e6e3b031f4.tar.zst
Shaarli-efb7d21b52eb033530e80e5e49d175e6e3b031f4.zip
Add strict types for bookmarks management
Parameters typing and using strict types overall increase the codebase quality by enforcing the a given parameter will have the expected type. It also removes the need to unnecessary unit tests checking methods behavior with invalid input.
Diffstat (limited to 'tests/bookmark/BookmarkTest.php')
-rw-r--r--tests/bookmark/BookmarkTest.php38
1 files changed, 0 insertions, 38 deletions
diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php
index afec2440..4c7ae4c0 100644
--- a/tests/bookmark/BookmarkTest.php
+++ b/tests/bookmark/BookmarkTest.php
@@ -154,25 +154,6 @@ class BookmarkTest extends TestCase
154 } 154 }
155 155
156 /** 156 /**
157 * Test validate() with a a bookmark with a non integer ID.
158 */
159 public function testValidateNotValidStringId()
160 {
161 $bookmark = new Bookmark();
162 $bookmark->setId('str');
163 $bookmark->setShortUrl('abc');
164 $bookmark->setCreated(\DateTime::createFromFormat('Ymd_His', '20190514_200102'));
165 $exception = null;
166 try {
167 $bookmark->validate();
168 } catch (InvalidBookmarkException $e) {
169 $exception = $e;
170 }
171 $this->assertNotNull($exception);
172 $this->assertContainsPolyfill('- ID: str'. PHP_EOL, $exception->getMessage());
173 }
174
175 /**
176 * Test validate() with a a bookmark without short url. 157 * Test validate() with a a bookmark without short url.
177 */ 158 */
178 public function testValidateNotValidNoShortUrl() 159 public function testValidateNotValidNoShortUrl()
@@ -211,25 +192,6 @@ class BookmarkTest extends TestCase
211 } 192 }
212 193
213 /** 194 /**
214 * Test validate() with a a bookmark with a bad created datetime.
215 */
216 public function testValidateNotValidBadCreated()
217 {
218 $bookmark = new Bookmark();
219 $bookmark->setId(1);
220 $bookmark->setShortUrl('abc');
221 $bookmark->setCreated('hi!');
222 $exception = null;
223 try {
224 $bookmark->validate();
225 } catch (InvalidBookmarkException $e) {
226 $exception = $e;
227 }
228 $this->assertNotNull($exception);
229 $this->assertContainsPolyfill('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage());
230 }
231
232 /**
233 * Test setId() and make sure that default fields are generated. 195 * Test setId() and make sure that default fields are generated.
234 */ 196 */
235 public function testSetIdEmptyGeneratedFields() 197 public function testSetIdEmptyGeneratedFields()