Browse Source

convert getObjectForTrait() to anonymous class

Kevin Pfeifer 2 years ago
parent
commit
dfb32b0d7d

+ 7 - 6
tests/TestCase/Core/StaticConfigTraitTest.php

@@ -38,7 +38,9 @@ class StaticConfigTraitTest extends TestCase
     public function setUp(): void
     {
         parent::setUp();
-        $this->subject = $this->getObjectForTrait(StaticConfigTrait::class);
+        $this->subject = new class {
+            use StaticConfigTrait;
+        };
     }
 
     /**
@@ -85,20 +87,19 @@ class StaticConfigTraitTest extends TestCase
     public function testGetConfigOrFail(): void
     {
         $className = get_class($this->subject);
-        $className::setConfig('foo', ['bar' => true]);
+        $className::setConfig('foo2', ['bar' => true]);
 
-        $result = $className::getConfigOrFail('foo');
+        $result = $className::getConfigOrFail('foo2');
         $this->assertSame(['bar' => true], $result);
     }
 
     public function testGetConfigOrFailException(): void
     {
         $this->expectException(InvalidArgumentException::class);
-        $this->expectExceptionMessage('Expected configuration `foo` not found.');
+        $this->expectExceptionMessage('Expected configuration `unknown` not found.');
 
         $className = get_class($this->subject);
-        $result = $className::getConfigOrFail('foo');
-        $this->assertSame('bar', $result);
+        $className::getConfigOrFail('unknown');
     }
 
     /**

+ 3 - 1
tests/TestCase/Event/EventDispatcherTraitTest.php

@@ -37,7 +37,9 @@ class EventDispatcherTraitTest extends TestCase
     {
         parent::setUp();
 
-        $this->subject = $this->getObjectForTrait(EventDispatcherTrait::class);
+        $this->subject = new class {
+            use EventDispatcherTrait;
+        };
     }
 
     /**

+ 4 - 1
tests/TestCase/Log/LogTraitTest.php

@@ -16,6 +16,7 @@ declare(strict_types=1);
 namespace Cake\Test\TestCase\Log;
 
 use Cake\Log\Log;
+use Cake\Log\LogTrait;
 use Cake\TestSuite\TestCase;
 
 /**
@@ -45,7 +46,9 @@ class LogTraitTest extends TestCase
             );
 
         Log::setConfig('trait_test', ['engine' => $mock]);
-        $subject = $this->getObjectForTrait('Cake\Log\LogTrait');
+        $subject = new class {
+            use LogTrait;
+        };
 
         $subject->log('Testing');
         $subject->log('message', 'debug');

+ 3 - 1
tests/TestCase/ORM/Locator/LocatorAwareTraitTest.php

@@ -41,7 +41,9 @@ class LocatorAwareTraitTest extends TestCase
     {
         parent::setUp();
 
-        $this->subject = $this->getObjectForTrait(LocatorAwareTrait::class);
+        $this->subject = new class {
+            use LocatorAwareTrait;
+        };
     }
 
     /**