Java转换为php?

New*_*ewb 0 php java

有可能将这个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());
        }
Run Code Online (Sandbox Code Playgroud)

Asa*_*aph 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");
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

  • @Asaph:我删除了我的downvote,因为你修复了错误并删除了屈尊俯就.但是为了记录,我不相信"它不是火箭科学"是适合任何*问题的东西,特别是当它被一个相对较新的用户提出时. (2认同)
  • "这不是火箭科学"是居高临下的吗?主观.我不敢苟同. (2认同)