5
5
use Illuminate \Filesystem \Filesystem ;
6
6
use Larapack \Hooks \Hook ;
7
7
use Larapack \Hooks \Hooks ;
8
+ use Larapack \Hooks \Composer ;
8
9
9
10
class HooksTest extends TestCase
10
11
{
@@ -23,16 +24,15 @@ public function setUp()
23
24
public function test_repository_set ()
24
25
{
25
26
$ filesystem = app (Filesystem::class);
27
+ $ composer = new Composer ;
26
28
27
- $ composer = json_decode ($ filesystem ->get (base_path ('composer.json ' )), true );
28
-
29
- $ this ->assertTrue (isset ($ composer ['repositories ' ]));
29
+ $ this ->assertTrue ($ composer ->has ('repositories ' ));
30
30
$ this ->assertEquals ([
31
31
'hooks ' => [
32
32
'url ' => static ::COMPOSER_REPOSITORY ,
33
33
'type ' => 'composer ' ,
34
34
],
35
- ], $ composer[ 'repositories ' ] );
35
+ ], $ composer-> get ( 'repositories ' ) );
36
36
}
37
37
38
38
public function test_install_hook_from_github ()
@@ -45,10 +45,10 @@ public function test_install_hook_from_github()
45
45
]);
46
46
47
47
// Check that hooks folder does exists
48
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks ' ) ));
48
+ $ this ->assertDirectoryExists ( base_path ('hooks ' ));
49
49
50
50
// Check that the hook folder exists
51
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('vendor/composer-github-hook ' ) ));
51
+ $ this ->assertDirectoryExists ( base_path ('vendor/composer-github-hook ' ));
52
52
53
53
// Check that the hook details is correct
54
54
$ hook = app ('hooks ' )->hook ('composer-github-hook ' );
@@ -88,10 +88,10 @@ public function test_making_local_hook()
88
88
]);
89
89
90
90
// Check that hooks folder does exists
91
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks ' ) ));
91
+ $ this ->assertDirectoryExists ( base_path ('hooks ' ));
92
92
93
93
// Check that the hook folder exists
94
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks/local-test-hook ' ) ));
94
+ $ this ->assertDirectoryExists ( base_path ('hooks/local-test-hook ' ));
95
95
96
96
// Check that hook is not yet installed
97
97
$ this ->assertCount (0 , app ('hooks ' )->hooks ()->all ());
@@ -134,10 +134,10 @@ public function test_enabling_hook()
134
134
]);
135
135
136
136
// Check that hooks folder does exists
137
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks ' ) ));
137
+ $ this ->assertDirectoryExists ( base_path ('hooks ' ));
138
138
139
139
// Check that the hook folder exists
140
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks/local-test-hook ' ) ));
140
+ $ this ->assertDirectoryExists ( base_path ('hooks/local-test-hook ' ));
141
141
142
142
// Check that hook is not yet installed
143
143
$ hooks = app ('hooks ' )->hooks ()->all ();
@@ -192,10 +192,10 @@ public function test_disabling_hook()
192
192
]);
193
193
194
194
// Check that hooks folder does exists
195
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks ' ) ));
195
+ $ this ->assertDirectoryExists ( base_path ('hooks ' ));
196
196
197
197
// Check that the hook folder exists
198
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks/local-test-hook ' ) ));
198
+ $ this ->assertDirectoryExists ( base_path ('hooks/local-test-hook ' ));
199
199
200
200
// Check that hook is not yet installed
201
201
$ hooks = app ('hooks ' )->hooks ()->all ();
@@ -269,10 +269,10 @@ public function test_uninstall_hook()
269
269
]);
270
270
271
271
// Check that hooks folder does exists
272
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks ' ) ));
272
+ $ this ->assertDirectoryExists ( base_path ('hooks ' ));
273
273
274
274
// Check that the hook folder exists
275
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks/local-test-hook ' ) ));
275
+ $ this ->assertDirectoryExists ( base_path ('hooks/local-test-hook ' ));
276
276
277
277
// Check that hook is not yet installed
278
278
$ hooks = app ('hooks ' )->hooks ()->all ();
@@ -303,8 +303,8 @@ public function test_uninstall_hook()
303
303
'--keep ' => true ,
304
304
]);
305
305
306
- // Check that the hook folder still exists
307
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks/local-test-hook ' ) ));
306
+ // Check that the hook folder exists
307
+ $ this ->assertDirectoryExists ( base_path ('hooks/local-test-hook ' ));
308
308
}
309
309
310
310
public function test_uninstall_hook_without_keep_parameter ()
@@ -317,10 +317,10 @@ public function test_uninstall_hook_without_keep_parameter()
317
317
]);
318
318
319
319
// Check that hooks folder does exists
320
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks ' ) ));
320
+ $ this ->assertDirectoryExists ( base_path ('hooks ' ));
321
321
322
322
// Check that the hook folder exists
323
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('hooks/local-test-hook ' ) ));
323
+ $ this ->assertDirectoryExists ( base_path ('hooks/local-test-hook ' ));
324
324
325
325
// Check that hook is not yet installed
326
326
$ hooks = app ('hooks ' )->hooks ()->all ();
@@ -351,7 +351,7 @@ public function test_uninstall_hook_without_keep_parameter()
351
351
]);
352
352
353
353
// Check that the hook no longer folder exists
354
- $ this ->assertFalse ( $ filesystem -> isDirectory ( base_path ('hooks/local-test-hook ' ) ));
354
+ $ this ->assertDirectoryNotExists ( base_path ('hooks/local-test-hook ' ));
355
355
}
356
356
357
357
public function test_installing_specific_version ()
@@ -364,11 +364,8 @@ public function test_installing_specific_version()
364
364
'version ' => 'v1.0.0 ' ,
365
365
]);
366
366
367
- // Check that hooks folder does exists
368
- $ this ->assertTrue ($ filesystem ->isDirectory (base_path ('hooks ' )));
369
-
370
367
// Check that the hook folder exists
371
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('vendor/composer-github-hook ' ) ));
368
+ $ this ->assertDirectoryExists ( base_path ('vendor/composer-github-hook ' ));
372
369
373
370
// Check that the hook details is correct
374
371
$ hook = app ('hooks ' )->hook ('composer-github-hook ' );
@@ -548,24 +545,24 @@ public function test_dependencies_are_downloaded()
548
545
$ filesystem = app (Filesystem::class);
549
546
550
547
// Make sure dependency not already exists
551
- $ this ->assertFalse ( $ filesystem -> isDirectory ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ) ));
548
+ $ this ->assertDirectoryNotExists ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ));
552
549
553
550
// Install hook
554
551
$ this ->artisan ('hook:install ' , [
555
552
'name ' => 'composer-github-hook ' ,
556
553
]);
557
554
558
555
// Make sure dependency is now downloaded
559
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ) ));
556
+ $ this ->assertDirectoryExists ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ));
560
557
}
561
558
562
559
public function test_updating_updates_dependencies ()
563
560
{
564
561
$ filesystem = app (Filesystem::class);
565
562
566
563
// Make sure dependency not already exists
567
- $ this ->assertFalse ( $ filesystem -> isDirectory ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ) ));
568
- $ this ->assertFalse ( $ filesystem -> isDirectory ( base_path ('vendor/marktopper/composer-hook-dependency-2 ' ) ));
564
+ $ this ->assertDirectoryNotExists ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ));
565
+ $ this ->assertDirectoryNotExists ( base_path ('vendor/marktopper/composer-hook-dependency-2 ' ));
569
566
570
567
// Install hook
571
568
$ this ->artisan ('hook:install ' , [
@@ -574,8 +571,8 @@ public function test_updating_updates_dependencies()
574
571
]);
575
572
576
573
// Make sure dependency is now downloaded
577
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ) ));
578
- $ this ->assertFalse ( $ filesystem -> isDirectory ( base_path ('vendor/marktopper/composer-hook-dependency-2 ' ) ));
574
+ $ this ->assertDirectoryExists ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ));
575
+ $ this ->assertDirectoryNotExists ( base_path ('vendor/marktopper/composer-hook-dependency-2 ' ));
579
576
580
577
Hooks::useVersionWildcardOnUpdate ();
581
578
@@ -585,8 +582,8 @@ public function test_updating_updates_dependencies()
585
582
]);
586
583
587
584
// Make sure dependency is now downloaded
588
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ) ));
589
- $ this ->assertTrue ( $ filesystem -> isDirectory ( base_path ('vendor/marktopper/composer-hook-dependency-2 ' ) ));
585
+ $ this ->assertDirectoryExists ( base_path ('vendor/marktopper/composer-hook-dependency-1 ' ));
586
+ $ this ->assertDirectoryExists ( base_path ('vendor/marktopper/composer-hook-dependency-2 ' ));
590
587
}
591
588
592
589
// TODO: Test that if a hook requires another hook, that hook should be loaded as well
0 commit comments