是否可以将此java代码段转换为php?
public void testBalanceReturnsToZeroOnVending()
{
sodaVendor.insertCoin(50);
sodaVendor.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());
}
答案 0 :(得分:5)
假设PHPUnit是您的单元测试框架:
<?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");
}
}
?>
答案 1 :(得分:0)
任何Java代码都可以转换为PHP
答案 2 :(得分:0)
是的,您可以将Java代码“翻译”为PHP。只是你可以在问题中解释一下你要参加的事情。
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());
}