diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2021-04-18 14:33:01 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2021-04-18 15:05:58 +0200 |
commit | b70a0cd7d16f09687d54562a8c3d4cf9ac7160f1 (patch) | |
tree | 6aaeef2d48d76e16b3ca3b923887b2288e46fc79 | |
parent | 3025047ed4a8ee805bbf59f27c58146490cf885d (diff) | |
download | gigologadmin-b70a0cd7d16f09687d54562a8c3d4cf9ac7160f1.tar.gz gigologadmin-b70a0cd7d16f09687d54562a8c3d4cf9ac7160f1.tar.bz2 gigologadmin-b70a0cd7d16f09687d54562a8c3d4cf9ac7160f1.zip |
Refactor BandTest.
Set up a test env before running the test cases.
-rw-r--r-- | tests/BandTest.php | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/tests/BandTest.php b/tests/BandTest.php index 98aa331..33b14f4 100644 --- a/tests/BandTest.php +++ b/tests/BandTest.php @@ -10,45 +10,54 @@ require __DIR__ . '/../includes/band.php'; final class BandTest extends WP_UnitTestCase { + /* This function runs _once_ before all the test cases. + * + * Use it to set up a common state that all test cases can + * use + */ + static function wpSetUpBeforeClass() : void + { + GiglogAdmin_Band::create("The Flamboyant Blasphemers"); + } + public function testCreatingBandWithName() : void { $count = count(GiglogAdmin_Band::all_bands()); - $band = GiglogAdmin_Band::create("The Flamboyant Blasphemers"); + $band = GiglogAdmin_Band::create("Tullerusk"); - $this->assertEquals("The Flamboyant Blasphemers", $band->bandname()); + $this->assertEquals("Tullerusk", $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"); + $count = count(GiglogAdmin_Band::all_bands()); + + $existing_band = GiglogAdmin_Band::find("The Flamboyant Blasphemers", "NO"); + $new_band = GiglogAdmin_Band::create("The Flamboyant Blasphemers"); - $this->assertEquals($band1->id(), $band2->id()); + $this->assertEquals($count, count(GiglogAdmin_Band::all_bands())); + $this->assertEquals($existing_band->id(), $new_band->id()); } public function testCreateBandsWithSameNameInDifferentCountry() : void { - $band1 = GiglogAdmin_Band::create("The Flamboyant Blasphemers", "RO"); - $band2 = GiglogAdmin_Band::create("The Flamboyant Blasphemers", "NO"); + $existing_band = GiglogAdmin_Band::find("The Flamboyant Blasphemers", "NO"); + $new_band = GiglogAdmin_Band::create("The Flamboyant Blasphemers", "RO"); - $this->assertNotEquals($band1->id(), $band2->id()); + $this->assertNotEquals($existing_band->id(), $new_band->id()); } public function testFindExistingBandReturnsObject() : void { - $created = GiglogAdmin_Band::create("The Flamboyant Blasphemers", "RO"); - $found = GiglogAdmin_Band::find("The Flamboyant Blasphemers", "RO"); + $found = GiglogAdmin_Band::find("The Flamboyant Blasphemers", "NO"); $this->assertNotNull($found); - $this->assertEquals($created->id(), $found->id()); } public function testFindNonExistingBandReturnsNULL() : void { - $band1 = GiglogAdmin_Band::create("The Flamboyant Blasphemers", "RO"); - // Nice, UK isn't in the country list, so let's move Venom to Azerbajan // for now... $found = GiglogAdmin_Band::find("Venom", "AZ"); |