-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from bc-luke/big-31502-super-reflection-cache-p
PHPMNT-100 Ensure CachingClassInspector works with no-op cache
- Loading branch information
Showing
2 changed files
with
87 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Reflection; | ||
|
||
use Bigcommerce\Injector\Cache\ArrayServiceCache; | ||
use Bigcommerce\Injector\Cache\ServiceCacheInterface; | ||
use Bigcommerce\Injector\Reflection\CachingClassInspector; | ||
use Bigcommerce\Injector\Reflection\ClassInspector; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
use Tests\Dummy\DummyDependency; | ||
|
||
class NoOpCachingClassInspectorTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
private CachingClassInspector $subject; | ||
private ArrayServiceCache|ObjectProphecy $serviceCache; | ||
private ClassInspector|ObjectProphecy $classInspector; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$serviceCache = $this->prophesize(ServiceCacheInterface::class); | ||
$serviceCache->has(Argument::cetera())->willReturn(false); | ||
$serviceCache->get(Argument::cetera())->willReturn(false); | ||
|
||
$this->serviceCache = $serviceCache; | ||
$this->classInspector = $this->prophesize(ClassInspector::class); | ||
$this->subject = new CachingClassInspector( | ||
$this->classInspector->reveal(), | ||
$this->serviceCache->reveal(), | ||
); | ||
} | ||
|
||
public function testClassHasMethodWorksWithNoOpCache(): void | ||
{ | ||
$this->classInspector->classHasMethod(Argument::cetera())->willReturn(true); | ||
$this->serviceCache->set(Argument::cetera())->shouldBeCalled(); | ||
|
||
$hasMethod = $this->subject->classHasMethod(DummyDependency::class, 'isEnabled'); | ||
|
||
$this->assertTrue($hasMethod); | ||
} | ||
|
||
public function testMethodIsPublicWorksWithNoOpCache(): void | ||
{ | ||
$this->classInspector->methodIsPublic(Argument::cetera())->willReturn(true); | ||
$this->serviceCache->set(Argument::cetera())->shouldBeCalled(); | ||
|
||
$public = $this->subject->methodIsPublic(DummyDependency::class, 'isEnabled'); | ||
|
||
$this->assertTrue($public); | ||
} | ||
|
||
public function testGetMethodSignatureWorksWithNoOpCache(): void | ||
{ | ||
$this->classInspector->getMethodSignature(Argument::cetera())->willReturn([]); | ||
$this->serviceCache->set(Argument::cetera())->shouldBeCalled(); | ||
|
||
$signature = $this->subject->getMethodSignature(DummyDependency::class, 'isEnabled'); | ||
|
||
$this->assertEquals([], $signature); | ||
} | ||
} |