From 1fa1654de0527440d057c5ed05891bed6cc0b69c Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 18 Jun 2022 18:18:23 +0200 Subject: Fix concert tests. --- tests/ConcertTest.php | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'tests/ConcertTest.php') diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php index dc2a712..d84e6a9 100644 --- a/tests/ConcertTest.php +++ b/tests/ConcertTest.php @@ -38,7 +38,7 @@ final class ConcertTest extends WP_UnitTestCase $created_venues[] = GiglogAdmin_Venue::find_or_create($venue[0], $venue[1]); } - $today = date("Y-m-d"); + $today = new DateTime(); foreach (self::CONCERTS as $concert) { for ($i = 0; $i < $concert[2]; $i++) { @@ -49,10 +49,13 @@ final class ConcertTest extends WP_UnitTestCase $concert_name = $concert[0]; } + $offset = rand(1, 13); + $concert_date = $today->modify( "+$offset days" ); + self::$concerts[] = GiglogAdmin_Concert::create( $concert_name, $created_venues[$concert[1]]->id(), - $today, + $concert_date->format( 'Y-m-d' ), "https://example.com/tickets/42", "https://example.com/events/93"); } @@ -82,30 +85,30 @@ final class ConcertTest extends WP_UnitTestCase { $this->expectException(GiglogAdmin_DuplicateConcertException::class); - $venue = GiglogAdmin_Venue::find_or_create("a venue", "Somewhere"); - $today = date("Y-m-d"); + $origin = self::$concerts[0]; $new = GiglogAdmin_Concert::create( - "a concert", - $venue->id(), - $today, - "https://example.com/tickets/42", - "https://example.com/events/93"); + $origin->cname(), + $origin->venue()->id(), + $origin->cdate(), + $origin->tickets(), + $origin->eventlink() + ); } public function testCreateExistingConcertVariableCase() : void { $this->expectException(GiglogAdmin_DuplicateConcertException::class); - $venue = GiglogAdmin_Venue::find_or_create("a venue", "Somewhere"); - $today = date("Y-m-d"); + $origin = self::$concerts[0]; $new = GiglogAdmin_Concert::create( - "a CoNceRt", - $venue->id(), - $today, - "https://example.com/tickets/42", - "https://example.com/events/93"); + strtoupper( $origin->cname() ), + $origin->venue()->id(), + $origin->cdate(), + $origin->tickets(), + $origin->eventlink() + ); } public function testGetConcertByIdReturnsFullConcertObject() : void @@ -201,17 +204,17 @@ final class ConcertTest extends WP_UnitTestCase public function testFetchConcertByNameVenueAndDate() : void { + $origin = self::$concerts[0]; + $gigs = GiglogAdmin_Concert::find_concerts([ - 'name' => 'a concert', - 'venue' => 'a venue', - 'date' => date('Y-m-d') + 'name' => $origin->cname(), + 'venue' => $origin->venue()->name(), + 'date' => $origin->cdate(), ]); $this->assertEquals(1, count($gigs)); $gig = array_shift($gigs); - $this->assertEquals('a concert', $gig->cname()); - $this->assertEquals('a venue', $gig->venue()->name()); - $this->assertEquals(date('Y-m-d'), explode(' ', $gig->cdate())[0]); + $this->assertEquals($origin, $gig); } } -- cgit v1.2.3