Skip to content

Instantly share code, notes, and snippets.

@johannesnagl
Created December 4, 2013 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johannesnagl/7785842 to your computer and use it in GitHub Desktop.
Save johannesnagl/7785842 to your computer and use it in GitHub Desktop.
<?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