Skip to content

Commit

Permalink
Merge pull request #2 from elminson/Adding-phpunit-xml-dist-1
Browse files Browse the repository at this point in the history
Adding the phpunit.xml.dist  file automatically #1
  • Loading branch information
elminson authored Oct 18, 2018
2 parents c1b6e2c + ef6a2a0 commit f87aee1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/PHPProjectGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function GenerateProject()
$this->generateComposer();
$this->generateClass();
$this->generateTestCases();
$this->generatePHPUnitTestCases();
$this->generateZipFile();
$this->cleanData();
}
Expand Down Expand Up @@ -106,6 +107,14 @@ private function generateTestCases()

}

private function generatePHPUnitTestCases()
{
$string = file_get_contents("src/phpunit.xml.dist.raw");
$string = str_replace('{!projectname!}', $this->composer_config['projectname'], $string);
$this->writeFile('phpunit.xml', $string, '', 'dist');

}

private function writeFile($name, $data, $prefix = "", $ext = "php")
{
$file = fopen('src/temp/' . $prefix . $name . '.' . $ext, 'w');
Expand All @@ -128,6 +137,7 @@ private function generateZipFile()
if ($this->composer_config['phpunit']) {
$testFile = "tests/test" . $this->composer_config['projectname'] . ".php";
$zipFile
->addFile(__DIR__ . "/temp/phpunit.xml.dist", "test/phpunit.xml.dist")
->addFile(__DIR__ . "/temp/test" . $this->composer_config['projectname'] . ".php", $testFile);
}

Expand All @@ -142,6 +152,7 @@ private function cleanData()
unlink(__DIR__ . "/temp/" . $this->composer_config['projectname'] . ".php");
if ($this->composer_config['phpunit']) {
unlink(__DIR__ . "/temp/test" . $this->composer_config['projectname'] . ".php");
unlink(__DIR__ . "/temp/phpunit.xml.dist");
}
unlink(__DIR__ . "/temp/composer.json");
}
Expand Down
9 changes: 9 additions & 0 deletions src/phpunit.xml.dist.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<phpunit bootstrap="src/autoload.php">
<testsuites>
<testsuite name="{!projectname!}">
<file>tests/test{!projectname!}.php</file>
<directory>tests/*Test.php</directory>
<exclude></exclude>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit f87aee1

Please sign in to comment.