[Pkg-owncloud-commits] [owncloud] 22/28: Dont use exceptions for the backgroundjob test cases

David Prévot taffit at moszumanska.debian.org
Sat Dec 7 02:33:32 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit f309920bef41a85ee78244756d80b385e964ca71
Author: Robin Appelman <icewind at owncloud.com>
Date:   Wed Dec 4 16:28:27 2013 +0100

    Dont use exceptions for the backgroundjob test cases
---
 tests/lib/backgroundjob/queuedjob.php | 30 ++++++++++++++-------
 tests/lib/backgroundjob/timedjob.php  | 51 +++++++++++++++++------------------
 2 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/tests/lib/backgroundjob/queuedjob.php b/tests/lib/backgroundjob/queuedjob.php
index 1d37347..19c1b28 100644
--- a/tests/lib/backgroundjob/queuedjob.php
+++ b/tests/lib/backgroundjob/queuedjob.php
@@ -9,8 +9,17 @@
 namespace Test\BackgroundJob;
 
 class TestQueuedJob extends \OC\BackgroundJob\QueuedJob {
+	private $testCase;
+
+	/**
+	 * @param QueuedJob $testCase
+	 */
+	public function __construct($testCase) {
+		$this->testCase = $testCase;
+	}
+
 	public function run($argument) {
-		throw new JobRun(); //throw an exception so we can detect if this function is called
+		$this->testCase->markRun();
 	}
 }
 
@@ -24,19 +33,22 @@ class QueuedJob extends \PHPUnit_Framework_TestCase {
 	 */
 	private $job;
 
+	private $jobRun = false;
+
+	public function markRun() {
+		$this->jobRun = true;
+	}
+
 	public function setup() {
 		$this->jobList = new DummyJobList();
-		$this->job = new TestQueuedJob();
+		$this->job = new TestQueuedJob($this);
 		$this->jobList->add($this->job);
+		$this->jobRun = false;
 	}
 
 	public function testJobShouldBeRemoved() {
-		try {
-			$this->assertTrue($this->jobList->has($this->job, null));
-			$this->job->execute($this->jobList);
-			$this->fail("job should have been run");
-		} catch (JobRun $e) {
-			$this->assertFalse($this->jobList->has($this->job, null));
-		}
+		$this->assertTrue($this->jobList->has($this->job, null));
+		$this->job->execute($this->jobList);
+		$this->assertTrue($this->jobRun);
 	}
 }
diff --git a/tests/lib/backgroundjob/timedjob.php b/tests/lib/backgroundjob/timedjob.php
index f3c3eb4..646a260 100644
--- a/tests/lib/backgroundjob/timedjob.php
+++ b/tests/lib/backgroundjob/timedjob.php
@@ -9,12 +9,18 @@
 namespace Test\BackgroundJob;
 
 class TestTimedJob extends \OC\BackgroundJob\TimedJob {
-	public function __construct() {
+	private $testCase;
+
+	/**
+	 * @param TimedJob $testCase
+	 */
+	public function __construct($testCase) {
 		$this->setInterval(10);
+		$this->testCase = $testCase;
 	}
 
 	public function run($argument) {
-		throw new JobRun(); //throw an exception so we can detect if this function is called
+		$this->testCase->markRun();
 	}
 }
 
@@ -28,44 +34,37 @@ class TimedJob extends \PHPUnit_Framework_TestCase {
 	 */
 	private $job;
 
+	private $jobRun = false;
+
+	public function markRun() {
+		$this->jobRun = true;
+	}
+
 	public function setup() {
 		$this->jobList = new DummyJobList();
-		$this->job = new TestTimedJob();
+		$this->job = new TestTimedJob($this);
 		$this->jobList->add($this->job);
+		$this->jobRun = false;
 	}
 
 	public function testShouldRunAfterInterval() {
 		$this->job->setLastRun(time() - 12);
-		try {
-			$this->job->execute($this->jobList);
-			$this->fail("job should have run");
-		} catch (JobRun $e) {
-		}
-		$this->assertTrue(true);
+		$this->job->execute($this->jobList);
+		$this->assertTrue($this->jobRun);
 	}
 
 	public function testShouldNotRunWithinInterval() {
 		$this->job->setLastRun(time() - 5);
-		try {
-			$this->job->execute($this->jobList);
-		} catch (JobRun $e) {
-			$this->fail("job should not have run");
-		}
-		$this->assertTrue(true);
+		$this->job->execute($this->jobList);
+		$this->assertFalse($this->jobRun);
 	}
 
 	public function testShouldNotTwice() {
 		$this->job->setLastRun(time() - 15);
-		try {
-			$this->job->execute($this->jobList);
-			$this->fail("job should have run the first time");
-		} catch (JobRun $e) {
-			try {
-				$this->job->execute($this->jobList);
-			} catch (JobRun $e) {
-				$this->fail("job should not have run the second time");
-			}
-		}
-		$this->assertTrue(true);
+		$this->job->execute($this->jobList);
+		$this->assertTrue($this->jobRun);
+		$this->jobRun = false;
+		$this->job->execute($this->jobList);
+		$this->assertFalse($this->jobRun);
 	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list