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.csdn.net/hguisu/article/details/7464977
http://php.net/manual/en/language.exceptions.php
PHP Backend Application(4)Mysql Advanced and Eclipse with PHPUnit
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326851625&siteId=291194637
Recommended
Ranking