-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@testWith feature #1151
Comments
@farafiri, can you please explain what exactly is the difference between the |
None. It's only syntactic sugar. Easer to write and read. Jumping around methods to find out what cases are tested is disturbing. |
@farafiri I guess one of the bright sides of having provider methods is that you can reuse them – not sure if that's a good practice, though. |
You are right, but in most cases you don't need reusability, in most cases you need readability. In case when programmer realise that he made bad choice using @testwith because he needs reusability/mock as parameter/whatever switching into @dataProvier is very easy and safe operation. |
@sebastianbergmann thoughts? I kind of like it. |
+1 from me :) Just make sure that internally the data provider infrastructure is reused. |
It would be great. Thank you. |
Hello, I came here to propose such feature. That nice it is already done. A few thoughts (according to: #1728). @sebastianbergmann @giorgiosironi Please express your opinions about them.
@dataProvider
0, 1, 1
1, 2, 3
20, 22, 42
Example 1 /**
* @dataProvider
* "EUR", "FR",
* "GBP", "UK"
* "USD", "US"
*/
public function testCountryUsesCurrency(Currency $currency, Country $country)
{
$this->assertTrue($country->isDefaultCurrency($currency));
}
/**
* @return Currency
*/
public function createCurrency($currency)
{
return new Currency($currency);
}
/**
* @return Country
*/
public function createCountry($country)
{
return new Country($country);
} Example 2 /**
* @dataProvider
* [49.95, "EUR"], "ACCEPTED", 49.95, "EUR"
* [39.95, "GBP"], "REFUSED", 0, "GBP"
*/
public function testCapturePayment(
Namespace_Order $order, Zend_Soap_Client $gateway,
$expectedAmount, $expectedCurrency
) {
$payment = new Payment($gateway, $order);
$transaction = $payment->capture();
$this->assertEquals($expectedAmount, $transaction->getAmount());
$this->assertEquals($expectedCurrency, $transaction->getCurrency());
}
/**
* @return Zend_Soap_Client
*/
public function createStubPaymentGateway($status)
{
$stub = $this->getMockBuilder('Zend_Soap_Client')->getMock();
$stub->method('getResult')->willReturn($status);
return $stub;
}
/**
* @return Namespace_Order
*/
public function createOrder($amount, $currency)
{
return new Namespace_Order($amount, $country);
} |
|
It would be great to have @testwith (like JUnit) feature:
I know that I can use @dataProvider but it overcomplicated and require to much code for most tasks.
The text was updated successfully, but these errors were encountered: