6
6
use Composer \Plugin \PluginInterface ;
7
7
use Composer \Script \Event ;
8
8
use Composer \Script \ScriptEvents ;
9
+ use Composer \Installer \PackageEvent ;
9
10
10
11
class Installer implements PluginInterface, EventSubscriberInterface
11
12
{
@@ -18,7 +19,14 @@ public function activate(Composer $composer, IOInterface $io)
18
19
{
19
20
$ this ->io = $ io ;
20
21
}
21
-
22
+
23
+ protected function isOperationOnC3 (PackageEvent $ event )
24
+ {
25
+ list (, $ name ) = explode ('/ ' , $ event ->getOperation ()->getPackage ()->getName ());
26
+
27
+ return $ name === 'c3 ' ;
28
+ }
29
+
22
30
public static function getSubscribedEvents ()
23
31
{
24
32
return [
@@ -40,8 +48,11 @@ public static function copyC3ToRoot(Event $event)
40
48
$ event ->getIO ()->write ("<warning>Please remove current \"post-install-cmd \" and \"post-update-cmd \" hooks from your composer.json</warning> " );
41
49
}
42
50
43
- public function copyC3 ()
51
+ public function copyC3 (PackageEvent $ event )
44
52
{
53
+ if (!$ this ->isOperationOnC3 ($ event )) {
54
+ return ;
55
+ }
45
56
if ($ this ->c3NotChanged ()) {
46
57
$ this ->io ->write ("<comment>[codeception/c3]</comment> c3.php is already up-to-date " );
47
58
return ;
@@ -52,9 +63,9 @@ public function copyC3()
52
63
$ this ->io ->write ("<comment>[codeception/c3]</comment> Include c3.php into index.php in order to collect codecoverage from server scripts " );
53
64
}
54
65
55
- public function askForUpdate ()
66
+ public function askForUpdate (PackageEvent $ event )
56
67
{
57
- if ($ this ->c3NotChanged ()) {
68
+ if (! $ this -> isOperationOnC3 ( $ event ) || $ this ->c3NotChanged ()) {
58
69
return ;
59
70
}
60
71
if (file_exists (getcwd () . DIRECTORY_SEPARATOR . 'c3.php ' )) {
@@ -72,12 +83,14 @@ private function c3NotChanged()
72
83
md5_file (__DIR__ . DIRECTORY_SEPARATOR . 'c3.php ' ) === md5_file (getcwd () . DIRECTORY_SEPARATOR . 'c3.php ' );
73
84
}
74
85
75
- public function deleteC3 ()
86
+ public function deleteC3 (PackageEvent $ event )
76
87
{
88
+ if (!$ this ->isOperationOnC3 ($ event )) {
89
+ return ;
90
+ }
77
91
if (file_exists (getcwd () . DIRECTORY_SEPARATOR . 'c3.php ' )) {
78
92
$ this ->io ->write ("<comment>[codeception/c3]</comment> Deleting c3.php from the root of your project... " );
79
93
unlink (getcwd () . DIRECTORY_SEPARATOR . 'c3.php ' );
80
94
}
81
95
}
82
96
}
83
-
0 commit comments