Is it possible to convert this java code snippet to php?
public void testBalanceReturnsToZeroOnVending()
{
sodaVendor.insertCoin(50);
sodaVendor开发者_JS百科.insertCoin(20);
sodaVendor.insertCoin(5);
// The price is right!
assertEquals("We have entered correct money",
SODA_PRICE,
sodaVendor.getCurrentBalance());
sodaVendor.dispenseItem();
assertEquals("After vending, the balance of soda vending machine is zero",
0,
sodaVendor.getCurrentBalance());
}
Assuming PHPUnit is your unit testing framework:
<?php
require_once 'PHPUnit/Framework.php';
// require the file containing the class that sodaVendor is an instance of
define('SODA_PRICE', 75);
class SodaVendorTest extends PHPUnit_Framework_TestCase {
private $sodaVendor;
public function setUp() {
// set up $this->sodaVendor somehow...
}
public function tearDown() {
$this->sodaVendor = null;
}
public function testBalanceReturnsToZeroOnVending() {
$this->sodaVendor->insertCoin(50);
$this->sodaVendor->insertCoin(20);
$this->sodaVendor->insertCoin(5);
// The price is right!
$this->assertEquals(SODA_PRICE,
$this->sodaVendor->getCurrentBalance(),
"We have entered correct money");
$this->sodaVendor->dispenseItem();
$this->assertEquals(0,
$this->sodaVendor->getCurrentBalance(),
"After vending, the balance of soda vending machine is zero");
}
}
?>
Any Java code can be converted to PHP
yes you can "translate" your Java code to PHP. Just it would have been nice you explain in the question a bit more what you are attending to do.
public function testBalanceReturnsToZeroOnVending()
{
$sodaVendor->insertCoin(50);
$sodaVendor->insertCoin(20);
$sodaVendor->insertCoin(5);
// The price is right!
assert("We have entered correct money",
SODA_PRICE ==
$sodaVendor->getCurrentBalance());
$sodaVendor->dispenseItem();
assert("After vending, the balance of soda vending machine is zero",
0 ==
$sodaVendor->getCurrentBalance());
}
精彩评论