Permalink
Browse files

Refactored library and tests

So I'm a pedant, and it was really bothering me that the test was testing
KingDiamond and not the track Melissa.  Considering that the track Melissa could
be a model and burning Melissa was business logic, I refactored the test along
those lines.  This is actually an integration or functional test, but for the
purposes of lulz it's close enough.
  • Loading branch information...
1 parent cbb3c41 commit 2325faa0192bc777ac5fbbb92cdc871d459cfd60 @jeremykendall committed Sep 15, 2012
@@ -0,0 +1,33 @@
+<?php
+
+namespace MercyfulFate\Album\Melissa\Track;
+
+class Melissa
+{
+ /**
+ * @var MercyfulFate\KingDiamond
+ */
+ protected $king;
+
+ /**
+ * @var MercyfulFate\Priest
+ */
+ protected $priest;
+
+ /**
+ * @var MercyfulFate\Witch\Melissa
+ */
+ protected $melissa;
+
+ public function __construct(\MercyfulFate\KingDiamond $king, \MercyfulFate\Witch\Melissa $melissa, \MercyfulFate\Priest $priest)
+ {
+ $this->king = $king;
+ $this->melissa = $melissa;
+ $this->priest = $priest;
+ }
+
+ public function priestBurnsWitch()
+ {
+ $this->priest->burnAtStake($this->melissa);
+ }
+}
@@ -0,0 +1,58 @@
+<?php
+
+namespace MercyfulFate\Album\Melissa\Track;
+
+use MercyfulFate\KingDiamond;
+use MercyfulFate\Priest;
+use MercyfulFate\Witch\Melissa as WitchMelissa;
+use MercyfulFate\Album\Melissa\Track\Melissa as TrackMelissa;
+
+class MelissaTest extends \PHPUnit_Framework_TestCase
+{
+
+ /**
+ * @var MercyfulFate\KingDiamond
+ */
+ protected $king;
+
+ /**
+ * @var MercyfulFate\Priest
+ */
+ protected $priest;
+
+ /**
+ * @var MercyfulFate\Witch\Melissa
+ */
+ protected $witch;
+
+ /**
+ * @var MercyfulFate\Album\Melissa\Track\Melissa
+ */
+ protected $trackMelissa;
+
+ protected function setUp()
+ {
+ $this->king = new KingDiamond();
+ $this->priest = new Priest();
+ $this->priest->attach($this->king);
+ $this->witch = new WitchMelissa();
+ $this->trackMelissa = new TrackMelissa($this->king, $this->witch, $this->priest);
+ }
+
+ protected function tearDown()
+ {
+ $this->trackMelissa = null;
+ }
+
+ public function testBurnMelissa()
+ {
+ $this->assertFalse($this->witch->isBurned());
+ $this->assertFalse($this->king->swearsRevenge());
+
+ $this->trackMelissa->priestBurnsWitch();
+
+ $this->assertTrue($this->witch->isBurned());
+ $this->assertTrue($this->king->swearsRevenge());
+ }
+
+}
@@ -1,45 +0,0 @@
-<?php
-
-namespace MercyfulFate;
-
-/**
- * Tests the premise of the Mercyful Fate song "Melissa"
- */
-class KingDiamondTest extends \PHPUnit_Framework_TestCase
-{
-
- /**
- * @var KingDiamond
- */
- protected $king;
-
- /**
- * @var Priest
- */
- protected $priest;
-
- /**
- * @var Witch\Melissa
- */
- protected $witch;
-
- protected function setUp()
- {
- $this->king = new KingDiamond();
- $this->priest = new Priest();
- $this->priest->attach($this->king);
- $this->witch = new Witch\Melissa();
- }
-
- public function testKingSwearsRevengeOnPriest()
- {
- $this->assertFalse($this->witch->isBurned());
- $this->assertFalse($this->king->swearsRevenge());
-
- $this->priest->burnAtStake($this->witch);
-
- $this->assertTrue($this->witch->isBurned());
- $this->assertTrue($this->king->swearsRevenge());
- }
-
-}

0 comments on commit 2325faa

Please sign in to comment.