]> source.dussan.org Git - nextcloud-server.git/commitdiff
prevent phpunit from messing with the bound $this
authorRobin Appelman <icewind@owncloud.com>
Mon, 23 Feb 2015 14:42:18 +0000 (15:42 +0100)
committerRobin Appelman <icewind@owncloud.com>
Wed, 25 Feb 2015 14:09:41 +0000 (15:09 +0100)
tests/lib/command/asyncbus.php

index d22ce34d83967b0e14f85ff47a59b69c16808230..183eaa29c37176dba2e679fb361fb4982c072140 100644 (file)
@@ -10,6 +10,7 @@
 namespace Test\Command;
 
 use OC\Command\FileAccess;
+use OCP\Command\IBus;
 use OCP\Command\ICommand;
 use Test\BackgroundJob\DummyJobList;
 use Test\TestCase;
@@ -44,6 +45,19 @@ function basicFunction() {
        AsyncBus::$lastCommand = 'function';
 }
 
+// clean class to prevent phpunit putting closure in $this
+class ThisClosureTest {
+       private function privateMethod() {
+               AsyncBus::$lastCommand = 'closure-this';
+       }
+
+       public function test(IBus $bus) {
+               $bus->push(function () {
+                       $this->privateMethod();
+               });
+       }
+}
+
 class AsyncBus extends TestCase {
        /**
         * Basic way to check output from a command
@@ -121,14 +135,11 @@ class AsyncBus extends TestCase {
                $this->assertEquals('closure-self', self::$lastCommand);
        }
 
-       private function privateMethod() {
-               self::$lastCommand = 'closure-this';
-       }
 
        public function testClosureThis() {
-               $this->bus->push(function () {
-                       $this->privateMethod();
-               });
+               // clean class to prevent phpunit putting closure in $this
+               $test = new ThisClosureTest();
+               $test->test($this->bus);
                $this->runJobs();
                $this->assertEquals('closure-this', self::$lastCommand);
        }