summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-09-06 16:42:51 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-09-06 16:42:51 +0200
commitf0eb0199ec8de0e76c7b75ddc80275cde8f12818 (patch)
tree820415f748b7660d6c3ca1d74818210c31dc5a1c
parentfc842d4dd0d9af352640316601aaee398be8b636 (diff)
downloadgigologadmin-f0eb0199ec8de0e76c7b75ddc80275cde8f12818.tar.gz
gigologadmin-f0eb0199ec8de0e76c7b75ddc80275cde8f12818.tar.bz2
gigologadmin-f0eb0199ec8de0e76c7b75ddc80275cde8f12818.zip
Throw instead of log error from Concert class.
Should get rid of most of the annoying output during testing, and allow moving error handling and logging to the presentation layer.
-rw-r--r--includes/concert.php23
-rw-r--r--tests/ConcertTest.php8
2 files changed, 13 insertions, 18 deletions
diff --git a/includes/concert.php b/includes/concert.php
index f0a9ecd..089e9a7 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -7,6 +7,13 @@
require_once __DIR__ . '/venue.php';
+if ( !class_exists('GiglogAdmin_DuplicateConcertException') )
+{
+ class GiglogAdmin_DuplicateConcertException extends Exception
+ {
+ }
+}
+
if ( !class_exists('GiglogAdmin_Concert') ) {
require_once __DIR__ . '/venue.php';
@@ -105,12 +112,8 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
]);
if (!empty($gigs)) {
- error_log( 'DUPLICATE ROW detected: '
- . ' CONCERT NAME ' . $name
- . ', VENUE ID ' . $venue_id
- . ', CONCERTDATE ' . $date);
-
- return NULL;
+ throw new GiglogAdmin_DuplicateConcertException(
+ "Duplicate concert: name: {$name}, venue_id: {$venue_id}, date: {$date}");
}
else {
$concert = new GiglogAdmin_Concert( (object) [
@@ -123,14 +126,6 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
$concert->save();
- error_log( 'NEW CONCERT ADDED: '
- . ' ID: ' . $concert -> id()
- . ' CONCERT NAME ' . $name
- . ', VENUE ID ' . $venue_id
- . ', CONCERTDATE ' . $date
- . ', Ticket LINK ' . $ticketlink
- . ', Event LINK ' . $eventlink);
-
return $concert;
}
}
diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php
index 13df320..02ce58e 100644
--- a/tests/ConcertTest.php
+++ b/tests/ConcertTest.php
@@ -80,6 +80,8 @@ final class ConcertTest extends WP_UnitTestCase
public function testCreateExistingConcertShouldFail() : void
{
+ $this->expectException(GiglogAdmin_DuplicateConcertException::class);
+
$venue = GiglogAdmin_Venue::find_or_create("a venue", "Somewhere");
$today = date("Y-m-d");
@@ -89,12 +91,12 @@ final class ConcertTest extends WP_UnitTestCase
$today,
"https://example.com/tickets/42",
"https://example.com/events/93");
-
- $this->assertNull($new);
}
public function testCreateExistingConcertVariableCase() : void
{
+ $this->expectException(GiglogAdmin_DuplicateConcertException::class);
+
$venue = GiglogAdmin_Venue::find_or_create("a venue", "Somewhere");
$today = date("Y-m-d");
@@ -104,8 +106,6 @@ final class ConcertTest extends WP_UnitTestCase
$today,
"https://example.com/tickets/42",
"https://example.com/events/93");
-
- $this->assertNull($new);
}
public function testGetConcertByIdReturnsFullConcertObject() : void