diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-27 10:51:02 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-28 13:52:01 +0200 |
commit | bbd2a07525db6b70645720f4c022b5562543127e (patch) | |
tree | ce97cb458ce1e7098bee4a49de707d07e76cab47 /tests/lib | |
parent | cdcd49b473dc7bad4ffb500977b2b8ea5d6f676e (diff) | |
download | nextcloud-server-bbd2a07525db6b70645720f4c022b5562543127e.tar.gz nextcloud-server-bbd2a07525db6b70645720f4c022b5562543127e.zip |
Remove emitter from class Repair
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/RepairTest.php | 134 | ||||
-rw-r--r-- | tests/lib/repair.php | 159 |
2 files changed, 134 insertions, 159 deletions
diff --git a/tests/lib/RepairTest.php b/tests/lib/RepairTest.php new file mode 100644 index 00000000000..9ae1318eb32 --- /dev/null +++ b/tests/lib/RepairTest.php @@ -0,0 +1,134 @@ +<?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. + */ + +namespace Test; + +use OCP\Migration\IRepairStep; +use Symfony\Component\EventDispatcher\EventDispatcher; + +class TestRepairStep implements IRepairStep { + private $warning; + + public function __construct($warning = false) { + $this->warning = $warning; + } + + public function getName() { + return 'Test Name'; + } + + public function run(\OCP\Migration\IOutput $out) { + if ($this->warning) { + $out->warning('Simulated warning'); + } + else { + $out->info('Simulated info'); + } + } +} + +class RepairTest extends TestCase { + /** @var \OC\Repair */ + private $repair; + + /** @var string[] */ + private $outputArray; + + public function setUp() { + parent::setUp(); + $dispatcher = new EventDispatcher(); + $this->repair = new \OC\Repair([], $dispatcher); + + $dispatcher->addListener('\OC\Repair::warning', function ($event) { + /** @var \Symfony\Component\EventDispatcher\GenericEvent $event */ + $this->outputArray[] = 'warning: ' . $event->getArgument(0); + }); + $dispatcher->addListener('\OC\Repair::info', function ($event) { + /** @var \Symfony\Component\EventDispatcher\GenericEvent $event */ + $this->outputArray[] = 'info: ' . $event->getArgument(0); + }); + $dispatcher->addListener('\OC\Repair::step', function ($event) { + /** @var \Symfony\Component\EventDispatcher\GenericEvent $event */ + $this->outputArray[] = 'step: ' . $event->getArgument(0); + }); + } + + public function testRunRepairStep() { + + $this->repair->addStep(new TestRepairStep(false)); + $this->repair->run(); + + $this->assertEquals( + array( + 'step: Test Name', + 'info: Simulated info', + ), + $this->outputArray + ); + } + + public function testRunRepairStepThatFail() { + + $this->repair->addStep(new TestRepairStep(true)); + $this->repair->run(); + + $this->assertEquals( + array( + 'step: Test Name', + 'warning: Simulated warning', + ), + $this->outputArray + ); + } + + public function testRunRepairStepsWithException() { + $mock = $this->getMock('\Test\TestRepairStep'); + $mock->expects($this->any()) + ->method('run') + ->will($this->throwException(new \Exception())); + $mock->expects($this->any()) + ->method('getName') + ->will($this->returnValue('Exception Test')); + + $this->repair->addStep($mock); + $this->repair->addStep(new TestRepairStep(false)); + + $thrown = false; + try { + $this->repair->run(); + } + catch (\Exception $e) { + $thrown = true; + } + + $this->assertTrue($thrown); + // jump out after exception + $this->assertEquals( + array( + 'step: Exception Test', + ), + $this->outputArray + ); + } + + public function testRunRepairStepsContinueAfterWarning() { + $this->repair->addStep(new TestRepairStep(true)); + $this->repair->addStep(new TestRepairStep(false)); + $this->repair->run(); + + $this->assertEquals( + array( + 'step: Test Name', + 'warning: Simulated warning', + 'step: Test Name', + 'info: Simulated info', + ), + $this->outputArray + ); + } +} diff --git a/tests/lib/repair.php b/tests/lib/repair.php deleted file mode 100644 index a598d3c1a29..00000000000 --- a/tests/lib/repair.php +++ /dev/null @@ -1,159 +0,0 @@ -<?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 OCP\Migration\IRepairStep; - -class TestRepairStep implements IRepairStep { - private $warning; - - public function __construct($warning = false) { - $this->warning = $warning; - } - - public function getName() { - return 'Test Name'; - } - - public function run(\OCP\Migration\IOutput $out) { - if ($this->warning) { - $out->warning('Simulated warning'); - } - else { - $out->info('Simulated info'); - } - } -} - -class Test_Repair extends \Test\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 - ); - } -} |