11<?php
22
3- use PlinCode \LaravelCleanArchitecture \Commands \GeneratePackageCommand ;
43use Illuminate \Filesystem \Filesystem ;
54use Illuminate \Support \Facades \File ;
5+ use PlinCode \LaravelCleanArchitecture \Commands \GeneratePackageCommand ;
66
77describe ('GeneratePackageCommand ' , function () {
88 beforeEach (function () {
9- $ this ->filesystem = new Filesystem () ;
10- $ this ->command = new GeneratePackageCommand ($ this ->filesystem );
11- $ this ->tempPath = sys_get_temp_dir () . '/test-package- ' . uniqid ();
12-
9+ $ this ->filesystem = new Filesystem ;
10+ $ this ->command = new GeneratePackageCommand ($ this ->filesystem );
11+ $ this ->tempPath = sys_get_temp_dir () . '/test-package- ' . uniqid ();
12+
1313 // Mock the output to avoid writeln errors
1414 $ mockOutput = mock ('Symfony\Component\Console\Output\OutputInterface ' );
1515 $ mockOutput ->shouldReceive ('writeln ' )->andReturn ();
1616 $ mockOutput ->shouldReceive ('write ' )->andReturn ();
17-
18- $ reflection = new ReflectionClass ($ this ->command );
17+
18+ $ reflection = new ReflectionClass ($ this ->command );
1919 $ outputProperty = $ reflection ->getProperty ('output ' );
2020 $ outputProperty ->setAccessible (true );
2121 $ outputProperty ->setValue ($ this ->command , $ mockOutput );
3434
3535 it ('has required arguments ' , function () {
3636 $ definition = $ this ->command ->getDefinition ();
37-
37+
3838 expect ($ definition ->hasArgument ('name ' ))->toBeTrue ();
3939 expect ($ definition ->hasArgument ('vendor ' ))->toBeTrue ();
4040 expect ($ definition ->getArgument ('name ' )->getDescription ())->toBe ('The name of the package ' );
4343
4444 it ('has correct options ' , function () {
4545 $ definition = $ this ->command ->getDefinition ();
46-
46+
4747 expect ($ definition ->hasOption ('path ' ))->toBeTrue ();
4848 expect ($ definition ->hasOption ('force ' ))->toBeTrue ();
4949 expect ($ definition ->getOption ('path ' )->getDescription ())->toBe ('Custom path for the package ' );
5252
5353 it ('can create package structure ' , function () {
5454 $ reflection = new ReflectionClass ($ this ->command );
55- $ method = $ reflection ->getMethod ('createPackageStructure ' );
55+ $ method = $ reflection ->getMethod ('createPackageStructure ' );
5656 $ method ->setAccessible (true );
5757
5858 $ packageName = 'test-package ' ;
59- $ studlyName = 'TestPackage ' ;
60- $ namespace = 'TestVendor \\TestPackage ' ;
61- $ vendor = 'test-vendor ' ;
59+ $ studlyName = 'TestPackage ' ;
60+ $ namespace = 'TestVendor \\TestPackage ' ;
61+ $ vendor = 'test-vendor ' ;
6262
6363 // Mock the filesystem to avoid actual file creation
6464 $ mockFilesystem = mock (Filesystem::class);
7676
7777 it ('can create package composer.json ' , function () {
7878 $ reflection = new ReflectionClass ($ this ->command );
79- $ method = $ reflection ->getMethod ('createPackageComposer ' );
79+ $ method = $ reflection ->getMethod ('createPackageComposer ' );
8080 $ method ->setAccessible (true );
8181
8282 $ packageName = 'test-package ' ;
83- $ studlyName = 'TestPackage ' ;
84- $ namespace = 'TestVendor \\TestPackage ' ;
85- $ vendor = 'test-vendor ' ;
83+ $ studlyName = 'TestPackage ' ;
84+ $ namespace = 'TestVendor \\TestPackage ' ;
85+ $ vendor = 'test-vendor ' ;
8686
8787 // Create temp directory
8888 $ this ->filesystem ->makeDirectory ($ this ->tempPath , 0755 , true );
8989
9090 $ method ->invoke ($ this ->command , $ this ->tempPath , $ packageName , $ studlyName , $ namespace , $ vendor );
9191
9292 expect (file_exists ($ this ->tempPath . '/composer.json ' ))->toBeTrue ();
93-
93+
9494 $ composerContent = json_decode (file_get_contents ($ this ->tempPath . '/composer.json ' ), true );
9595 expect ($ composerContent ['name ' ])->toBe ('test-vendor/test-package ' );
9696 expect ($ composerContent ['description ' ])->toBe ('Laravel package for TestPackage ' );
9999
100100 it ('can create service provider ' , function () {
101101 $ reflection = new ReflectionClass ($ this ->command );
102- $ method = $ reflection ->getMethod ('createPackageServiceProvider ' );
102+ $ method = $ reflection ->getMethod ('createPackageServiceProvider ' );
103103 $ method ->setAccessible (true );
104104
105105 $ studlyName = 'TestPackage ' ;
106- $ namespace = 'TestVendor \\TestPackage ' ;
106+ $ namespace = 'TestVendor \\TestPackage ' ;
107107
108108 // Create a mock stub content
109109 $ stubContent = '<?php namespace {{Namespace}}; class {{StudlyName}}ServiceProvider {} ' ;
110-
110+
111111 // Mock filesystem to return stub content
112112 $ mockFilesystem = mock (Filesystem::class);
113113 $ mockFilesystem ->shouldReceive ('exists ' )->andReturn (true );
122122
123123 it ('can create package model ' , function () {
124124 $ reflection = new ReflectionClass ($ this ->command );
125- $ method = $ reflection ->getMethod ('createPackageModel ' );
125+ $ method = $ reflection ->getMethod ('createPackageModel ' );
126126 $ method ->setAccessible (true );
127127
128128 $ studlyName = 'TestPackage ' ;
129- $ namespace = 'TestVendor \\TestPackage ' ;
129+ $ namespace = 'TestVendor \\TestPackage ' ;
130130
131131 // Mock filesystem and stub
132132 $ mockFilesystem = mock (Filesystem::class);
142142
143143 it ('can create package service ' , function () {
144144 $ reflection = new ReflectionClass ($ this ->command );
145- $ method = $ reflection ->getMethod ('createPackageService ' );
145+ $ method = $ reflection ->getMethod ('createPackageService ' );
146146 $ method ->setAccessible (true );
147147
148148 $ studlyName = 'TestPackage ' ;
149- $ namespace = 'TestVendor \\TestPackage ' ;
149+ $ namespace = 'TestVendor \\TestPackage ' ;
150150
151151 // Mock filesystem and stub
152152 $ mockFilesystem = mock (Filesystem::class);
162162
163163 it ('can create package readme ' , function () {
164164 $ reflection = new ReflectionClass ($ this ->command );
165- $ method = $ reflection ->getMethod ('createPackageReadme ' );
165+ $ method = $ reflection ->getMethod ('createPackageReadme ' );
166166 $ method ->setAccessible (true );
167167
168168 $ packageName = 'test-package ' ;
169- $ studlyName = 'TestPackage ' ;
170- $ vendor = 'test-vendor ' ;
169+ $ studlyName = 'TestPackage ' ;
170+ $ vendor = 'test-vendor ' ;
171171
172172 // Mock filesystem and stub
173173 $ mockFilesystem = mock (Filesystem::class);
183183
184184 it ('throws exception when stub file not found ' , function () {
185185 $ reflection = new ReflectionClass ($ this ->command );
186- $ method = $ reflection ->getMethod ('getStub ' );
186+ $ method = $ reflection ->getMethod ('getStub ' );
187187 $ method ->setAccessible (true );
188188
189189 // Mock filesystem to return false for exists
199199
200200 it ('can get stub content when file exists ' , function () {
201201 $ reflection = new ReflectionClass ($ this ->command );
202- $ method = $ reflection ->getMethod ('getStub ' );
202+ $ method = $ reflection ->getMethod ('getStub ' );
203203 $ method ->setAccessible (true );
204204
205205 $ stubContent = '<?php // Test stub content ' ;
214214 $ result = $ method ->invoke ($ this ->command , 'test-stub ' );
215215 expect ($ result )->toBe ($ stubContent );
216216 });
217- });
217+ });
0 commit comments