8 years of Java, Python and BASH Next is php Some docker some CI/CD and a little bit TDD Through AWS and Azure CentOS and Mac One Life
2016年12月20日 星期二
2016年12月13日 星期二
php array to html table
function build_table($array){
// start table
$html = '<table>';
// header row
$html .= '<tr>';
foreach($array[0] as $key=>$value){
$html .= '<th>' . $key . '</th>';
}
$html .= '</tr>';
// data rows
foreach( $array as $key=>$value){
$html .= '<tr>';
foreach($value as $key2=>$value2){
$html .= '<td>' . $value2 . '</td>';
}
$html .= '</tr>';
}
// finish table and return it
$html .= '</table>';
return $html;
}
// start table
$html = '<table>';
// header row
$html .= '<tr>';
foreach($array[0] as $key=>$value){
$html .= '<th>' . $key . '</th>';
}
$html .= '</tr>';
// data rows
foreach( $array as $key=>$value){
$html .= '<tr>';
foreach($value as $key2=>$value2){
$html .= '<td>' . $value2 . '</td>';
}
$html .= '</tr>';
}
// finish table and return it
$html .= '</table>';
return $html;
}
2016年11月24日 星期四
log4php and phpunit
https://hackpad.com/ep/pad/static/i2nReTrh1wr
log4php_config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://logging.apache.org/log4php/">
<appender name="default" class="LoggerAppenderDailyFile">
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date{m-d-Y H:i:s,u} [%process] %logger %-5level %file (%class.%method line: %line): %msg%n" />
</layout>
<param name="file" value="/var/log/apache2/php_addressbook-%s.log" />
<param name="datePattern" value="Y-m-d" />
</appender>
<appender name="echo" class="LoggerAppenderEcho">
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date{m-d-Y H:i:s,u} [%process] %logger %-5level %file (%class.%method line: %line): %msg%n" />
</layout>
<param name="htmlLineBreaks" value="false" />
</appender>
<root>
<level value="trace" />
<appender_ref ref="default" />
</root>
<logger name="unittest">
<level value="trace" />
<appender_ref ref="echo" />
</logger>
</configuration>
log4php_config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://logging.apache.org/log4php/">
<appender name="default" class="LoggerAppenderDailyFile">
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date{m-d-Y H:i:s,u} [%process] %logger %-5level %file (%class.%method line: %line): %msg%n" />
</layout>
<param name="file" value="/var/log/apache2/php_addressbook-%s.log" />
<param name="datePattern" value="Y-m-d" />
</appender>
<appender name="echo" class="LoggerAppenderEcho">
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date{m-d-Y H:i:s,u} [%process] %logger %-5level %file (%class.%method line: %line): %msg%n" />
</layout>
<param name="htmlLineBreaks" value="false" />
</appender>
<root>
<level value="trace" />
<appender_ref ref="default" />
</root>
<logger name="unittest">
<level value="trace" />
<appender_ref ref="echo" />
</logger>
</configuration>
sampleTest.php
<?php
include_once(’log4php/Logger.php’);
$log4php_config_path = "./resources/log4php_config.xml";
Logger::configure($log4php_config_path);
class baseTestCase extends PHPUnit_Framework_TestCase
{
protected static $testlog;
public function __construct() {
$this->testlog = Logger::getLogger(’unittest’);
}
public static function setUpBeforeClass() {
$testlog = Logger::getLogger(’unittest’);
$testlog->trace(’Setting up simpleTest class’);
}
public static function tearDownAfterClass() {
$testlog = Logger::getLogger(’unittest’);
$testlog->trace(’Tearing down simpleTest class’);
}
protected function setUp() {
$this->testlog->trace(’Setting up function’);
}
protected function tearDown() {
$this->testlog->trace(’Tearing down function’);
}
}
?>
include_once(’log4php/Logger.php’);
$log4php_config_path = "./resources/log4php_config.xml";
Logger::configure($log4php_config_path);
class baseTestCase extends PHPUnit_Framework_TestCase
{
protected static $testlog;
public function __construct() {
$this->testlog = Logger::getLogger(’unittest’);
}
public static function setUpBeforeClass() {
$testlog = Logger::getLogger(’unittest’);
$testlog->trace(’Setting up simpleTest class’);
}
public static function tearDownAfterClass() {
$testlog = Logger::getLogger(’unittest’);
$testlog->trace(’Tearing down simpleTest class’);
}
protected function setUp() {
$this->testlog->trace(’Setting up function’);
}
protected function tearDown() {
$this->testlog->trace(’Tearing down function’);
}
}
?>
Sonar in settings.xml
<settings>
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://localhost:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
</settings>
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://localhost:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
</settings>
Jacoco maven target
clean install -Djacoco.agent.path=”PATH_TO_AGENT” -Djacoco.file.path=”PATH_TO_DUMP” -Dsonar.jacoco.itReportPath=”PATH_TO_DUMP” sonar:sonar
org.jacoco:jacoco-maven-plugin:prepare-agent install
org.jacoco:jacoco-maven-plugin:prepare-agent install
訂閱:
文章 (Atom)