Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.