From 378afeb561798af20b6f94c0125ff790416222b9 Mon Sep 17 00:00:00 2001 From: Joseph Mancuso Date: Sun, 1 Oct 2017 15:08:18 -0400 Subject: [PATCH] added creation of tests --- CreateTest.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 CreateTest.php diff --git a/CreateTest.php b/CreateTest.php new file mode 100644 index 0000000..bdd5338 --- /dev/null +++ b/CreateTest.php @@ -0,0 +1,50 @@ +setName("new:modeltest") + ->setDescription('Make a new model test') + ->addArgument('model', InputArgument::REQUIRED, "Model test name") + ->addArgument('app', InputArgument::REQUIRED, "App where the model resides"); + } + + public function execute(InputInterface $input, OutputInterface $output) + { + $model = $input->getArgument('model'); + $app = $input->getArgument('app'); + + $this->new($model, $app, $output); + } + + public static function new($model, $app, OutputInterface $output) + { + if (!file_exists('tests/models/')) { + mkdir('tests'); + mkdir('tests/models/'); + } + $basedir = $_SERVER['DOCUMENT_ROOT']; + if (file_exists('tests/models/'.ucwords($model).'Test.php')) { + $output->writeln('Model Test already exists. Try renaming your model'); + return false; + } + $modelname = ucwords($model); + $file = fopen('tests/models/'.$modelname.'Test.php', "w"); + $data = "model = new '.$modelname."();\n\x20\x20\x20}\n}"; + fwrite($file, $data); + fclose($file); + + $output->writeln("Model Created"); + } +}