PHP Backend Application(4)Mysql Advanced and Eclipse with PHPUnit

本文详细介绍了如何优化PHP后端应用,使用Mysql高级操作和Eclipse配合PHPUnit进行测试,解决配置问题及版本兼容性挑战。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PHP Backend Application(4)Mysql Advanced and Eclipse with PHPUnit

1 MySQL Advanced Operation
FIND_IN_SET is not using index, it is said.
public function getStateIDsByZipCodes($zipCodes)
{
//set up base features
$logger = $this->ioc->getService("logger");

$query = "
SELECT
zipcode,
statesid
FROM
zipcities
WHERE
find_in_set(zipcode, ?)
";

//prepare params
$zipParam = implode(",", $zipCodes);
$logger->debug("getStateIDsByZipCodes params--------------");
$logger->debug("zipParam = " . $zipParam);
$logger->debug("------------------------------------------");

$conn = $this->getStatsDBConn();
$stmt = $conn->prepare($query);
$stmt->bind_param("s", $zipParam);
$stmt->execute();

$result = $stmt->get_result();
//fetch all the rows
$data = $result->fetch_all(MYSQLI_ASSOC);

$this->closeDBConn($conn);
return $data;
}

So I plan to change that to IN
//prepare params
$zipParam = "(".implode(",", $zipCodes).")";
$logger->debug("getStateIDsByZipCodes params--------------");
$logger->debug("zipParam = " . $zipParam);
$logger->debug("------------------------------------------");

$query = "
SELECT
zipcode,
statesid
FROM
zipcities
WHERE
zipcode IN $zipParam
";

2 ECLIPSE and PHPUNIT
Go to “Eclipse Marketplace” and Search for “MakeGood”, accept and install that plugin.
http://kumamidori.github.io/php/2014/11/24/makegood_composer/
https://github.com/piece/makegood/releases

I create a class named tests/bootstrap_test.php
<?php

require __DIR__.'/../vendor/autoload.php';
?>

Change the phpunit.xml as follow
<phpunit bootstrap="tests/bootstrap_test.php">
<testsuites>
<testsuite name="unitsuite">
<directory>tests</directory>
</testsuite>
</testsuites>

</phpunit>

Set the MakeGood Configuration as follow:
PHPUnit
Test Folders = /projectname/tests/namespace_directory
Preload Script: /projectname/tests/bootstrap_test.php
XML Configuration File: /projectname/phpunit.xml

That is all I have, I may put more initiation actions in bootstrap_test.php later, but till now, it is good.

Check PHPUNIT Version
> phpunit --version
PHPUnit 5.4.2 by Sebastian Bergmann and contributors.

In the composer.json, if I have the latest version of phpunit, I will get some exceptions as follow:
"require-dev": {
"php": ">=5.3.0",
"phpunit/phpunit": ">=5.4.2",
"phpunit/dbunit": ">=1.2",
"phpunit/php-invoker": "*"
}

Fatal error: Call to undefined method PHPUnit_Util_Configuration::getSeleniumBrowserConfiguration() in /Applications/Eclipse.app/Contents/Eclipse/plugins/com.piece_framework.makegood.stagehandtestrunner_3.1.1.v201409021510/resources/php/vendor/piece/stagehand-testrunner/src/Preparer/PHPUnitPreparer.php on line 128

I think it is related to the version of MakeGood=3.1.1 and PHPUNIT=5.4.4

So I change the configuration to downgrade the version
"require-dev": {
"php": ">=5.3.0",
"phpunit/phpunit": "^4",
"phpunit/dbunit": ">=1.2",
"phpunit/php-invoker": "*"
}

PHPUNIT=4.8.26, it throw new exceptions:
[PHPUnit_Framework_Exception]

Argument #3 (No Value) of PHPUnit_TextUI_ResultPrinter::__construct() must be a value from "never", "auto" or "always"

Then I check the phpunit version list from this URL
https://packagist.org/packages/phpunit/phpunit

I tried the version as follow, it works perfectly.
"require-dev": {
"php": ">=5.3.0",
"phpunit/phpunit": "~4.5.1",
"phpunit/dbunit": ">=1.2",
"phpunit/php-invoker": "*"
}

By the way, I am using Eclipse latest version right now, it is

Eclipse for PHP Developers

Version: Neon Release Candidate 3 (4.6.0RC3)
Build id: 20160602-0837

References:
Exception Handler
http://blog.youkuaiyun.com/hguisu/article/details/7464977
http://php.net/manual/en/language.exceptions.php
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值