Permalink
Browse files

add initial test cases

  • Loading branch information...
llaville committed Mar 26, 2015
1 parent b44a256 commit be0718629748cb282dd05ff1b0b5e9f6c38e4f80
View
@@ -31,5 +31,10 @@
"psr-0": {
"Bartlett\\": "src/"
}
},
"autoload-dev": {
"psr-0": {
"Bartlett\\Tests\\UmlWriter\\": "tests/"
}
}
}
View
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnRisky="false"
stopOnSkipped="false"
verbose="false"
>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="UmlWriter Test Suite">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>
</phpunit>
View
@@ -0,0 +1,123 @@
<?php
/**
* Unit tests for PHP_CompatInfo package, issues reported
*
* PHP version 5
*
* @category PHP
* @package UmlWriter
* @subpackage Tests
* @author Laurent Laville <pear@laurent-laville.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version GIT: $Id$
* @link http://php5.laurent-laville.org/umlwriter/
* @since Class available since Release 1.0.0-RC2
*/
namespace Bartlett\Tests\UmlWriter;
/**
* Tests for PHP_CompatInfo, retrieving reference elements,
* and versioning information.
*
* @category PHP
* @package UmlWriter
* @subpackage Tests
* @author Laurent Laville <pear@laurent-laville.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link http://php5.laurent-laville.org/umlwriter/
*/
class ProcessorTest extends \PHPUnit_Framework_TestCase
{
private function generator($extFile)
{
$fixtures = __DIR__ . DIRECTORY_SEPARATOR
. 'fixtures' . DIRECTORY_SEPARATOR;
$graphs = array();
$iterator = new \DirectoryIterator($fixtures);
foreach ($iterator as $file) {
/* @var $file \SplFileInfo */
if (!preg_match('/\.php$/', $file)) {
continue;
}
$phpFile = $file->getRealpath();
$gFile = preg_replace('/\.php$/', $extFile, $file->getRealPath());
if (!file_exists($gFile)) {
continue;
}
$gCode = file_get_contents($gFile);
$graphs[] = array(
'phpFile' => $phpFile,
'graphStmts' => $gCode,
);
}
return $graphs;
}
/**
* Data Provider to test generation of graph statements with Graphviz processor
*
* @return array
*/
public function graphvizProvider()
{
return $this->generator('.gv');
}
/**
* Data Provider to test generation of graph statements with PlantUML processor
*
* @return array
*/
public function plantumlProvider()
{
return $this->generator('.puml');
}
/**
* Tests graph statements generation with the Graphviz processor
*
* @return void
* @dataProvider graphvizProvider
*/
public function testGraphvizProcessor($phpFile, $graphStmts)
{
// uses Bartlett\Reflect as reverse engine
$reflector = new \Bartlett\UmlWriter\Reflector\Reflect($phpFile);
// creates a new instance of Graphviz processor
$processor = new \Bartlett\UmlWriter\Processor\GraphvizProcessor($reflector);
// render a full graph with all objects
$gvStmts = $processor->setGraphId('G1')->render();
$this->assertEquals($graphStmts, $gvStmts);
}
/**
* Tests graph statements generation with the PlantUML processor
*
* @return void
* @dataProvider plantumlProvider
*/
public function testPlantUMLProcessor($phpFile, $graphStmts)
{
// uses Bartlett\Reflect as reverse engine
$reflector = new \Bartlett\UmlWriter\Reflector\Reflect($phpFile);
// creates a new instance of PlantUML processor
$processor = new \Bartlett\UmlWriter\Processor\PlantUMLProcessor($reflector);
// render a full graph with all objects
$pumlStmts = $processor->render();
$this->assertEquals($graphStmts, $pumlStmts);
}
}
View
@@ -0,0 +1,6 @@
<?php
$baseDir = dirname(__DIR__);
$vendorDir = $baseDir . '/vendor';
require_once $vendorDir . '/autoload.php';
@@ -0,0 +1,15 @@
digraph G1 {
overlap = false;
node [fontname="Verdana", fontsize="8", shape="none", margin="0", fillcolor="#FEFECE", style="filled"];
edge [fontname="Verdana", fontsize="8"];
subgraph cluster_0 {
label="";
"OneClass" [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td align="center">&lt;&lt; <font color="black"><i>class</i></font> &gt;&gt;<br/><b>OneClass</b></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
>];
}
}
@@ -0,0 +1,4 @@
<?php
class OneClass
{
}
@@ -0,0 +1,2 @@
class OneClass << class >> {
}
@@ -0,0 +1,23 @@
digraph G1 {
overlap = false;
node [fontname="Verdana", fontsize="8", shape="none", margin="0", fillcolor="#FEFECE", style="filled"];
edge [fontname="Verdana", fontsize="8"];
subgraph cluster_1 {
label="";
"OneClass" [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td align="center">&lt;&lt; <font color="black"><i>class</i></font> &gt;&gt;<br/><b>OneClass</b></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
>];
"TwoClass" [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td align="center">&lt;&lt; <font color="black"><i>class</i></font> &gt;&gt;<br/><b>TwoClass</b></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
>];
}
"TwoClass" -> "OneClass";
}
@@ -0,0 +1,6 @@
<?php
class OneClass {
}
class TwoClass extends OneClass {
}
@@ -0,0 +1,5 @@
class OneClass << class >> {
}
class TwoClass << class >> {
}
TwoClass --|> OneClass
@@ -0,0 +1,39 @@
digraph G1 {
overlap = false;
node [fontname="Verdana", fontsize="8", shape="none", margin="0", fillcolor="#FEFECE", style="filled"];
edge [fontname="Verdana", fontsize="8"];
subgraph cluster_2 {
label="";
"OneInterface" [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td align="center">&lt;&lt; <font color="black"><i>interface</i></font> &gt;&gt;<br/><b>OneInterface</b></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
>];
"TwoInterface" [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td align="center">&lt;&lt; <font color="black"><i>interface</i></font> &gt;&gt;<br/><b>TwoInterface</b></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
>];
"OneClass" [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td align="center">&lt;&lt; <font color="black"><i>class</i></font> &gt;&gt;<br/><b>OneClass</b></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
>];
"TwoClass" [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td align="center">&lt;&lt; <font color="black"><i>class</i></font> &gt;&gt;<br/><b>TwoClass</b></td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
>];
}
"TwoInterface" -> "OneInterface";
"OneClass" -> "OneInterface" [arrowhead="empty", style="dashed"];
"TwoClass" -> "TwoInterface" [arrowhead="empty", style="dashed"];
}
@@ -0,0 +1,16 @@
<?php
interface OneInterface
{
}
interface TwoInterface extends OneInterface
{
}
class OneClass implements OneInterface
{
}
class TwoClass implements TwoInterface
{
}
@@ -0,0 +1,11 @@
interface OneInterface << interface >> {
}
interface TwoInterface << interface >> {
}
class OneClass << class >> {
}
class TwoClass << class >> {
}
TwoInterface --|> OneInterface
OneClass ..|> OneInterface
TwoClass ..|> TwoInterface
@@ -0,0 +1,22 @@
digraph G1 {
overlap = false;
node [fontname="Verdana", fontsize="8", shape="none", margin="0", fillcolor="#FEFECE", style="filled"];
edge [fontname="Verdana", fontsize="8"];
subgraph cluster_3 {
label="";
"OneClass" [label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td align="center">&lt;&lt; <font color="black"><i>class</i></font> &gt;&gt;<br/><b>OneClass</b></td></tr>
<tr><td> </td></tr>
<tr><td><table border="0" cellspacing="0" cellpadding="2">
<tr><td align="left">+zeroMethod()</td></tr>
<tr><td align="left">+objectTypeHint()</td></tr>
<tr><td align="left">+objectTypeHintAndDocComment()</td></tr>
<tr><td align="left">#scalarParameters()</td></tr>
<tr><td align="left">-typeHintWinsOverDocComment()</td></tr>
<tr><td align="left">+parametersWithValues()</td></tr>
</table></td></tr>
</table>
>];
}
}
@@ -0,0 +1,43 @@
<?php
class OneClass
{
/**
* @return bool
*/
function zeroMethod()
{
}
public function objectTypeHint(OneClass $oneClass)
{
}
/**
* @param OneClass $oneClass
*
* @return OneClass
*/
public function objectTypeHintAndDocComment(OneClass $oneClass)
{
}
/**
* @param int $int
* @param float $float
* @param bool $bool
*/
protected function scalarParameters($int, $float, $bool)
{
}
/**
* @param WrongDocComment $oneClass
*/
private function typeHintWinsOverDocComment(OneClass $oneClass)
{
}
public function parametersWithValues($int = 1, $float = 12.1, $string = 'foo', $bool = true)
{
}
}
@@ -0,0 +1,8 @@
class OneClass << class >> {
+zeroMethod()
+objectTypeHint()
+objectTypeHintAndDocComment()
#scalarParameters()
-typeHintWinsOverDocComment()
+parametersWithValues()
}
Oops, something went wrong.

0 comments on commit be07186

Please sign in to comment.