2013-12-19 19:18:09 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Vincent Petry <pvince81@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detects tests that didn't clean up properly, show a warning, then clean up after them.
|
|
|
|
*/
|
|
|
|
class TestCleanupListener implements PHPUnit_Framework_TestListener {
|
|
|
|
private $verbosity;
|
|
|
|
|
|
|
|
public function __construct($verbosity = 'verbose') {
|
|
|
|
$this->verbosity = $verbosity;
|
|
|
|
}
|
|
|
|
|
2014-04-24 14:42:28 +00:00
|
|
|
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
|
|
|
}
|
2013-12-19 19:18:09 +00:00
|
|
|
|
2014-04-24 14:42:28 +00:00
|
|
|
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
|
|
|
}
|
2013-12-19 19:18:09 +00:00
|
|
|
|
2014-04-24 14:42:28 +00:00
|
|
|
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
|
|
|
}
|
2013-12-19 19:18:09 +00:00
|
|
|
|
2014-04-24 13:16:57 +00:00
|
|
|
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
|
|
|
}
|
|
|
|
|
2014-04-24 14:42:28 +00:00
|
|
|
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
|
|
|
}
|
2013-12-19 19:18:09 +00:00
|
|
|
|
2014-04-24 14:42:28 +00:00
|
|
|
public function startTest(PHPUnit_Framework_Test $test) {
|
|
|
|
}
|
2013-12-19 19:18:09 +00:00
|
|
|
|
2014-04-24 14:42:28 +00:00
|
|
|
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
|
|
|
}
|
2013-12-19 19:18:09 +00:00
|
|
|
|
2014-04-24 14:42:28 +00:00
|
|
|
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
|
|
|
}
|
2013-12-19 19:18:09 +00:00
|
|
|
|
2014-04-24 14:42:28 +00:00
|
|
|
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
2013-12-19 19:18:09 +00:00
|
|
|
if ($this->cleanStrayDataFiles() && $this->isShowSuiteWarning()) {
|
|
|
|
printf("TestSuite '%s': Did not clean up data dir\n", $suite->getName());
|
|
|
|
}
|
|
|
|
if ($this->cleanStrayHooks() && $this->isShowSuiteWarning()) {
|
|
|
|
printf("TestSuite '%s': Did not clean up hooks\n", $suite->getName());
|
|
|
|
}
|
|
|
|
if ($this->cleanProxies() && $this->isShowSuiteWarning()) {
|
|
|
|
printf("TestSuite '%s': Did not clean up proxies\n", $suite->getName());
|
|
|
|
}
|
2014-04-24 14:42:28 +00:00
|
|
|
}
|
2013-12-19 19:18:09 +00:00
|
|
|
|
|
|
|
private function isShowSuiteWarning() {
|
|
|
|
return $this->verbosity === 'suite' || $this->verbosity === 'detail';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isShowDetail() {
|
|
|
|
return $this->verbosity === 'detail';
|
|
|
|
}
|
|
|
|
|
2014-02-19 08:31:54 +00:00
|
|
|
/**
|
|
|
|
* @param string $dir
|
|
|
|
*/
|
2013-12-19 19:18:09 +00:00
|
|
|
private function unlinkDir($dir) {
|
2014-01-13 14:32:11 +00:00
|
|
|
if ($dh = @opendir($dir)) {
|
2013-12-19 19:18:09 +00:00
|
|
|
while (($file = readdir($dh)) !== false) {
|
|
|
|
if ($file === '..' || $file === '.') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$path = $dir . '/' . $file;
|
|
|
|
if (is_dir($path)) {
|
|
|
|
$this->unlinkDir($path);
|
|
|
|
}
|
|
|
|
else {
|
2014-01-13 14:32:11 +00:00
|
|
|
@unlink($path);
|
2013-12-19 19:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dh);
|
|
|
|
}
|
2014-01-13 14:32:11 +00:00
|
|
|
@rmdir($dir);
|
2013-12-19 19:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function cleanStrayDataFiles() {
|
|
|
|
$knownEntries = array(
|
|
|
|
'owncloud.log' => true,
|
|
|
|
'owncloud.db' => true,
|
2014-03-14 12:03:18 +00:00
|
|
|
'.ocdata' => true,
|
2013-12-19 19:18:09 +00:00
|
|
|
'..' => true,
|
|
|
|
'.' => true
|
|
|
|
);
|
|
|
|
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data');
|
|
|
|
$entries = array();
|
|
|
|
if ($dh = opendir($datadir)) {
|
|
|
|
while (($file = readdir($dh)) !== false) {
|
|
|
|
if (!isset($knownEntries[$file])) {
|
|
|
|
$entries[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dh);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($entries) > 0) {
|
|
|
|
foreach ($entries as $entry) {
|
|
|
|
$this->unlinkDir($datadir . '/' . $entry);
|
|
|
|
if ($this->isShowDetail()) {
|
|
|
|
printf("Stray datadir entry: %s\n", $entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function cleanStrayHooks() {
|
|
|
|
$hasHooks = false;
|
|
|
|
$hooks = OC_Hook::getHooks();
|
|
|
|
if (!$hooks || sizeof($hooks) === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($hooks as $signalClass => $signals) {
|
|
|
|
if (sizeof($signals)) {
|
|
|
|
foreach ($signals as $signalName => $handlers ) {
|
|
|
|
if (sizeof($handlers) > 0) {
|
|
|
|
$hasHooks = true;
|
|
|
|
OC_Hook::clear($signalClass, $signalName);
|
|
|
|
if ($this->isShowDetail()) {
|
|
|
|
printf("Stray hook: \"%s\" \"%s\"\n", $signalClass, $signalName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $hasHooks;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function cleanProxies() {
|
|
|
|
$proxies = OC_FileProxy::getProxies();
|
|
|
|
OC_FileProxy::clearProxies();
|
|
|
|
return count($proxies) > 0;
|
|
|
|
}
|
|
|
|
}
|