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

PHPBackendApplication(4)MysqlAdvancedandEclipsewithPHPUnit

1MySQLAdvancedOperation

FIND_IN_SETisnotusingindex,itissaid.

publicfunctiongetStateIDsByZipCodes($zipCodes)

{

//setupbasefeatures

$logger=$this->ioc->getService("logger");

$query="

SELECT

zipcode,

statesid

FROM

zipcities

WHERE

find_in_set(zipcode,?)

";

//prepareparams

$zipParam=implode(",",$zipCodes);

$logger->debug("getStateIDsByZipCodesparams--------------");

$logger->debug("zipParam=".$zipParam);

$logger->debug("------------------------------------------");

$conn=$this->getStatsDBConn();

$stmt=$conn->prepare($query);

$stmt->bind_param("s",$zipParam);

$stmt->execute();

$result=$stmt->get_result();

//fetchalltherows

$data=$result->fetch_all(MYSQLI_ASSOC);

$this->closeDBConn($conn);

return$data;

}

SoIplantochangethattoIN

//prepareparams

$zipParam="(".implode(",",$zipCodes).")";

$logger->debug("getStateIDsByZipCodesparams--------------");

$logger->debug("zipParam=".$zipParam);

$logger->debug("------------------------------------------");

$query="

SELECT

zipcode,

statesid

FROM

zipcities

WHERE

zipcodeIN$zipParam

";

2ECLIPSEandPHPUNIT

Goto“EclipseMarketplace”andSearchfor“MakeGood”,acceptandinstallthatplugin.

http://kumamidori.github.io/php/2014/11/24/makegood_composer/

https://github.com/piece/makegood/releases

Icreateaclassnamedtests/bootstrap_test.php

<?php

require__DIR__.'/../vendor/autoload.php';

?>

Changethephpunit.xmlasfollow

<phpunitbootstrap="tests/bootstrap_test.php">

<testsuites>

<testsuitename="unitsuite">

<directory>tests</directory>

</testsuite>

</testsuites>

</phpunit>

SettheMakeGoodConfigurationasfollow:

PHPUnit

TestFolders=/projectname/tests/namespace_directory

PreloadScript:/projectname/tests/bootstrap_test.php

XMLConfigurationFile:/projectname/phpunit.xml

ThatisallIhave,Imayputmoreinitiationactionsinbootstrap_test.phplater,buttillnow,itisgood.

CheckPHPUNITVersion

>phpunit--version

PHPUnit5.4.2bySebastianBergmannandcontributors.

Inthecomposer.json,ifIhavethelatestversionofphpunit,Iwillgetsomeexceptionsasfollow:

"require-dev":{

"php":">=5.3.0",

"phpunit/phpunit":">=5.4.2",

"phpunit/dbunit":">=1.2",

"phpunit/php-invoker":"*"

}

Fatalerror:CalltoundefinedmethodPHPUnit_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.phponline128

IthinkitisrelatedtotheversionofMakeGood=3.1.1andPHPUNIT=5.4.4

SoIchangetheconfigurationtodowngradetheversion

"require-dev":{

"php":">=5.3.0",

"phpunit/phpunit":"^4",

"phpunit/dbunit":">=1.2",

"phpunit/php-invoker":"*"

}

PHPUNIT=4.8.26,itthrownewexceptions:

[PHPUnit_Framework_Exception]

Argument#3(NoValue)ofPHPUnit_TextUI_ResultPrinter::__construct()mustbeavaluefrom"never","auto"or"always"

ThenIcheckthephpunitversionlistfromthisURL

https://packagist.org/packages/phpunit/phpunit

Itriedtheversionasfollow,itworksperfectly.

"require-dev":{

"php":">=5.3.0",

"phpunit/phpunit":"~4.5.1",

"phpunit/dbunit":">=1.2",

"phpunit/php-invoker":"*"

}

Bytheway,IamusingEclipselatestversionrightnow,itis

EclipseforPHPDevelopers

Version:NeonReleaseCandidate3(4.6.0RC3)

Buildid:20160602-0837

References:

ExceptionHandler

http://blog.csdn.net/hguisu/article/details/7464977

http://php.net/manual/en/language.exceptions.php

相关推荐