Skip to content

Commit

Permalink
Junit runner working just enought
Browse files Browse the repository at this point in the history
  • Loading branch information
Amjad Mohamed committed Oct 22, 2011
1 parent 19b0656 commit 51a0295
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 100 deletions.
21 changes: 11 additions & 10 deletions build/build.xml
@@ -1,9 +1,10 @@
<project name="PHPSpec"> <project name="PHPSpec" default="pearify" basedir="..">


<property name="version" value="1.2.2" /> <property name="version" value="1.2.2" />
<property name="stability" value="beta" /> <property name="stability" value="beta" />
<property name="pear" value="pear" /> <property name="source" value="src" />
<property name="source" value="/md/dev/php/phpspec" /> <property name="build" value="build" />
<property name="pear" value="${build}/pear" />


<target name="clean" description="Clean build"> <target name="clean" description="Clean build">
<delete dir="${pear}" /> <delete dir="${pear}" />
Expand All @@ -12,15 +13,15 @@
<target name="init" description="Create build directory" depends="clean"> <target name="init" description="Create build directory" depends="clean">
<mkdir dir="${pear}" /> <mkdir dir="${pear}" />
<copy toDir="${pear}" > <copy toDir="${pear}" >
<fileset file="${source}/README.markdown" /> <fileset file="README.markdown" />
<fileset file="${source}/LICENSE" /> <fileset file="LICENSE" />
<fileset file="${source}/scripts/phpspec.php" /> <fileset file="scripts/phpspec.php" />
<fileset file="${source}/scripts/phpspec.bat" /> <fileset file="scripts/phpspec.bat" />
</copy> </copy>


<mkdir dir="${pear}/PHPSpec" /> <mkdir dir="${pear}/PHPSpec" />
<copy toDir="${pear}/PHPSpec" > <copy toDir="${pear}/PHPSpec" >
<fileset dir="${source}/src/PHPSpec" /> <fileset dir="${source}/PHPSpec" />
</copy> </copy>


<delete dir="${pear}/PHPSpec/Mocks" /> <delete dir="${pear}/PHPSpec/Mocks" />
Expand All @@ -29,12 +30,12 @@


<target name="code-sniffer" description="Check standards" depends="init"> <target name="code-sniffer" description="Check standards" depends="init">
<exec executable="phpcs" dir="${pear}/PHPSpec" failonerror="on"> <exec executable="phpcs" dir="${pear}/PHPSpec" failonerror="on">
<arg line="--standard=Zend --ignore=*Functions.php ." /> <arg line="--standard=Zend --ignore=*Functions.php -n ." />
</exec> </exec>
</target> </target>


<target name="pearify" description="Create the package.xml" depends="code-sniffer"> <target name="pearify" description="Create the package.xml" depends="code-sniffer">
<exec executable="pearify"> <exec executable="build/pearify">
<arg line="${pear} ${version} ${stability}" /> <arg line="${pear} ${version} ${stability}" />
</exec> </exec>
</target> </target>
Expand Down
2 changes: 2 additions & 0 deletions scripts/phpspec.php
Expand Up @@ -173,9 +173,11 @@
error_reporting(E_ALL|E_STRICT); error_reporting(E_ALL|E_STRICT);


require_once 'PHPSpec/Loader/UniversalClassLoader.php'; require_once 'PHPSpec/Loader/UniversalClassLoader.php';
include_once 'Mockery.php';
$paths = explode(':', ini_get('include_path')); $paths = explode(':', ini_get('include_path'));
$loader = new \PHPSpec\Loader\UniversalClassLoader(); $loader = new \PHPSpec\Loader\UniversalClassLoader();
$loader->registerNamespace('PHPSpec', $paths); $loader->registerNamespace('PHPSpec', $paths);
$loader->registerNamespace('Mockery', $paths);
$loader->register(); $loader->register();


$phpspec = new \PHPSpec\PHPSpec($argv); $phpspec = new \PHPSpec\PHPSpec($argv);
Expand Down
12 changes: 10 additions & 2 deletions src/PHPSpec/Matcher/Equal.php
Expand Up @@ -96,12 +96,20 @@ public function matches($actual, $epsilon = null)
} }
if (is_object($this->_expected) && is_object($this->_actual) && if (is_object($this->_expected) && is_object($this->_actual) &&
(get_class($this->_expected) === get_class($this->_actual))) { (get_class($this->_expected) === get_class($this->_actual))) {
return $this->_expected === $this->_actual; if ($epsilon === true) {
return $this->_expected === $this->_actual;
} else {
return $this->_expected == $this->_actual;
}
} }


if (is_array($this->_actual) && is_array($this->_expected)) { if (is_array($this->_actual) && is_array($this->_expected)) {
// compare arrays - we'll curently enforce key equality // compare arrays - we'll curently enforce key equality
return $this->_expected === $this->_actual; if ($epsilon === true) {
return $this->_expected === $this->_actual;
} else {
return $this->_expected == $this->_actual;
}
} }


if (!is_array($this->_expected) && !is_array($this->_actual) && if (!is_array($this->_expected) && !is_array($this->_actual) &&
Expand Down
67 changes: 67 additions & 0 deletions src/PHPSpec/Runner/Formatter/FormatterAbstract.php
@@ -0,0 +1,67 @@
<?php
/**
* PHPSpec
*
* LICENSE
*
* This file is subject to the GNU Lesser General Public License Version 3
* that is bundled with this package in the file LICENSE.
* It is also available through the world-wide-web at this URL:
* http://www.gnu.org/licenses/lgpl-3.0.txt
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@phpspec.net so we can send you a copy immediately.
*
* @category PHPSpec
* @package PHPSpec
* @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
* @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
* Marcello Duarte
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
namespace PHPSpec\Runner\Formatter;

/**
* @category PHPSpec
* @package PHPSpec
* @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
* @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
* Marcello Duarte
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
use PHPSpec\Runner\Formatter;

abstract class FormatterAbstract implements Formatter
{

/**
* Listens to events from the reporter, and calls appropriate methods to
* update the output
*
* @param SplSubject $method
* @param unknown $reporterEvent
*/
public function update(\SplSubject $method, $reporterEvent = null)
{
switch ($reporterEvent->event) {
case 'start':
$this->_startRenderingExampleGroup($reporterEvent);
break;
case 'finish':
$this->_finishRenderingExampleGroup();
break;
case 'status':
$this->_renderExamples($reporterEvent);
break;
case 'exit':
$this->output();
exit(0);
break;
}
}

abstract protected function _startRenderingExampleGroup($reporterEvent);
abstract protected function _finishRenderingExampleGroup();
abstract protected function _renderExamples($reporterEvent);

}
28 changes: 3 additions & 25 deletions src/PHPSpec/Runner/Formatter/Html.php
Expand Up @@ -100,28 +100,6 @@ protected function getResults()
return $this->_result; return $this->_result;
} }


/**
* Listens to events from the reporter to interact with the HTML report
* as things happens
*/
public function update(\SplSubject $method, $reporterEvent = null)
{
switch ($reporterEvent->event) {
case 'start' :
$this->startRenderingExampleGroup($reporterEvent);
break;
case 'finish' :
$this->finishRenderingExampleGroup();
break;
case 'status' :
$this->rendersExamplesSpecdox($reporterEvent);
break;
case 'exit':
$this->output();
exit;
break;
}
}
/** /**
* Gets the template directory * Gets the template directory
* *
Expand Down Expand Up @@ -157,7 +135,7 @@ public function put($output)
* *
* @param ReporterEvent $reporterEvent * @param ReporterEvent $reporterEvent
*/ */
private function startRenderingExampleGroup($reporterEvent) protected function _startRenderingExampleGroup($reporterEvent)
{ {
static $groupIndex = 1; static $groupIndex = 1;
$template = new \Text_Template( $template = new \Text_Template(
Expand All @@ -175,7 +153,7 @@ private function startRenderingExampleGroup($reporterEvent)
/** /**
* Finishes rendering example group * Finishes rendering example group
*/ */
private function finishRenderingExampleGroup() protected function _finishRenderingExampleGroup()
{ {
$template = new \Text_Template( $template = new \Text_Template(
$this->templateDir() . '/GroupEnd.html.dist' $this->templateDir() . '/GroupEnd.html.dist'
Expand All @@ -190,7 +168,7 @@ private function finishRenderingExampleGroup()
* *
* @param ReporterEvent $reporterEvent * @param ReporterEvent $reporterEvent
*/ */
private function rendersExamplesSpecdox($reporterEvent) protected function _renderExamples($reporterEvent)
{ {
$this->_examples .= $this->specdox( $this->_examples .= $this->specdox(
$reporterEvent->status, $reporterEvent->example, $reporterEvent->status, $reporterEvent->example,
Expand Down

0 comments on commit 51a0295

Please sign in to comment.