Created
December 4, 2013 11:04
-
-
Save johannesnagl/7785842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('Controller', 'Controller'); | |
App::uses('CakeRequest', 'Network'); | |
App::uses('CakeResponse', 'Network'); | |
App::uses('ComponentCollection', 'Controller'); | |
App::uses('StatisticComponent', 'Controller/Component'); | |
// A fake controller to test against | |
class TestStatisticController extends Controller { | |
} | |
class StatisticComponentTest extends CakeTestCase { | |
public $StatisticComponent = null; | |
public $Controller = null; | |
public function setUp() { | |
parent::setUp(); | |
// Setup our component and fake test controller | |
$Collection = new ComponentCollection(); | |
$this->StatisticComponent = new StatisticComponent($Collection); | |
$CakeRequest = new CakeRequest(); | |
$CakeResponse = new CakeResponse(); | |
$this->Controller = new TestStatisticController($CakeRequest, $CakeResponse); | |
$this->StatisticComponent->startup($this->Controller); | |
} | |
public function testCalcIncreasePercent() { | |
$result = $this->StatisticComponent->calcIncreasePercent(1, 0); | |
$this->assertEquals(0, $result); | |
$result = $this->StatisticComponent->calcIncreasePercent(20, 10); | |
$this->assertEquals(100.0, $result); | |
} | |
public function tearDown() { | |
parent::tearDown(); | |
// Clean up after we're done | |
unset($this->StatisticComponent); | |
unset($this->Controller); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment