aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-09-27 14:07:08 +0200
committerArthurHoaro <arthur@hoa.ro>2020-09-27 14:09:55 +0200
commitb1baca99f280570d0336b4d71ad1f9dca213a35b (patch)
tree518de2057da549d0baa982c6aa689aa813377774 /tests/bookmark
parent8f60e1206e45e67c96a7630d4ff94e72fe875f09 (diff)
downloadShaarli-b1baca99f280570d0336b4d71ad1f9dca213a35b.tar.gz
Shaarli-b1baca99f280570d0336b4d71ad1f9dca213a35b.tar.zst
Shaarli-b1baca99f280570d0336b4d71ad1f9dca213a35b.zip
Convert legacy PHPUnit @expected* to new ->expect*
Converted automatically using https://github.com/ArthurHoaro/convert-legacy-phpunit-expect
Diffstat (limited to 'tests/bookmark')
-rw-r--r--tests/bookmark/BookmarkArrayTest.php24
-rw-r--r--tests/bookmark/BookmarkFileServiceTest.php84
-rw-r--r--tests/bookmark/BookmarkFilterTest.php10
3 files changed, 60 insertions, 58 deletions
diff --git a/tests/bookmark/BookmarkArrayTest.php b/tests/bookmark/BookmarkArrayTest.php
index 0f8f04c5..bad3af8d 100644
--- a/tests/bookmark/BookmarkArrayTest.php
+++ b/tests/bookmark/BookmarkArrayTest.php
@@ -47,22 +47,22 @@ class BookmarkArrayTest extends TestCase
47 47
48 /** 48 /**
49 * Test adding a bad entry: wrong type 49 * Test adding a bad entry: wrong type
50 *
51 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
52 */ 50 */
53 public function testArrayAccessAddBadEntryInstance() 51 public function testArrayAccessAddBadEntryInstance()
54 { 52 {
53 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
54
55 $array = new BookmarkArray(); 55 $array = new BookmarkArray();
56 $array[] = 'nope'; 56 $array[] = 'nope';
57 } 57 }
58 58
59 /** 59 /**
60 * Test adding a bad entry: no id 60 * Test adding a bad entry: no id
61 *
62 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
63 */ 61 */
64 public function testArrayAccessAddBadEntryNoId() 62 public function testArrayAccessAddBadEntryNoId()
65 { 63 {
64 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
65
66 $array = new BookmarkArray(); 66 $array = new BookmarkArray();
67 $bookmark = new Bookmark(); 67 $bookmark = new Bookmark();
68 $array[] = $bookmark; 68 $array[] = $bookmark;
@@ -70,11 +70,11 @@ class BookmarkArrayTest extends TestCase
70 70
71 /** 71 /**
72 * Test adding a bad entry: no url 72 * Test adding a bad entry: no url
73 *
74 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
75 */ 73 */
76 public function testArrayAccessAddBadEntryNoUrl() 74 public function testArrayAccessAddBadEntryNoUrl()
77 { 75 {
76 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
77
78 $array = new BookmarkArray(); 78 $array = new BookmarkArray();
79 $bookmark = (new Bookmark())->setId(11); 79 $bookmark = (new Bookmark())->setId(11);
80 $array[] = $bookmark; 80 $array[] = $bookmark;
@@ -82,11 +82,11 @@ class BookmarkArrayTest extends TestCase
82 82
83 /** 83 /**
84 * Test adding a bad entry: invalid offset 84 * Test adding a bad entry: invalid offset
85 *
86 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
87 */ 85 */
88 public function testArrayAccessAddBadEntryOffset() 86 public function testArrayAccessAddBadEntryOffset()
89 { 87 {
88 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
89
90 $array = new BookmarkArray(); 90 $array = new BookmarkArray();
91 $bookmark = (new Bookmark())->setId(11); 91 $bookmark = (new Bookmark())->setId(11);
92 $bookmark->validate(); 92 $bookmark->validate();
@@ -95,11 +95,11 @@ class BookmarkArrayTest extends TestCase
95 95
96 /** 96 /**
97 * Test adding a bad entry: invalid ID type 97 * Test adding a bad entry: invalid ID type
98 *
99 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
100 */ 98 */
101 public function testArrayAccessAddBadEntryIdType() 99 public function testArrayAccessAddBadEntryIdType()
102 { 100 {
101 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
102
103 $array = new BookmarkArray(); 103 $array = new BookmarkArray();
104 $bookmark = (new Bookmark())->setId('nope'); 104 $bookmark = (new Bookmark())->setId('nope');
105 $bookmark->validate(); 105 $bookmark->validate();
@@ -108,11 +108,11 @@ class BookmarkArrayTest extends TestCase
108 108
109 /** 109 /**
110 * Test adding a bad entry: ID/offset not consistent 110 * Test adding a bad entry: ID/offset not consistent
111 *
112 * @expectedException Shaarli\Bookmark\Exception\InvalidBookmarkException
113 */ 111 */
114 public function testArrayAccessAddBadEntryIdOffset() 112 public function testArrayAccessAddBadEntryIdOffset()
115 { 113 {
114 $this->expectException(\Shaarli\Bookmark\Exception\InvalidBookmarkException::class);
115
116 $array = new BookmarkArray(); 116 $array = new BookmarkArray();
117 $bookmark = (new Bookmark())->setId(11); 117 $bookmark = (new Bookmark())->setId(11);
118 $bookmark->validate(); 118 $bookmark->validate();
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php
index aed4dc76..9cff0fb3 100644
--- a/tests/bookmark/BookmarkFileServiceTest.php
+++ b/tests/bookmark/BookmarkFileServiceTest.php
@@ -134,11 +134,11 @@ class BookmarkFileServiceTest extends TestCase
134 134
135 /** 135 /**
136 * Test get() method for an undefined bookmark 136 * Test get() method for an undefined bookmark
137 *
138 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
139 */ 137 */
140 public function testGetUndefined() 138 public function testGetUndefined()
141 { 139 {
140 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
141
142 $this->privateLinkDB->get(666); 142 $this->privateLinkDB->get(666);
143 } 143 }
144 144
@@ -230,13 +230,13 @@ class BookmarkFileServiceTest extends TestCase
230 230
231 /** 231 /**
232 * Test add() method for a bookmark without any field set and without writing the data store 232 * Test add() method for a bookmark without any field set and without writing the data store
233 *
234 * @expectedExceptionMessage Shaarli\Bookmark\Exception\BookmarkNotFoundException
235 */ 233 */
236 public function testAddMinimalNoWrite() 234 public function testAddMinimalNoWrite()
237 { 235 {
236 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
237
238 $bookmark = new Bookmark(); 238 $bookmark = new Bookmark();
239 $this->privateLinkDB->add($bookmark); 239 $this->privateLinkDB->add($bookmark, false);
240 240
241 $bookmark = $this->privateLinkDB->get(43); 241 $bookmark = $this->privateLinkDB->get(43);
242 $this->assertEquals(43, $bookmark->getId()); 242 $this->assertEquals(43, $bookmark->getId());
@@ -249,34 +249,34 @@ class BookmarkFileServiceTest extends TestCase
249 249
250 /** 250 /**
251 * Test add() method while logged out 251 * Test add() method while logged out
252 *
253 * @expectedException \Exception
254 * @expectedExceptionMessage You're not authorized to alter the datastore
255 */ 252 */
256 public function testAddLoggedOut() 253 public function testAddLoggedOut()
257 { 254 {
255 $this->expectException(\Exception::class);
256 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
257
258 $this->publicLinkDB->add(new Bookmark()); 258 $this->publicLinkDB->add(new Bookmark());
259 } 259 }
260 260
261 /** 261 /**
262 * Test add() method with an entry which is not a bookmark instance 262 * Test add() method with an entry which is not a bookmark instance
263 *
264 * @expectedException \Exception
265 * @expectedExceptionMessage Provided data is invalid
266 */ 263 */
267 public function testAddNotABookmark() 264 public function testAddNotABookmark()
268 { 265 {
266 $this->expectException(\Exception::class);
267 $this->expectExceptionMessage('Provided data is invalid');
268
269 $this->privateLinkDB->add(['title' => 'hi!']); 269 $this->privateLinkDB->add(['title' => 'hi!']);
270 } 270 }
271 271
272 /** 272 /**
273 * Test add() method with a Bookmark already containing an ID 273 * Test add() method with a Bookmark already containing an ID
274 *
275 * @expectedException \Exception
276 * @expectedExceptionMessage This bookmarks already exists
277 */ 274 */
278 public function testAddWithId() 275 public function testAddWithId()
279 { 276 {
277 $this->expectException(\Exception::class);
278 $this->expectExceptionMessage('This bookmarks already exists');
279
280 $bookmark = new Bookmark(); 280 $bookmark = new Bookmark();
281 $bookmark->setId(43); 281 $bookmark->setId(43);
282 $this->privateLinkDB->add($bookmark); 282 $this->privateLinkDB->add($bookmark);
@@ -397,44 +397,44 @@ class BookmarkFileServiceTest extends TestCase
397 397
398 /** 398 /**
399 * Test set() method while logged out 399 * Test set() method while logged out
400 *
401 * @expectedException \Exception
402 * @expectedExceptionMessage You're not authorized to alter the datastore
403 */ 400 */
404 public function testSetLoggedOut() 401 public function testSetLoggedOut()
405 { 402 {
403 $this->expectException(\Exception::class);
404 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
405
406 $this->publicLinkDB->set(new Bookmark()); 406 $this->publicLinkDB->set(new Bookmark());
407 } 407 }
408 408
409 /** 409 /**
410 * Test set() method with an entry which is not a bookmark instance 410 * Test set() method with an entry which is not a bookmark instance
411 *
412 * @expectedException \Exception
413 * @expectedExceptionMessage Provided data is invalid
414 */ 411 */
415 public function testSetNotABookmark() 412 public function testSetNotABookmark()
416 { 413 {
414 $this->expectException(\Exception::class);
415 $this->expectExceptionMessage('Provided data is invalid');
416
417 $this->privateLinkDB->set(['title' => 'hi!']); 417 $this->privateLinkDB->set(['title' => 'hi!']);
418 } 418 }
419 419
420 /** 420 /**
421 * Test set() method with a Bookmark without an ID defined. 421 * Test set() method with a Bookmark without an ID defined.
422 *
423 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
424 */ 422 */
425 public function testSetWithoutId() 423 public function testSetWithoutId()
426 { 424 {
425 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
426
427 $bookmark = new Bookmark(); 427 $bookmark = new Bookmark();
428 $this->privateLinkDB->set($bookmark); 428 $this->privateLinkDB->set($bookmark);
429 } 429 }
430 430
431 /** 431 /**
432 * Test set() method with a Bookmark with an unknow ID 432 * Test set() method with a Bookmark with an unknow ID
433 *
434 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
435 */ 433 */
436 public function testSetWithUnknownId() 434 public function testSetWithUnknownId()
437 { 435 {
436 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
437
438 $bookmark = new Bookmark(); 438 $bookmark = new Bookmark();
439 $bookmark->setId(666); 439 $bookmark->setId(666);
440 $this->privateLinkDB->set($bookmark); 440 $this->privateLinkDB->set($bookmark);
@@ -481,23 +481,23 @@ class BookmarkFileServiceTest extends TestCase
481 481
482 /** 482 /**
483 * Test addOrSet() method while logged out 483 * Test addOrSet() method while logged out
484 *
485 * @expectedException \Exception
486 * @expectedExceptionMessage You're not authorized to alter the datastore
487 */ 484 */
488 public function testAddOrSetLoggedOut() 485 public function testAddOrSetLoggedOut()
489 { 486 {
487 $this->expectException(\Exception::class);
488 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
489
490 $this->publicLinkDB->addOrSet(new Bookmark()); 490 $this->publicLinkDB->addOrSet(new Bookmark());
491 } 491 }
492 492
493 /** 493 /**
494 * Test addOrSet() method with an entry which is not a bookmark instance 494 * Test addOrSet() method with an entry which is not a bookmark instance
495 *
496 * @expectedException \Exception
497 * @expectedExceptionMessage Provided data is invalid
498 */ 495 */
499 public function testAddOrSetNotABookmark() 496 public function testAddOrSetNotABookmark()
500 { 497 {
498 $this->expectException(\Exception::class);
499 $this->expectExceptionMessage('Provided data is invalid');
500
501 $this->privateLinkDB->addOrSet(['title' => 'hi!']); 501 $this->privateLinkDB->addOrSet(['title' => 'hi!']);
502 } 502 }
503 503
@@ -524,11 +524,11 @@ class BookmarkFileServiceTest extends TestCase
524 524
525 /** 525 /**
526 * Test remove() method with an existing Bookmark 526 * Test remove() method with an existing Bookmark
527 *
528 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
529 */ 527 */
530 public function testRemoveExisting() 528 public function testRemoveExisting()
531 { 529 {
530 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
531
532 $bookmark = $this->privateLinkDB->get(42); 532 $bookmark = $this->privateLinkDB->get(42);
533 $this->privateLinkDB->remove($bookmark); 533 $this->privateLinkDB->remove($bookmark);
534 534
@@ -548,34 +548,34 @@ class BookmarkFileServiceTest extends TestCase
548 548
549 /** 549 /**
550 * Test remove() method while logged out 550 * Test remove() method while logged out
551 *
552 * @expectedException \Exception
553 * @expectedExceptionMessage You're not authorized to alter the datastore
554 */ 551 */
555 public function testRemoveLoggedOut() 552 public function testRemoveLoggedOut()
556 { 553 {
554 $this->expectException(\Exception::class);
555 $this->expectExceptionMessage('You\'re not authorized to alter the datastore');
556
557 $bookmark = $this->privateLinkDB->get(42); 557 $bookmark = $this->privateLinkDB->get(42);
558 $this->publicLinkDB->remove($bookmark); 558 $this->publicLinkDB->remove($bookmark);
559 } 559 }
560 560
561 /** 561 /**
562 * Test remove() method with an entry which is not a bookmark instance 562 * Test remove() method with an entry which is not a bookmark instance
563 *
564 * @expectedException \Exception
565 * @expectedExceptionMessage Provided data is invalid
566 */ 563 */
567 public function testRemoveNotABookmark() 564 public function testRemoveNotABookmark()
568 { 565 {
566 $this->expectException(\Exception::class);
567 $this->expectExceptionMessage('Provided data is invalid');
568
569 $this->privateLinkDB->remove(['title' => 'hi!']); 569 $this->privateLinkDB->remove(['title' => 'hi!']);
570 } 570 }
571 571
572 /** 572 /**
573 * Test remove() method with a Bookmark with an unknown ID 573 * Test remove() method with a Bookmark with an unknown ID
574 *
575 * @expectedException Shaarli\Bookmark\Exception\BookmarkNotFoundException
576 */ 574 */
577 public function testRemoveWithUnknownId() 575 public function testRemoveWithUnknownId()
578 { 576 {
577 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
578
579 $bookmark = new Bookmark(); 579 $bookmark = new Bookmark();
580 $bookmark->setId(666); 580 $bookmark->setId(666);
581 $this->privateLinkDB->remove($bookmark); 581 $this->privateLinkDB->remove($bookmark);
@@ -635,15 +635,15 @@ class BookmarkFileServiceTest extends TestCase
635 * to make sure that nothing have been broken in the migration process. 635 * to make sure that nothing have been broken in the migration process.
636 * They mostly cover search/filters. Some of them might be redundant with the previous ones. 636 * They mostly cover search/filters. Some of them might be redundant with the previous ones.
637 */ 637 */
638
639 /** 638 /**
640 * Attempt to instantiate a LinkDB whereas the datastore is not writable 639 * Attempt to instantiate a LinkDB whereas the datastore is not writable
641 * 640 *
642 * @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException 641 * @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException
643 * @expectedExceptionMessageRegExp #Couldn't load data from the data store file "null".*#
644 */ 642 */
645 public function testConstructDatastoreNotWriteable() 643 public function testConstructDatastoreNotWriteable()
646 { 644 {
645 $this->expectExceptionMessageRegExp('#Couldn\'t load data from the data store file "null".*#');
646
647 $conf = new ConfigManager('tests/utils/config/configJson'); 647 $conf = new ConfigManager('tests/utils/config/configJson');
648 $conf->set('resource.datastore', 'null/store.db'); 648 $conf->set('resource.datastore', 'null/store.db');
649 new BookmarkFileService($conf, $this->history, true); 649 new BookmarkFileService($conf, $this->history, true);
diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php
index 91e139c2..752631a5 100644
--- a/tests/bookmark/BookmarkFilterTest.php
+++ b/tests/bookmark/BookmarkFilterTest.php
@@ -213,20 +213,22 @@ class BookmarkFilterTest extends TestCase
213 /** 213 /**
214 * Use an invalid date format 214 * Use an invalid date format
215 * @expectedException Exception 215 * @expectedException Exception
216 * @expectedExceptionMessageRegExp /Invalid date format/
217 */ 216 */
218 public function testFilterInvalidDayWithChars() 217 public function testFilterInvalidDayWithChars()
219 { 218 {
219 $this->expectExceptionMessageRegExp('/Invalid date format/');
220
220 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away'); 221 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away');
221 } 222 }
222 223
223 /** 224 /**
224 * Use an invalid date format 225 * Use an invalid date format
225 * @expectedException Exception 226 * @expectedException Exception
226 * @expectedExceptionMessageRegExp /Invalid date format/
227 */ 227 */
228 public function testFilterInvalidDayDigits() 228 public function testFilterInvalidDayDigits()
229 { 229 {
230 $this->expectExceptionMessageRegExp('/Invalid date format/');
231
230 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20'); 232 self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20');
231 } 233 }
232 234
@@ -250,11 +252,11 @@ class BookmarkFilterTest extends TestCase
250 252
251 /** 253 /**
252 * No link for this hash 254 * No link for this hash
253 *
254 * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException
255 */ 255 */
256 public function testFilterUnknownSmallHash() 256 public function testFilterUnknownSmallHash()
257 { 257 {
258 $this->expectException(\Shaarli\Bookmark\Exception\BookmarkNotFoundException::class);
259
258 self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah'); 260 self::$linkFilter->filter(BookmarkFilter::$FILTER_HASH, 'Iblaah');
259 } 261 }
260 262