Added new template for PHP called "phpunit" to generate PHPUnit bootstrap test
This commit is contained in:
parent
09fb388ee7
commit
d813ef7b94
6 changed files with 98 additions and 2 deletions
76
src/ncc/Classes/PhpExtension/Templates/PhpUnitTemplate.php
Normal file
76
src/ncc/Classes/PhpExtension/Templates/PhpUnitTemplate.php
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) Nosial 2022-2023, all rights reserved.
|
||||||
|
*
|
||||||
|
* 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 NON-INFRINGEMENT. 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace ncc\Classes\PhpExtension\Templates;
|
||||||
|
|
||||||
|
use ncc\Classes\NccExtension\ConstantCompiler;
|
||||||
|
use ncc\Enums\Options\BuildConfigurationOptions;
|
||||||
|
use ncc\Enums\Options\ProjectOptions;
|
||||||
|
use ncc\Enums\Runners;
|
||||||
|
use ncc\Enums\SpecialConstants\AssemblyConstants;
|
||||||
|
use ncc\Enums\Types\BuildOutputType;
|
||||||
|
use ncc\Exceptions\ConfigurationException;
|
||||||
|
use ncc\Exceptions\IOException;
|
||||||
|
use ncc\Exceptions\PathNotFoundException;
|
||||||
|
use ncc\Interfaces\TemplateInterface;
|
||||||
|
use ncc\Managers\ProjectManager;
|
||||||
|
use ncc\Objects\ProjectConfiguration\Build\BuildConfiguration;
|
||||||
|
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
|
||||||
|
use ncc\Utilities\IO;
|
||||||
|
|
||||||
|
class PhpUnitTemplate implements TemplateInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
* @param ProjectManager $project_manager
|
||||||
|
*/
|
||||||
|
public static function applyTemplate(ProjectManager $project_manager): void
|
||||||
|
{
|
||||||
|
self::createPhpUnitBootstrapTemplate($project_manager);
|
||||||
|
self::createPhpUnitTemplate($project_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function createPhpUnitTemplate(ProjectManager $project_manager): void
|
||||||
|
{
|
||||||
|
IO::fwrite(
|
||||||
|
$project_manager->getProjectPath() . DIRECTORY_SEPARATOR . 'phpunit.xml',
|
||||||
|
ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(),
|
||||||
|
IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.tpl')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!file_exists($project_manager->getProjectPath() . DIRECTORY_SEPARATOR . 'tests'))
|
||||||
|
{
|
||||||
|
mkdir($project_manager->getProjectPath() . DIRECTORY_SEPARATOR . 'tests');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function createPhpUnitBootstrapTemplate(ProjectManager $project_manager): void
|
||||||
|
{
|
||||||
|
IO::fwrite(
|
||||||
|
$project_manager->getProjectPath() . DIRECTORY_SEPARATOR . 'bootstrap.php',
|
||||||
|
ConstantCompiler::compileConstants($project_manager->getProjectConfiguration(),
|
||||||
|
IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'bootstrap.php.tpl')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
3
src/ncc/Classes/PhpExtension/Templates/bootstrap.php.tpl
Normal file
3
src/ncc/Classes/PhpExtension/Templates/bootstrap.php.tpl
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
require 'ncc';
|
||||||
|
import('%ASSEMBLY.PACKAGE%');
|
11
src/ncc/Classes/PhpExtension/Templates/phpunit.xml.tpl
Normal file
11
src/ncc/Classes/PhpExtension/Templates/phpunit.xml.tpl
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<phpunit bootstrap="bootstrap.php">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="%ASSEMBLY.NAME% Test Suite">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<php>
|
||||||
|
<ini name="error_reporting" value="-1"/>
|
||||||
|
<server name="KERNEL_DIR" value="app/"/>
|
||||||
|
</php>
|
||||||
|
</phpunit>
|
|
@ -33,4 +33,6 @@
|
||||||
* A template that is used to create a PHP CLI application project
|
* A template that is used to create a PHP CLI application project
|
||||||
*/
|
*/
|
||||||
case PHP_CLI = 'phpcli';
|
case PHP_CLI = 'phpcli';
|
||||||
|
|
||||||
|
case PHP_UNIT = 'phpunit';
|
||||||
}
|
}
|
|
@ -30,8 +30,8 @@
|
||||||
use ncc\Classes\PhpExtension\NccCompiler;
|
use ncc\Classes\PhpExtension\NccCompiler;
|
||||||
use ncc\Classes\PhpExtension\Templates\CliTemplate;
|
use ncc\Classes\PhpExtension\Templates\CliTemplate;
|
||||||
use ncc\Classes\PhpExtension\Templates\LibraryTemplate;
|
use ncc\Classes\PhpExtension\Templates\LibraryTemplate;
|
||||||
|
use ncc\Classes\PhpExtension\Templates\PhpUnitTemplate;
|
||||||
use ncc\Enums\CompilerExtensions;
|
use ncc\Enums\CompilerExtensions;
|
||||||
use ncc\Enums\ComponentFileExtensions;
|
|
||||||
use ncc\Enums\Options\BuildConfigurationOptions;
|
use ncc\Enums\Options\BuildConfigurationOptions;
|
||||||
use ncc\Enums\Options\BuildConfigurationValues;
|
use ncc\Enums\Options\BuildConfigurationValues;
|
||||||
use ncc\Enums\Options\InitializeProjectOptions;
|
use ncc\Enums\Options\InitializeProjectOptions;
|
||||||
|
@ -199,6 +199,10 @@
|
||||||
LibraryTemplate::applyTemplate($this);
|
LibraryTemplate::applyTemplate($this);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ProjectTemplates::PHP_UNIT->value:
|
||||||
|
PhpUnitTemplate::applyTemplate($this);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException('The given template \'' . $template_name . '\' is not supported');
|
throw new NotSupportedException('The given template \'' . $template_name . '\' is not supported');
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,7 +289,7 @@
|
||||||
*/
|
*/
|
||||||
public function update(): void
|
public function update(): void
|
||||||
{
|
{
|
||||||
if(Resolver::checkLogLevel(LogLevel::VERBOSE, Main::getLogLevel()))
|
if(LogLevel::VERBOSE->checkLogLevel(Main::getLogLevel()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue