Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad1c9a3
commit 787450c
Showing
14 changed files
with
396 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (C) 2011 by Nils Langner | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config; | ||
|
||
class Config | ||
{ | ||
private $includedPages = array(); | ||
private $excludedPages = array(); | ||
|
||
private $testCases = array(); | ||
private $inherit = true; | ||
|
||
private $baseDir; | ||
|
||
private $parentConfig; | ||
|
||
public function __construct(Config $parentConfig = null) | ||
{ | ||
$this->parentConfig = $parentConfig; | ||
} | ||
|
||
public function setBaseDir($baseDir) | ||
{ | ||
$this->baseDir = $baseDir; | ||
} | ||
|
||
public function getBaseDir() | ||
{ | ||
if (is_null($this->baseDir)) | ||
{ | ||
return $this->parentConfig->getBaseDir(); | ||
} | ||
return $this->baseDir; | ||
} | ||
|
||
public function includePage($page) | ||
{ | ||
$this->includedPages[$page] = $page; | ||
} | ||
|
||
public function includePages($pages) | ||
{ | ||
foreach( $pages as $page ) | ||
{ | ||
$this->includePage(trim($page)); | ||
} | ||
} | ||
|
||
public function excludePage($page) | ||
{ | ||
$this->excludedPages[$page] = $page; | ||
} | ||
|
||
public function doNotInherit() | ||
{ | ||
$this->inherit = false; | ||
} | ||
|
||
public function clearPages() | ||
{ | ||
$this->includedPages = array(); | ||
$this->excludedPages = array(); | ||
} | ||
|
||
public function createTestCase($name, $className, $parameters) | ||
{ | ||
$config = new self($this); | ||
|
||
$this->testCases[] = array('config' => $config,'className' => $className,'parameters' => $parameters); | ||
|
||
return $config; | ||
} | ||
|
||
public function getPages() | ||
{ | ||
if ($this->inherit && !is_null($this->parentConfig)) | ||
{ | ||
$result = array_merge($this->includedPages, $this->parentConfig->getPages()); | ||
} | ||
else | ||
{ | ||
$result = $this->includedPages; | ||
} | ||
|
||
return array_diff($result, $this->excludedPages); | ||
} | ||
|
||
public function getTestCases() | ||
{ | ||
return $this->testCases; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config; | ||
|
||
class Parser | ||
{ | ||
private $configArray; | ||
private $config; | ||
private $registeredTags; | ||
|
||
public function __construct() | ||
{ | ||
// @todo This should be done automaticly | ||
$this->registeredTags = array('TestSuite' => 'LiveTest\Config\Tags\TestSuite', | ||
'TestCases' => 'LiveTest\Config\Tags\TestCases', | ||
'TestCase' => 'LiveTest\Config\Tags\TestCase', | ||
'Pages' => 'LiveTest\Config\Tags\Pages', | ||
'IncludePages' => 'LiveTest\Config\Tags\IncludePages', | ||
'ExcludePages' => 'LiveTest\Config\Tags\ExcludePages', | ||
'PageFiles' => 'LiveTest\Config\Tags\PageFiles' ); | ||
} | ||
|
||
public function parse(array $configArray, Config $config) | ||
{ | ||
foreach ($configArray as $configTag => $value) | ||
{ | ||
if (array_key_exists($configTag, $this->registeredTags)) | ||
{ | ||
$tagClassName = $this->registeredTags[$configTag]; | ||
$tag = new $tagClassName($value, $config, $this); | ||
$config = $tag->process(); | ||
} | ||
else | ||
{ | ||
throw new \Exception('Unknown tag (' . $configTag . ')'); | ||
} | ||
} | ||
|
||
return $config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config\Tags; | ||
|
||
use LiveTest\Config\Parser; | ||
use LiveTest\Config\Config; | ||
|
||
abstract class Base implements Tag | ||
{ | ||
private $config; | ||
private $parser; | ||
private $configParameters; | ||
|
||
public function __construct(array $configParameters, Config $config, Parser $parser) | ||
{ | ||
$this->config = $config; | ||
$this->parser = $parser; | ||
$this->configParameters = $configParameters; | ||
} | ||
|
||
public function getConfig( ) | ||
{ | ||
return $this->config; | ||
} | ||
|
||
protected function getParser( ) | ||
{ | ||
return $this->parser; | ||
} | ||
|
||
protected function getParameters( ) | ||
{ | ||
return $this->configParameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config\Tags; | ||
|
||
use LiveTest\Config\Parser; | ||
use LiveTest\Config\Config; | ||
|
||
class ExcludePages extends Base | ||
{ | ||
public function process() | ||
{ | ||
$config = $this->getConfig(); | ||
|
||
foreach ($this->getParameters() as $page) | ||
{ | ||
$config->excludePage($page); | ||
} | ||
return $config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config\Tags; | ||
|
||
class IncludePages extends Base | ||
{ | ||
public function process() | ||
{ | ||
$config = $this->getConfig(); | ||
|
||
foreach ($this->getParameters() as $page) | ||
{ | ||
$config->includePage($page); | ||
} | ||
return $config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config\Tags; | ||
|
||
use LiveTest\Config\Parser; | ||
use LiveTest\Config\Config; | ||
|
||
class PageFiles extends Base | ||
{ | ||
public function process() | ||
{ | ||
$config = $this->getConfig(); | ||
$config->doNotInherit(); | ||
|
||
$parameters = $this->getParameters(); | ||
|
||
foreach ($this->getParameters() as $file) | ||
{ | ||
$config->includePages( file( $config->getBaseDir().'/'.$file ) ); | ||
} | ||
return $config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config\Tags; | ||
|
||
use LiveTest\Config\Parser; | ||
use LiveTest\Config\Config; | ||
|
||
class Pages extends Base | ||
{ | ||
public function process() | ||
{ | ||
$config = $this->getConfig(); | ||
$config->doNotInherit(); | ||
|
||
foreach ($this->getParameters() as $page) | ||
{ | ||
$config->includePage($page); | ||
} | ||
return $config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config\Tags; | ||
|
||
use LiveTest\Config\Parser; | ||
|
||
use LiveTest\Config\Config; | ||
|
||
interface Tag | ||
{ | ||
public function __construct(array $configParameters, Config $config, Parser $parser); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config\Tags; | ||
|
||
class TestCases extends Base | ||
{ | ||
public function process() | ||
{ | ||
$config = $this->getConfig(); | ||
foreach ($this->getParameters() as $name => $value) | ||
{ | ||
$parameters = array(); | ||
if (array_key_exists('Parameter', $value)) | ||
{ | ||
$parameters = $value['Parameter']; | ||
} | ||
|
||
$testCaseConfig = $this->getConfig()->createTestCase($name, $value['TestCase'], $parameters); | ||
|
||
unset($value['Parameter']); | ||
unset($value['TestCase']); | ||
|
||
$this->getParser()->parse($value, $testCaseConfig); | ||
} | ||
return $config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace LiveTest\Config\Tags; | ||
|
||
use LiveTest\Config\Parser; | ||
use LiveTest\Config\Config; | ||
|
||
class TestSuite implements Tag | ||
{ | ||
private $config; | ||
private $parser; | ||
private $configParameters; | ||
|
||
public function __construct(array $configParameters, Config $config, Parser $parser) | ||
{ | ||
$this->config = $config; | ||
$this->parser = $parser; | ||
$this->configParameters = $configParameters; | ||
} | ||
|
||
public function process( ) | ||
{ | ||
$this->parser->parse(($this->configParameters), $this->config); | ||
return $this->config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Test\Unit\LiveTest\Parser; | ||
|
||
use Base\Config\Yaml; | ||
|
||
use LiveTest\Config\Config; | ||
|
||
use LiveTest\Config\Parser; | ||
|
||
class ParserTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testParser() | ||
{ | ||
$config = new Config(); | ||
$config->setBaseDir(__DIR__ . '/fixtures/'); | ||
$configYaml = new Yaml(__DIR__ . '/fixtures/testsuite.yml'); | ||
|
||
$parser = new Parser(); | ||
$parsedConfig = $parser->parse($configYaml->toArray(), $config); | ||
|
||
foreach ($parsedConfig->getTestCases() as $testCase) | ||
{ | ||
\Base\Debug\DebugHelper::doVarDump($testCase['className']); | ||
\Base\Debug\DebugHelper::doVarDump($testCase['config']->getPages()); | ||
} | ||
|
||
\Base\Debug\DebugHelper::doVarDump($parsedConfig->getPages()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
http://www.example.com | ||
http://www.example.com/index.php |
Oops, something went wrong.