33namespace Statamic \Testing \Extend ;
44
55use Facades \Statamic \Licensing \LicenseManager ;
6+ use Foo \Bar \TestAddonServiceProvider ;
67use Illuminate \Support \Collection ;
78use Statamic \Extend \Addon ;
89use Statamic \Facades \File ;
910use Tests \TestCase ;
1011
1112class AddonTest extends TestCase
1213{
14+ protected $ addonFixtureDir ;
15+
16+ public function setUp (): void
17+ {
18+ parent ::setUp ();
19+ $ this ->addonFixtureDir = realpath (__DIR__ .'/../Fixtures/Addon ' );
20+ }
21+
1322 /** @test */
1423 public function it_creates_an_instance_with_a_name ()
1524 {
@@ -100,7 +109,8 @@ public function it_creates_an_instance_from_a_package()
100109 $ this ->assertEquals ('Test Addon ' , $ addon ->name ());
101110 $ this ->assertEquals ('Test description ' , $ addon ->description ());
102111 $ this ->assertEquals ('Vendor \\TestAddon ' , $ addon ->namespace ());
103- $ this ->assertEquals ('/path/to/addon ' , $ addon ->directory ());
112+ $ this ->assertEquals ($ this ->addonFixtureDir , $ addon ->directory ());
113+ $ this ->assertEquals ('' , $ addon ->autoload ());
104114 $ this ->assertEquals ('http://test-url.com ' , $ addon ->url ());
105115 $ this ->assertEquals ('Test Developer LLC ' , $ addon ->developer ());
106116 $ this ->assertEquals ('http://test-developer.com ' , $ addon ->developerUrl ());
@@ -111,10 +121,10 @@ public function it_creates_an_instance_from_a_package()
111121 /** @test */
112122 public function it_checks_if_a_file_exists ()
113123 {
114- $ addon = Addon:: make ( ' Test Addon ' )-> directory ( ' /path/to/addon ' );
124+ $ addon = $ this -> makeFromPackage ( );
115125
116- File::shouldReceive ('exists ' )->with (' /path/to/addon /test.txt ' )->andReturnTrue ();
117- File::shouldReceive ('exists ' )->with (' /path/to/addon /notfound.txt ' )->andReturnFalse ();
126+ File::shouldReceive ('exists ' )->with ($ this -> addonFixtureDir . ' /test.txt ' )->andReturnTrue ();
127+ File::shouldReceive ('exists ' )->with ($ this -> addonFixtureDir . ' /notfound.txt ' )->andReturnFalse ();
118128
119129 $ this ->assertTrue ($ addon ->hasFile ('test.txt ' ));
120130 $ this ->assertFalse ($ addon ->hasFile ('notfound.txt ' ));
@@ -123,33 +133,33 @@ public function it_checks_if_a_file_exists()
123133 /** @test */
124134 public function it_gets_file_contents ()
125135 {
126- $ addon = Addon:: make ( ' Test Addon ' )-> directory ( ' /path/to/addon ' );
136+ $ addon = $ this -> makeFromPackage ( );
127137
128- File::shouldReceive ('get ' )->with (' /path/to/addon /test.txt ' )->andReturn ('the file contents ' );
138+ File::shouldReceive ('get ' )->with ($ this -> addonFixtureDir . ' /test.txt ' )->andReturn ('the file contents ' );
129139
130140 $ this ->assertEquals ('the file contents ' , $ addon ->getFile ('test.txt ' ));
131141 }
132142
133143 /** @test */
134144 public function it_writes_file_contents ()
135145 {
136- $ addon = Addon:: make ( ' Test Addon ' )-> directory ( ' /path/to/addon ' );
146+ $ addon = $ this -> makeFromPackage ( );
137147
138- File::shouldReceive ('put ' )->with (' /path/to/addon /test.txt ' , 'the file contents ' );
148+ File::shouldReceive ('put ' )->with ($ this -> addonFixtureDir . ' /test.txt ' , 'the file contents ' );
139149
140150 $ addon ->putFile ('test.txt ' , 'the file contents ' );
141151 }
142152
143153 /** @test */
144- public function it_doesnt_allow_getting_files_if_no_directory_is_set ()
154+ public function it_doesnt_allow_getting_files_if_no_provider_is_set ()
145155 {
146156 File::spy ();
147- $ addon = $ this ->makeFromPackage (['directory ' => null ]);
157+ $ addon = $ this ->makeFromPackage (['provider ' => null ]);
148158
149159 try {
150160 $ addon ->getFile ('foo.txt ' , 'foo ' );
151161 } catch (\Exception $ e ) {
152- $ this ->assertEquals ('Cannot get files without a directory specified. ' , $ e ->getMessage ());
162+ $ this ->assertEquals ('Cannot get files without a provider specified. ' , $ e ->getMessage ());
153163 File::shouldNotHaveReceived ('get ' );
154164
155165 return ;
@@ -159,15 +169,15 @@ public function it_doesnt_allow_getting_files_if_no_directory_is_set()
159169 }
160170
161171 /** @test */
162- public function it_doesnt_allow_checking_for_files_if_no_directory_is_set ()
172+ public function it_doesnt_allow_checking_for_files_if_no_provider_is_set ()
163173 {
164174 File::spy ();
165- $ addon = $ this ->makeFromPackage (['directory ' => null ]);
175+ $ addon = $ this ->makeFromPackage (['provider ' => null ]);
166176
167177 try {
168178 $ addon ->hasFile ('foo.txt ' , 'foo ' );
169179 } catch (\Exception $ e ) {
170- $ this ->assertEquals ('Cannot check files without a directory specified. ' , $ e ->getMessage ());
180+ $ this ->assertEquals ('Cannot check files without a provider specified. ' , $ e ->getMessage ());
171181 File::shouldNotHaveReceived ('get ' );
172182
173183 return ;
@@ -177,15 +187,15 @@ public function it_doesnt_allow_checking_for_files_if_no_directory_is_set()
177187 }
178188
179189 /** @test */
180- public function it_doesnt_allow_writing_files_if_no_directory_is_set ()
190+ public function it_doesnt_allow_writing_files_if_no_provider_is_set ()
181191 {
182192 File::spy ();
183- $ addon = $ this ->makeFromPackage (['directory ' => null ]);
193+ $ addon = $ this ->makeFromPackage (['provider ' => null ]);
184194
185195 try {
186196 $ addon ->putFile ('foo.txt ' , 'foo ' );
187197 } catch (\Exception $ e ) {
188- $ this ->assertEquals ('Cannot write files without a directory specified. ' , $ e ->getMessage ());
198+ $ this ->assertEquals ('Cannot write files without a provider specified. ' , $ e ->getMessage ());
189199 File::shouldNotHaveReceived ('put ' );
190200
191201 return ;
@@ -230,15 +240,15 @@ public function it_gets_the_license()
230240 $ this ->assertEquals ('the license ' , Addon::make ('foo/bar ' )->license ());
231241 }
232242
233- private function makeFromPackage ($ attributes )
243+ private function makeFromPackage ($ attributes = [] )
234244 {
235245 return Addon::makeFromPackage (array_merge ([
236246 'id ' => 'vendor/test-addon ' ,
237247 'name ' => 'Test Addon ' ,
238248 'description ' => 'Test description ' ,
239249 'namespace ' => 'Vendor \\TestAddon ' ,
240- 'directory ' => ' /path/to/addon ' ,
241- 'autoload ' => 'src ' ,
250+ 'provider ' => TestAddonServiceProvider::class ,
251+ 'autoload ' => '' ,
242252 'url ' => 'http://test-url.com ' ,
243253 'developer ' => 'Test Developer LLC ' ,
244254 'developerUrl ' => 'http://test-developer.com ' ,
0 commit comments