Skip to content

Commit d71e5d2

Browse files
NaktibaldaDavertMik
authored andcommitted
Use package events instead of command events (#22)
* Use package events instead of command events * Improved formatting * Ignore composer.lock
1 parent 0d6d9a2 commit d71e5d2

3 files changed

Lines changed: 35 additions & 20 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
composer.phar
33
vendor/
4-
RoboFile.php
4+
RoboFile.php
5+
composer.lock

Installer.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ public function activate(Composer $composer, IOInterface $io)
2121

2222
public static function getSubscribedEvents()
2323
{
24-
return array(
25-
ScriptEvents::POST_INSTALL_CMD => array(
26-
array('copyC3', 0)
27-
),
28-
ScriptEvents::POST_UPDATE_CMD => array(
29-
array('askForUpdate', 0)
30-
)
31-
);
24+
return [
25+
ScriptEvents::POST_PACKAGE_INSTALL => [
26+
['copyC3', 0]
27+
],
28+
ScriptEvents::POST_PACKAGE_UPDATE => [
29+
['askForUpdate', 0]
30+
],
31+
ScriptEvents::POST_PACKAGE_UNINSTALL => [
32+
['deleteC3', 0]
33+
]
34+
];
3235
}
3336

3437
public static function copyC3ToRoot(Event $event)
@@ -45,25 +48,36 @@ public function copyC3()
4548
}
4649

4750
$this->io->write("<comment>[codeception/c3]</comment> Copying c3.php to the root of your project...");
48-
copy(__DIR__.DIRECTORY_SEPARATOR.'c3.php', getcwd().DIRECTORY_SEPARATOR.'c3.php');
51+
copy(__DIR__ . DIRECTORY_SEPARATOR . 'c3.php', getcwd() . DIRECTORY_SEPARATOR.'c3.php');
4952
$this->io->write("<comment>[codeception/c3]</comment> Include c3.php into index.php in order to collect codecoverage from server scripts");
5053
}
5154

5255
public function askForUpdate()
5356
{
54-
if ($this->c3NotChanged()) return;
55-
if (file_exists(getcwd().DIRECTORY_SEPARATOR.'c3.php')) {
57+
if ($this->c3NotChanged()) {
58+
return;
59+
}
60+
if (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'c3.php')) {
5661
$replace = $this->io->askConfirmation("<warning>c3.php has changed</warning> Do you want to replace c3.php with latest version?", false);
57-
if (!$replace) return;
62+
if (!$replace) {
63+
return;
64+
}
5865
}
5966
$this->copyC3();
6067
}
6168

6269
private function c3NotChanged()
6370
{
64-
return file_exists(getcwd().DIRECTORY_SEPARATOR.'c3.php') &&
65-
md5_file(__DIR__.DIRECTORY_SEPARATOR.'c3.php') === md5_file(getcwd().DIRECTORY_SEPARATOR.'c3.php');
71+
return file_exists(getcwd() . DIRECTORY_SEPARATOR . 'c3.php') &&
72+
md5_file(__DIR__ . DIRECTORY_SEPARATOR . 'c3.php') === md5_file(getcwd() . DIRECTORY_SEPARATOR . 'c3.php');
6673
}
6774

75+
public function deleteC3()
76+
{
77+
if (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'c3.php')) {
78+
$this->io->write("<comment>[codeception/c3]</comment> Deleting c3.php from the root of your project...");
79+
unlink(getcwd() . DIRECTORY_SEPARATOR . 'c3.php');
80+
}
81+
}
6882
}
6983

c3.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
if ($cookie) {
2323
foreach ($cookie as $key => $value) {
24-
$_SERVER["HTTP_X_CODECEPTION_".strtoupper($key)] = $value;
24+
$_SERVER["HTTP_X_CODECEPTION_" . strtoupper($key)] = $value;
2525
}
2626
}
2727
}
@@ -38,7 +38,7 @@ function __c3_error($message)
3838
C3_CODECOVERAGE_MEDIATE_STORAGE . DIRECTORY_SEPARATOR . 'error.txt';
3939
if (is_writable($errorLogFile)) {
4040
file_put_contents($errorLogFile, $message);
41-
}else{
41+
} else {
4242
$message = "Could not write error to log file ($errorLogFile), original message: $message";
4343
}
4444
if (!headers_sent()) {
@@ -61,7 +61,7 @@ class_alias('SebastianBergmann\CodeCoverage\Exception', 'PHP_CodeCoverage_Except
6161
// Autoload Codeception classes
6262
if (!class_exists('\\Codeception\\Codecept')) {
6363
if (file_exists(__DIR__ . '/codecept.phar')) {
64-
require_once 'phar://'.__DIR__ . '/codecept.phar/autoload.php';
64+
require_once 'phar://' . __DIR__ . '/codecept.phar/autoload.php';
6565
} elseif (stream_resolve_include_path(__DIR__ . '/vendor/autoload.php')) {
6666
require_once __DIR__ . '/vendor/autoload.php';
6767
// Required to load some methods only available at codeception/autoload.php
@@ -71,7 +71,7 @@ class_alias('SebastianBergmann\CodeCoverage\Exception', 'PHP_CodeCoverage_Except
7171
} elseif (stream_resolve_include_path('Codeception/autoload.php')) {
7272
require_once 'Codeception/autoload.php';
7373
} else {
74-
__c3_error('Codeception is not loaded. Please check that either PHAR or Composer or PEAR package can be used');
74+
__c3_error('Codeception is not loaded. Please check that either PHAR or Composer package can be used');
7575
}
7676
}
7777

@@ -266,7 +266,7 @@ function () use ($codeCoverage, $current_report) {
266266

267267
$codeCoverage->stop();
268268
if (!file_exists(dirname($current_report))) { // verify directory exists
269-
if(!mkdir(dirname($current_report), 0777, true)){
269+
if (!mkdir(dirname($current_report), 0777, true)) {
270270
__c3_error("Can't write CodeCoverage report into $current_report");
271271
}
272272
}

0 commit comments

Comments
 (0)