Permalink
Browse files

Greatly trimming up phing tasks, travis config, and killing server af…

…ter tests. Addresses #469
  • Loading branch information...
1 parent 0d41a57 commit 5ad7211ee42b2bd1e7405c63cdac7e3a5515c006 @mtdowling mtdowling committed Nov 21, 2013
View
@@ -14,18 +14,9 @@ before_script:
- sh -c "cd pecl_http-1.7.6 && phpize && ./configure && make && sudo make install" > /dev/null
- echo "extension=http.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
- pecl install uri_template-beta
- - pear config-set auto_discover 1
- - pear install pear.phing.info/phing
- - pear install pear.phpunit.de/phploc
- - pear install pear/PHP_CodeSniffer
- - pear install pear.pdepend.org/PHP_Depend
- - pear install bartlett.laurent-laville.org/PHP_CompatInfo
- - pear install pear/PEAR_PackageFileManager2 pear/PEAR_PackageFileManager2_Plugins pear/XML_Serializer-beta
- - pear install VersionControl_Git-alpha
- phpenv rehash
- composer install --dev
- - cp phing/build.properties.travis phing/build.properties
- echo 'Ensuring the correct version of node is running'
- ~/.nvm/nvm.sh install v0.6.14
-script: phing travisci
+script: vendor/bin/phpunit
View
@@ -10,24 +10,14 @@
<property name="repo.dir" value="${project.basedir}" />
<import file="${dir.imports}/dependencies.xml"/>
- <import file="${dir.imports}/test.xml"/>
<import file="${dir.imports}/deploy.xml"/>
- <!-- <import file="${dir.imports}/metrics.xml"/> -->
-
- <target name="test" description="Run unit tests" depends="test-init">
- <trycatch>
- <try>
- <exec passthru="true" command="vendor/bin/phpunit" checkReturn="true" />
- </try>
- <finally>
- <testserver cmd="${cmd.testserver}" action="stop" />
- </finally>
- </trycatch>
+
+ <target name="composer-lint" description="lint-check composer.json only">
+ <composerlint dir="${project.basedir}/src" file="{$project.basedir}/composer.json" />
</target>
- <target name="test-init" depends="install-dependencies" description="Initialize test dependencies">
- <testserver cmd="${cmd.testserver}" action="start" />
- <copy file="phpunit.xml.dist" tofile="phpunit.xml" overwrite="false" />
+ <target name="test" description="Run unit tests">
+ <exec passthru="true" command="vendor/bin/phpunit" checkReturn="true" />
</target>
<target name="build-init" description="Initialize local phing properties">
@@ -39,7 +29,7 @@
<delete dir="${project.basedir}/build/pearwork"/>
</target>
- <target name="prepare" depends="clean,test-init,build-init">
+ <target name="prepare" depends="clean,build-init">
<mkdir dir="${dir.output}"/>
<mkdir dir="${dir.output}/logs" />
</target>
@@ -1,16 +0,0 @@
-# update this if you're working on a fork.
-guzzle.remote=git@github.com:guzzle/guzzle.git
-
-# github credentials -- only used by GitHub API calls to create subtree repos
-github.basicauth=username:password
-# for the subtree split and testing
-github.org=guzzle
-
-# your git path
-cmd.git=/usr/bin/git
-
-# your composer command
-cmd.composer=composer
-
-# test server start
-cmd.testserver="~/.nvm/nvm.sh run v0.6.14"
@@ -9,47 +9,9 @@
Our custom tasks
-->
<taskdef name="composerlint" classname="phing.tasks.ComposerLintTask" />
- <taskdef name="testserver" classname="phing.tasks.NodeServerTask" />
<taskdef name="guzzlesubsplit" classname="phing.tasks.GuzzleSubSplitTask" />
<taskdef name="guzzlepear" classname="phing.tasks.GuzzlePearPharPackageTask" />
- <!--
- Handle locating composer (global) or composer.phar, and
- if necessary, installing composer.phar locally.
- -->
- <target name="install-composer" description="Installs composer locally if it can't be found in build.properties or global install.">
- <if>
- <contains string="${cmd.composer}" substring="composer" />
- <then>
- <echo>Using composer at ${cmd.composer}</echo>
- </then>
- <else>
- <exec command="which composer" outputProperty="cmd.composer" />
- <if>
- <contains string="${cmd.composer}" substring="composer" />
- <then>
- <echo>Using composer at ${cmd.composer}</echo>
- </then>
-
- <elseif>
- <available file="${project.basedir}/composer.phar" />
- <then>
- <echo>Composer is installed locally</echo>
- <property name="cmd.composer" value="${php.interpreter} ${project.basedir}/composer.phar" override="true"/>
- </then>
- </elseif>
-
- <else>
- <echo message="Installing composer locally" />
- <exec command="curl -s http://getcomposer.org/installer | php" passthru="true" />
- <property name="cmd.composer" value="${php.interpreter} ${project.basedir}/composer.phar" override="true"/>
- </else>
- </if>
- </else>
- </if>
- <echo message="cmd.composer is ${cmd.composer}"/>
- </target>
-
<target name="find-git">
<if>
<contains string="${cmd.git}" substring="git" />
@@ -63,14 +25,6 @@
</if>
</target>
- <target name="install-dependencies" depends="install-composer">
- <exec command="${cmd.composer} install --dev" passthru="true" />
- </target>
-
- <target name="update-dependencies" depends="install-composer">
- <exec command="${cmd.composer} update --dev" passthru="true" />
- </target>
-
<target name="clean-dependencies">
<delete dir="${project.basedir}/vendor"/>
<delete file="${project.basedir}/composer.lock" />
View
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project basedir="../../" default="metrics">
-
- <target name="metrics" depends="phploc,pdepend"/>
-
- <target name="phploc" description="Measure project size using PHPLOC">
- <exec command="phploc --log-csv ${dir.output}/logs/phploc.csv ${project.basedir}/src" passthru="true"/>
- </target>
-
- <target name="pdepend" description="Calculate software metrics using PHP_Depend">
- <mkdir dir="${dir.output}/pdepend" />
- <phpdepend>
- <fileset dir="${project.basedir}/src">
- <include name="**/*.php" />
- </fileset>
- <logger type="jdepend-xml" outfile="${dir.output}/logs/jdepend.xml" />
- <logger type="jdepend-chart" outfile="${dir.output}/pdepend/dependencies.svg" />
- <logger type="overview-pyramid" outfile="${dir.output}/pdepend/overview-pyramid.svg" />
- <analyzer type="coderank-mode" value="method" />
- </phpdepend>
- </target>
-
-</project>
View
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project basedir="../../" default="preflight">
-
- <!-- instead of phingcall sub-tasks, use an empty target with deps -->
- <target name="preflight" depends="test-init,lint"/>
-
- <target name="travisci" depends="install-dependencies,composer-lint,php-lint,test"/>
-
- <target name="lint" depends="install-composer,composer-lint,php-lint" description="lint-check PHP and JSON" />
-
- <target name="composer-lint" description="lint-check composer.json only">
- <composerlint dir="${project.basedir}/src" file="{$project.basedir}/composer.json" />
- </target>
-
- <target name="php-lint" description="lint-check just the PHP source">
- <phplint level="info">
- <fileset dir="${project.basedir}/src">
- <include name="**/*.php" />
- </fileset>
- </phplint>
- <phplint level="info">
- <fileset dir="${project.basedir}/tests">
- <include name="**/*.php" />
- </fileset>
- </phplint>
- </target>
-
- <target name="sniff" description="Check code for PSR-2 compliance">
- <phpcodesniffer
- standard="PSR2"
- format="summary" />
-
- </target>
-</project>
@@ -1,118 +0,0 @@
-<?php
-/**
- * Phing task for node server checking
- *
- * @copyright 2012 Clay Loveless <clay@php.net>
- * @license http://claylo.mit-license.org/2012/ MIT License
- */
-
-require_once 'phing/Task.php';
-
-class NodeServerTask extends Task
-{
- protected $cmd = null;
- protected $action = 'start';
- protected $serverfile = 'tests/Guzzle/Tests/Http/server.js';
-
- /**
- * The setter for the start command
- *
- * @param string $str How to start the node server
- */
- public function setCmd($str)
- {
- $this->cmd = $str;
- }
-
- public function getCmd()
- {
- return $this->cmd;
- }
-
- /**
- * The setter for the action
- *
- * @param string $str Start up or shutdown
- */
- public function setAction($str)
- {
- $this->action = $str;
- }
- public function getAction()
- {
- return $this->action;
- }
-
- public function main()
- {
- $cmd = $this->getCmd();
- $action = $this->getAction();
-
- if (empty($cmd)) {
- throw new BuildException('"cmd" is a required parameter');
- }
-
- if ($action == 'start') {
- $this->startServer();
- } else {
- $this->stopServer();
- }
- }
-
- protected function startServer()
- {
- chdir(__DIR__ . '/../..');
- $serverfile = $this->serverfile;
- $cmd = $this->getCmd();
-
- // resolve $HOME directory
- if ($cmd[0] == '~') {
- $cmd = $_ENV["HOME"] . substr($cmd, 1);
- }
-
- $fp = @fsockopen('127.0.0.1', 8124, $errno, $errstr, 1);
- if (! $fp) {
- // need to start node server
- $cmd = escapeshellcmd($cmd . ' ' . $serverfile);
- $this->log('starting node test server with '.$cmd);
- exec($cmd . ' &> /dev/null &');
- sleep(2);
- $fp = @fsockopen('127.0.0.1', 8124, $errno, $errstr, 1);
- }
-
- // test it again
- if (! $fp) {
- $this->log('could not start node server');
- } else {
- fclose($fp);
- $this->log('node test server running');
- }
- }
-
- protected function stopServer()
- {
- exec('ps axo "pid,command"', $out);
- $nodeproc = false;
- foreach ($out as $proc) {
- if (strpos($proc, $this->serverfile) !== false) {
- $nodeproc = $proc;
- break;
- }
- }
-
- if ($nodeproc) {
- $proc = trim($nodeproc);
- $space = strpos($proc, ' ');
- $pid = substr($proc, 0, $space);
-
- $killed = posix_kill($pid, 9);
- if ($killed) {
- $this->log('test server stopped');
- } else {
- $this->log('test server appears immortal');
- }
- } else {
- $this->log('could not find test server in process list');
- }
- }
-}
@@ -49,6 +49,16 @@ public function __construct($port = null)
$this->client = new Client($this->getUrl());
}
+ public function __destruct()
+ {
+ try {
+ $this->stop();
+ } catch (\Exception $e) {
+ // Can't throw exceptions in destructor
+ echo "\n{$e}\n";
+ }
+ }
+
/**
* Flush the received requests from the server
* @throws RuntimeException

0 comments on commit 5ad7211

Please sign in to comment.