Skip to content

Instantly share code, notes, and snippets.

@adililhan
Created August 1, 2013 09:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adililhan/6129870 to your computer and use it in GitHub Desktop.
Save adililhan/6129870 to your computer and use it in GitHub Desktop.
Symfony'nin dependency injection componentinin kullanımını göstermek amacıyla hazırlanmış örnek sınıfın, test sınıfı.
<?php
/**
* Tests of DependencyInjection.php
*/
class ControllerTest extends PHPUnit_Framework_TestCase {
public function setUp() {
$this->obj = new Controller;
$mock = $this->getMock(('iCurrency'), array('getExchangeRate'));
$mock->expects($this->any())
->method('getExchangeRate')
->will($this->returnValue(1.93));
$mockOfiObject = $this->getMock(('iObject'), array('setInstance', 'getValue'), array($mock));
$mockOfiObject->expects($this->any())
->method('getValue')
->will($this->returnValue(1.93));
$this->obj->setObject($mock, $mockOfiObject);
}
/**
* @dataProvider trueValuesProvider
*/
public function testgetTLtoCurrencyTrueValues($expectedValue, $givenValue) {
$this->assertEquals($expectedValue, $this->obj->getTLtoCurrency($givenValue));
}
public function trueValuesProvider() {
return array(
array(1.93, 1.00),
array(3.86, 2.00),
array(4.825, 2.50),
array(246.9821, 127.97));
}
/**
* @expectedException InvalidArgumentException
* @dataProvider wrongValuesProvider
*/
public function testgetTLtoCurrencyWrongValues($givenValue) {
$this->obj->getTLtoCurrency($givenValue);
}
public function wrongValuesProvider() {
return array(
array(120),
array('string'),
array(1,2),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment