Blame view
sources/tests/lib/repair.php
3.78 KB
|
f7d878ff1
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
<?php
/**
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
use OC\Hooks\BasicEmitter;
class TestRepairStep extends BasicEmitter implements \OC\RepairStep{
private $warning;
public function __construct($warning = false) {
$this->warning = $warning;
}
public function getName() {
return 'Test Name';
}
public function run() {
if ($this->warning) {
$this->emit('\OC\Repair', 'warning', array('Simulated warning'));
}
else {
$this->emit('\OC\Repair', 'info', array('Simulated info'));
}
}
}
class Test_Repair extends PHPUnit_Framework_TestCase {
public function testRunRepairStep() {
$output = array();
$repair = new \OC\Repair();
$repair->addStep(new TestRepairStep(false));
$repair->listen('\OC\Repair', 'warning', function ($description) use (&$output) {
$output[] = 'warning: ' . $description;
});
$repair->listen('\OC\Repair', 'info', function ($description) use (&$output) {
$output[] = 'info: ' . $description;
});
$repair->listen('\OC\Repair', 'step', function ($description) use (&$output) {
$output[] = 'step: ' . $description;
});
$repair->run();
$this->assertEquals(
array(
'step: Test Name',
'info: Simulated info',
),
$output
);
}
public function testRunRepairStepThatFail() {
$output = array();
$repair = new \OC\Repair();
$repair->addStep(new TestRepairStep(true));
$repair->listen('\OC\Repair', 'warning', function ($description) use (&$output) {
$output[] = 'warning: ' . $description;
});
$repair->listen('\OC\Repair', 'info', function ($description) use (&$output) {
$output[] = 'info: ' . $description;
});
$repair->listen('\OC\Repair', 'step', function ($description) use (&$output) {
$output[] = 'step: ' . $description;
});
$repair->run();
$this->assertEquals(
array(
'step: Test Name',
'warning: Simulated warning',
),
$output
);
}
public function testRunRepairStepsWithException() {
$output = array();
$mock = $this->getMock('TestRepairStep');
$mock->expects($this->any())
->method('run')
->will($this->throwException(new Exception));
$mock->expects($this->any())
->method('getName')
->will($this->returnValue('Exception Test'));
$repair = new \OC\Repair();
$repair->addStep($mock);
$repair->addStep(new TestRepairStep(false));
$repair->listen('\OC\Repair', 'warning', function ($description) use (&$output) {
$output[] = 'warning: ' . $description;
});
$repair->listen('\OC\Repair', 'info', function ($description) use (&$output) {
$output[] = 'info: ' . $description;
});
$repair->listen('\OC\Repair', 'step', function ($description) use (&$output) {
$output[] = 'step: ' . $description;
});
$thrown = false;
try {
$repair->run();
}
catch (Exception $e) {
$thrown = true;
}
$this->assertTrue($thrown);
// jump out after exception
$this->assertEquals(
array(
'step: Exception Test',
),
$output
);
}
public function testRunRepairStepsContinueAfterWarning() {
$output = array();
$repair = new \OC\Repair();
$repair->addStep(new TestRepairStep(true));
$repair->addStep(new TestRepairStep(false));
$repair->listen('\OC\Repair', 'warning', function ($description) use (&$output) {
$output[] = 'warning: ' . $description;
});
$repair->listen('\OC\Repair', 'info', function ($description) use (&$output) {
$output[] = 'info: ' . $description;
});
$repair->listen('\OC\Repair', 'step', function ($description) use (&$output) {
$output[] = 'step: ' . $description;
});
$repair->run();
$this->assertEquals(
array(
'step: Test Name',
'warning: Simulated warning',
'step: Test Name',
'info: Simulated info',
),
$output
);
}
}
|