diff --git a/.gitignore b/.gitignore
index 44aa53f..7988c22 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.idea
composer.phar
vendor/
-RoboFile.php
\ No newline at end of file
+RoboFile.php
+composer.lock
\ No newline at end of file
diff --git a/Installer.php b/Installer.php
index 42ddf2b..1e04265 100644
--- a/Installer.php
+++ b/Installer.php
@@ -21,14 +21,17 @@ public function activate(Composer $composer, IOInterface $io)
public static function getSubscribedEvents()
{
- return array(
- ScriptEvents::POST_INSTALL_CMD => array(
- array('copyC3', 0)
- ),
- ScriptEvents::POST_UPDATE_CMD => array(
- array('askForUpdate', 0)
- )
- );
+ return [
+ ScriptEvents::POST_PACKAGE_INSTALL => [
+ ['copyC3', 0]
+ ],
+ ScriptEvents::POST_PACKAGE_UPDATE => [
+ ['askForUpdate', 0]
+ ],
+ ScriptEvents::POST_PACKAGE_UNINSTALL => [
+ ['deleteC3', 0]
+ ]
+ ];
}
public static function copyC3ToRoot(Event $event)
@@ -45,25 +48,36 @@ public function copyC3()
}
$this->io->write("[codeception/c3] Copying c3.php to the root of your project...");
- copy(__DIR__.DIRECTORY_SEPARATOR.'c3.php', getcwd().DIRECTORY_SEPARATOR.'c3.php');
+ copy(__DIR__ . DIRECTORY_SEPARATOR . 'c3.php', getcwd() . DIRECTORY_SEPARATOR.'c3.php');
$this->io->write("[codeception/c3] Include c3.php into index.php in order to collect codecoverage from server scripts");
}
public function askForUpdate()
{
- if ($this->c3NotChanged()) return;
- if (file_exists(getcwd().DIRECTORY_SEPARATOR.'c3.php')) {
+ if ($this->c3NotChanged()) {
+ return;
+ }
+ if (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'c3.php')) {
$replace = $this->io->askConfirmation("c3.php has changed Do you want to replace c3.php with latest version?", false);
- if (!$replace) return;
+ if (!$replace) {
+ return;
+ }
}
$this->copyC3();
}
private function c3NotChanged()
{
- return file_exists(getcwd().DIRECTORY_SEPARATOR.'c3.php') &&
- md5_file(__DIR__.DIRECTORY_SEPARATOR.'c3.php') === md5_file(getcwd().DIRECTORY_SEPARATOR.'c3.php');
+ return file_exists(getcwd() . DIRECTORY_SEPARATOR . 'c3.php') &&
+ md5_file(__DIR__ . DIRECTORY_SEPARATOR . 'c3.php') === md5_file(getcwd() . DIRECTORY_SEPARATOR . 'c3.php');
}
+ public function deleteC3()
+ {
+ if (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'c3.php')) {
+ $this->io->write("[codeception/c3] Deleting c3.php from the root of your project...");
+ unlink(getcwd() . DIRECTORY_SEPARATOR . 'c3.php');
+ }
+ }
}
diff --git a/c3.php b/c3.php
index 2ce5b6b..4946e22 100644
--- a/c3.php
+++ b/c3.php
@@ -21,7 +21,7 @@
if ($cookie) {
foreach ($cookie as $key => $value) {
- $_SERVER["HTTP_X_CODECEPTION_".strtoupper($key)] = $value;
+ $_SERVER["HTTP_X_CODECEPTION_" . strtoupper($key)] = $value;
}
}
}
@@ -38,7 +38,7 @@ function __c3_error($message)
C3_CODECOVERAGE_MEDIATE_STORAGE . DIRECTORY_SEPARATOR . 'error.txt';
if (is_writable($errorLogFile)) {
file_put_contents($errorLogFile, $message);
- }else{
+ } else {
$message = "Could not write error to log file ($errorLogFile), original message: $message";
}
if (!headers_sent()) {
@@ -61,7 +61,7 @@ class_alias('SebastianBergmann\CodeCoverage\Exception', 'PHP_CodeCoverage_Except
// Autoload Codeception classes
if (!class_exists('\\Codeception\\Codecept')) {
if (file_exists(__DIR__ . '/codecept.phar')) {
- require_once 'phar://'.__DIR__ . '/codecept.phar/autoload.php';
+ require_once 'phar://' . __DIR__ . '/codecept.phar/autoload.php';
} elseif (stream_resolve_include_path(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
// Required to load some methods only available at codeception/autoload.php
@@ -71,7 +71,7 @@ class_alias('SebastianBergmann\CodeCoverage\Exception', 'PHP_CodeCoverage_Except
} elseif (stream_resolve_include_path('Codeception/autoload.php')) {
require_once 'Codeception/autoload.php';
} else {
- __c3_error('Codeception is not loaded. Please check that either PHAR or Composer or PEAR package can be used');
+ __c3_error('Codeception is not loaded. Please check that either PHAR or Composer package can be used');
}
}
@@ -266,7 +266,7 @@ function () use ($codeCoverage, $current_report) {
$codeCoverage->stop();
if (!file_exists(dirname($current_report))) { // verify directory exists
- if(!mkdir(dirname($current_report), 0777, true)){
+ if (!mkdir(dirname($current_report), 0777, true)) {
__c3_error("Can't write CodeCoverage report into $current_report");
}
}