From 6cb35b68c70d8dce9c70dde8fd819e1d3bae1d53 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 23 Jul 2016 22:49:46 +0200 Subject: [PATCH] Creating test templates --- testGenerator.php | 108 +++++++++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 30 deletions(-) diff --git a/testGenerator.php b/testGenerator.php index 267cc85..ff879ae 100644 --- a/testGenerator.php +++ b/testGenerator.php @@ -25,51 +25,99 @@ function listFolderFiles($dir, $extension) } // PHP tests -$base = __DIR__ . '/../phpOMS'; -$files = listFolderFiles($base, '.php'); +$base = __DIR__ . '/../phpOMS'; +$files = listFolderFiles($base, '.php'); $testBase = __DIR__ . '/../Tests/PHPUnit/Framework'; foreach ($files as $file) { - $file = str_replace($base, '', $file); - $subdir = trim($file, '/'); - $split = explode('.', $file); - $testPath = $testBase . '/'. $split[0] . 'Test.' . $split[1]; + $file = str_replace($base, '', $file); + $subdir = trim($file, '/'); + $split = explode('.', $file); + $testPath = $testBase . '/' . $split[0] . 'Test.' . $split[1]; + + if (stripos($subdir, 'Status.php') === false + && stripos($subdir, 'Type.php') === false + && stripos($subdir, 'Status') === false + && stripos($subdir, 'Enum') === false + && stripos($subdir, 'Null') === false + && stripos($subdir, 'Interface') === false + && stripos($subdir, 'Abstract') === false + ) { + if (!file_exists($testPath)) { + $namespace = str_replace('/', '\\', $split[0]); + $namespace = explode('\\', $namespace); + $classname = $namespace[count($namespace) - 1] . 'Test'; + unset($namespace[count($namespace) - 1]); + $namespace = trim('Tests\PHPUnit\Framework\\' . trim(implode('\\', $namespace), '\\'), '\\'); + $autoloader = str_repeat('/..', count(explode('\\', $namespace))); - if (strpos($subdir, 'Status.php') === false - && strpos($subdir, 'Type.php') === false - && strpos($subdir, 'Status') === false - && strpos($subdir, 'Enum') === false - && strpos($subdir, 'Null') === false - && strpos($subdir, 'Interface') === false - && strpos($subdir, 'Abstract') === false) { - if(!file_exists($testPath)) { mkdir(dirname($testPath), 0777, true); - file_put_contents($testPath, '' . PHP_EOL + . ' * @author Dennis Eichhorn ' . PHP_EOL + . ' * @copyright Dennis Eichhorn' . PHP_EOL + . ' * @license OMS License 1.0' . PHP_EOL + . ' * @version 1.0.0' . PHP_EOL + . ' * @link http://orange-management.com' . PHP_EOL + . ' */' . PHP_EOL + . '' . PHP_EOL + . 'namespace ' . $namespace . ';' . PHP_EOL + . '' . PHP_EOL + . 'require_once __DIR__ . \'' . $autoloader . '/phpOMS/Autoloader.php\';' . PHP_EOL + . '' . PHP_EOL + . 'class ' . $classname . ' extends \PHPUnit_Framework_TestCase' . PHP_EOL + . '{' . PHP_EOL + . '}' . PHP_EOL + ); } } } // JS tests -$base = __DIR__ . '/../jsOMS'; -$files = listFolderFiles($base, '.js'); +$base = __DIR__ . '/../jsOMS'; +$files = listFolderFiles($base, '.js'); $testBase = __DIR__ . '/../Tests/JS/Framework'; foreach ($files as $file) { - $file = str_replace($base, '', $file); - $subdir = trim($file, '/'); - $split = explode('.', $file); - $testPath = $testBase . '/'. $split[0] . 'Test.' . $split[1]; + $file = str_replace($base, '', $file); + $subdir = trim($file, '/'); + $split = explode('.', $file); + $testPath = $testBase . '/' . $split[0] . 'Test.' . $split[1]; + + if (stripos($subdir, 'Status.php') === false + && stripos($subdir, 'Type.php') === false + && stripos($subdir, 'Status') === false + && stripos($subdir, 'Enum') === false + && stripos($subdir, 'Null') === false + && stripos($subdir, 'Interface') === false + && stripos($subdir, 'Abstract') === false + ) { + if (!file_exists($testPath)) { + $name = explode('/', $split[0]); - if (strpos($subdir, 'Status.php') === false - && strpos($subdir, 'Type.php') === false - && strpos($subdir, 'Status') === false - && strpos($subdir, 'Enum') === false - && strpos($subdir, 'Null') === false - && strpos($subdir, 'Interface') === false - && strpos($subdir, 'Abstract') === false) { - if(!file_exists($testPath)) { mkdir(dirname($testPath), 0777, true); - file_put_contents($testPath, ''); + file_put_contents($testPath, + 'describe(\'' . $name[count($name) - 1] . 'Test\', function ()' . PHP_EOL + . '{' . PHP_EOL + . ' "use strict";' . PHP_EOL + . '' . PHP_EOL + . ' beforeEach(function ()' . PHP_EOL + . ' {' . PHP_EOL + . ' });' . PHP_EOL + . '' . PHP_EOL + . ' afterEach(function ()' . PHP_EOL + . ' {' . PHP_EOL + . ' });' . PHP_EOL + . '}' . PHP_EOL + ); } } } \ No newline at end of file