From 7160aacdc83cfcef9ffd795cec7e9397bfbb3698 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 15 Apr 2021 21:50:58 +0200 Subject: Make Band::create return band object, not just id. --- tests/BandTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/BandTest.php (limited to 'tests') diff --git a/tests/BandTest.php b/tests/BandTest.php new file mode 100644 index 0000000..764abe3 --- /dev/null +++ b/tests/BandTest.php @@ -0,0 +1,22 @@ + +// SPDX-FileCopyrightText: 2021 Harald Eilertsen +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +declare(strict_types=1); + +require __DIR__ . '/../includes/band.php'; + +final class BandTest extends WP_UnitTestCase +{ + public function testCreatingBandWithName(): void + { + $count = count(GiglogAdmin_Band::all_bands()); + + $band = GiglogAdmin_Band::create("The Flamboyant Blasphemers"); + + $this->assertEquals("The Flamboyant Blasphemers", $band->bandname()); + $this->assertEquals($count + 1, count(GiglogAdmin_Band::all_bands())); + } +} -- cgit v1.2.3 From a851dd35b8ead5e4688062ff0c6e94d83133b006 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 15 Apr 2021 22:22:40 +0200 Subject: Refactor Band::create into Band::find and ::create Not sure if it's a good idea to have `create` return an existing band. Will have to look at callsites to see if it should be renamed back or if the callsite should be changed. --- tests/BandTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/BandTest.php b/tests/BandTest.php index 764abe3..d3feb51 100644 --- a/tests/BandTest.php +++ b/tests/BandTest.php @@ -10,7 +10,7 @@ require __DIR__ . '/../includes/band.php'; final class BandTest extends WP_UnitTestCase { - public function testCreatingBandWithName(): void + public function testCreatingBandWithName() : void { $count = count(GiglogAdmin_Band::all_bands()); @@ -19,4 +19,12 @@ final class BandTest extends WP_UnitTestCase $this->assertEquals("The Flamboyant Blasphemers", $band->bandname()); $this->assertEquals($count + 1, count(GiglogAdmin_Band::all_bands())); } + + public function testCreateExistingBand() : void + { + $band1 = GiglogAdmin_Band::create("The Flamboyant Blasphemers"); + $band2 = GiglogAdmin_Band::create("The Flamboyant Blasphemers"); + + $this->assertEquals($band1->id(), $band2->id()); + } } -- cgit v1.2.3