[英]Java conversion to php?
是否可以将此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());
}
假设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");
}
}
?>
任何Java代码都可以转换为PHP
是的,您可以将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());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.