diff --git a/config/modular.php b/config/modular.php index 03fbf15..623b843 100644 --- a/config/modular.php +++ b/config/modular.php @@ -28,6 +28,7 @@ 'resources/css', 'routes', 'storage', - 'tests', + 'tests/Feature', + 'tests/Unit', ], ]; diff --git a/src/Commands/JobMakeCommand.php b/src/Commands/JobMakeCommand.php new file mode 100644 index 0000000..759bb57 --- /dev/null +++ b/src/Commands/JobMakeCommand.php @@ -0,0 +1,19 @@ +error($e->getMessage()); } - // $this->generateModuleFacade(); + $this->generatePestFiles(); } private function generateModuleComposerFile(): void @@ -134,6 +134,27 @@ private function generateModuleServiceProvider(): void ]); } + private function generatePestFiles(): void + { + // phpunit.xml + $path = Modular::module($this->moduleName)->path('phpunit.xml'); + $this->copyStubToApp('phpunit', $path, [ + 'moduleName' => $this->moduleStudlyName, + ]); + + // Pest.php + $path = Modular::module($this->moduleName)->testsPath('Pest.php'); + $this->copyStubToApp('pest.class', $path, [ + 'namespace' => $this->moduleNamespace, + ]); + + // TestCase.php + $path = Modular::module($this->moduleName)->testsPath('TestCase.php'); + $this->copyStubToApp('test-case', $path, [ + 'namespace' => $this->moduleNamespace.'\\Tests', + ]); + } + private function installModule(): void { $this->comment('Activating the new Module'); diff --git a/src/Commands/TestMakeCommand.php b/src/Commands/TestMakeCommand.php new file mode 100644 index 0000000..88628c4 --- /dev/null +++ b/src/Commands/TestMakeCommand.php @@ -0,0 +1,36 @@ +rootNamespace(), '', $name); + + return $this->getModule()->testsPath(str_replace('\\', '/', $name).'.php'); + } + + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + */ + protected function getDefaultNamespace($rootNamespace): string + { + if ($this->option('unit')) { + return $rootNamespace.'\Unit'; + } else { + return $rootNamespace.'\Feature'; + } + } +} diff --git a/src/Module.php b/src/Module.php index f324850..8139b94 100644 --- a/src/Module.php +++ b/src/Module.php @@ -119,4 +119,14 @@ public function resourcePath(string $string, bool $relative = false): string { return $this->path('resources'.DIRECTORY_SEPARATOR.trim($string, DIRECTORY_SEPARATOR), $relative); } + + public function testsPath(string $string, bool $relative = false): string + { + return $this->path('tests'.DIRECTORY_SEPARATOR.trim($string, DIRECTORY_SEPARATOR), $relative); + } + + public function getBaseProviderClass(): string + { + return $this->makeNamespace('\\'.$this->studlyName.'ServiceProvider'); + } } diff --git a/stubs/pest.class.stub b/stubs/pest.class.stub new file mode 100644 index 0000000..68bf05d --- /dev/null +++ b/stubs/pest.class.stub @@ -0,0 +1,48 @@ +in(__DIR__); + +/* +|-------------------------------------------------------------------------- +| Expectations +|-------------------------------------------------------------------------- +| +| When you're writing tests, you often need to check that values meet certain conditions. The +| "expect()" function gives you access to a set of "expectations" methods that you can use +| to assert different things. Of course, you may extend the Expectation API at any time. +| +*/ + +expect()->extend('toBeOne', function () { + return $this->toBe(1); +}); + +/* +|-------------------------------------------------------------------------- +| Functions +|-------------------------------------------------------------------------- +| +| While Pest is very powerful out-of-the-box, you may have some testing code specific to your +| project that you don't want to repeat in every file. Here you can also expose helpers as +| global functions to help you to reduce the number of lines of code in your test files. +| +*/ + +function something() +{ + // .. +} diff --git a/stubs/phpunit.stub b/stubs/phpunit.stub new file mode 100644 index 0000000..ec4f59f --- /dev/null +++ b/stubs/phpunit.stub @@ -0,0 +1,33 @@ + + + + + tests/Unit + + + tests/Feature + + + + + app + + + + + + + + + + + + + + + + diff --git a/stubs/test-case.stub b/stubs/test-case.stub new file mode 100644 index 0000000..9e74331 --- /dev/null +++ b/stubs/test-case.stub @@ -0,0 +1,10 @@ +