diff --git a/Document/AuthCodeManager.php b/Document/AuthCodeManager.php index f8edfc72..05b2b44c 100644 --- a/Document/AuthCodeManager.php +++ b/Document/AuthCodeManager.php @@ -46,11 +46,6 @@ public function __construct(DocumentManager $dm, $class) $this->class = $class; } - public function getDocumentManager(): DocumentManager - { - return $this->dm; - } - /** * {@inheritdoc} */ diff --git a/Document/ClientManager.php b/Document/ClientManager.php index c3d15d52..5fde9b3d 100644 --- a/Document/ClientManager.php +++ b/Document/ClientManager.php @@ -46,16 +46,6 @@ public function __construct(DocumentManager $dm, $class) $this->class = $class; } - public function getRepository(): DocumentRepository - { - return $this->repository; - } - - public function getDocumentManager(): DocumentManager - { - return $this->dm; - } - /** * {@inheritdoc} */ diff --git a/Entity/AuthCodeManager.php b/Entity/AuthCodeManager.php index 4803db99..355f2bd2 100644 --- a/Entity/AuthCodeManager.php +++ b/Entity/AuthCodeManager.php @@ -38,11 +38,6 @@ public function __construct(EntityManagerInterface $em, $class) $this->class = $class; } - public function getEntityManager(): EntityManagerInterface - { - return $this->em; - } - /** * {@inheritdoc} */ diff --git a/Entity/ClientManager.php b/Entity/ClientManager.php index ed80a9e3..346c9732 100644 --- a/Entity/ClientManager.php +++ b/Entity/ClientManager.php @@ -79,14 +79,4 @@ public function deleteClient(ClientInterface $client) $this->em->remove($client); $this->em->flush(); } - - public function getEntityManager(): EntityManagerInterface - { - return $this->em; - } - - public function getRepository(): EntityRepository - { - return $this->repository; - } } diff --git a/Entity/TokenManager.php b/Entity/TokenManager.php index 4843618a..4a87c17f 100644 --- a/Entity/TokenManager.php +++ b/Entity/TokenManager.php @@ -94,14 +94,4 @@ public function deleteExpired() return $qb->getQuery()->execute(); } - - public function getEntityManager(): EntityManagerInterface - { - return $this->em; - } - - public function getRepository(): EntityRepository - { - return $this->repository; - } } diff --git a/Form/Handler/AuthorizeFormHandler.php b/Form/Handler/AuthorizeFormHandler.php index 70ff6d0e..4f29097d 100644 --- a/Form/Handler/AuthorizeFormHandler.php +++ b/Form/Handler/AuthorizeFormHandler.php @@ -107,16 +107,6 @@ public function getScope() return $this->form->getData()->scope; } - public function getForm(): FormInterface - { - return $this->form; - } - - public function getRequest() - { - return $this->requestStack; - } - /** * Put form data in $_GET so that OAuth2 library will call Request::createFromGlobals(). * diff --git a/Tests/Document/AuthCodeManagerTest.php b/Tests/Document/AuthCodeManagerTest.php index d3c5ca06..4ac4c670 100644 --- a/Tests/Document/AuthCodeManagerTest.php +++ b/Tests/Document/AuthCodeManagerTest.php @@ -19,8 +19,8 @@ use Doctrine\ORM\AbstractQuery; use FOS\OAuthServerBundle\Document\AuthCodeManager; use FOS\OAuthServerBundle\Model\AuthCodeInterface; +use FOS\OAuthServerBundle\Tests\TestCase; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; /** * @group time-sensitive @@ -81,7 +81,7 @@ public function setUp(): void public function testConstructWillSetParameters(): void { - self::assertSame($this->documentManager, $this->instance->getDocumentManager()); + self::assertObjectPropertySame($this->documentManager, $this->instance, 'dm'); self::assertSame($this->className, $this->instance->getClass()); } diff --git a/Tests/Document/ClientManagerTest.php b/Tests/Document/ClientManagerTest.php index 7419d43f..5cc2bc72 100644 --- a/Tests/Document/ClientManagerTest.php +++ b/Tests/Document/ClientManagerTest.php @@ -17,8 +17,8 @@ use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use FOS\OAuthServerBundle\Document\ClientManager; use FOS\OAuthServerBundle\Model\ClientInterface; +use FOS\OAuthServerBundle\Tests\TestCase; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; use function random_bytes; use stdClass; @@ -79,8 +79,8 @@ public function setUp(): void public function testConstructWillSetParameters(): void { - self::assertSame($this->documentManager, $this->instance->getDocumentManager()); - self::assertSame($this->repository, $this->instance->getRepository()); + self::assertObjectPropertySame($this->documentManager, $this->instance, 'dm'); + self::assertObjectPropertySame($this->repository, $this->instance, 'repository'); self::assertSame($this->className, $this->instance->getClass()); } diff --git a/Tests/Entity/AuthCodeManagerTest.php b/Tests/Entity/AuthCodeManagerTest.php index 83fe59ca..6e9d98a4 100644 --- a/Tests/Entity/AuthCodeManagerTest.php +++ b/Tests/Entity/AuthCodeManagerTest.php @@ -20,8 +20,8 @@ use Doctrine\ORM\QueryBuilder; use FOS\OAuthServerBundle\Entity\AuthCodeManager; use FOS\OAuthServerBundle\Model\AuthCodeInterface; +use FOS\OAuthServerBundle\Tests\TestCase; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; /** * @group time-sensitive @@ -62,7 +62,7 @@ public function setUp(): void public function testConstructWillSetParameters(): void { - self::assertSame($this->entityManager, $this->instance->getEntityManager()); + self::assertObjectPropertySame($this->entityManager, $this->instance, 'em'); self::assertSame($this->className, $this->instance->getClass()); } diff --git a/Tests/Entity/ClientManagerTest.php b/Tests/Entity/ClientManagerTest.php index 7ae539cb..194ab5f4 100644 --- a/Tests/Entity/ClientManagerTest.php +++ b/Tests/Entity/ClientManagerTest.php @@ -17,8 +17,8 @@ use Doctrine\ORM\EntityRepository; use FOS\OAuthServerBundle\Entity\ClientManager; use FOS\OAuthServerBundle\Model\ClientInterface; +use FOS\OAuthServerBundle\Tests\TestCase; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; use function random_bytes; /** @@ -74,8 +74,8 @@ public function setUp(): void public function testConstructWillSetParameters(): void { - self::assertSame($this->entityManager, $this->instance->getEntityManager()); - self::assertSame($this->repository, $this->instance->getRepository()); + self::assertObjectPropertySame($this->entityManager, $this->instance, 'em'); + self::assertObjectPropertySame($this->repository, $this->instance, 'repository'); self::assertSame($this->className, $this->instance->getClass()); } diff --git a/Tests/Entity/TokenManagerTest.php b/Tests/Entity/TokenManagerTest.php index 39f7fc96..97f03543 100644 --- a/Tests/Entity/TokenManagerTest.php +++ b/Tests/Entity/TokenManagerTest.php @@ -21,8 +21,8 @@ use FOS\OAuthServerBundle\Entity\AccessToken; use FOS\OAuthServerBundle\Entity\TokenManager; use FOS\OAuthServerBundle\Model\TokenInterface; +use FOS\OAuthServerBundle\Tests\TestCase; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; use function random_bytes; /** @@ -78,8 +78,8 @@ public function setUp(): void public function testConstructWillSetParameters(): void { - self::assertSame($this->entityManager, $this->instance->getEntityManager()); - self::assertSame($this->repository, $this->instance->getRepository()); + self::assertObjectPropertySame($this->entityManager, $this->instance, 'em'); + self::assertObjectPropertySame($this->repository, $this->instance, 'repository'); self::assertSame($this->className, $this->instance->getClass()); } diff --git a/Tests/Form/Handler/AuthorizeFormHandlerTest.php b/Tests/Form/Handler/AuthorizeFormHandlerTest.php index 12f7ab10..4e888615 100644 --- a/Tests/Form/Handler/AuthorizeFormHandlerTest.php +++ b/Tests/Form/Handler/AuthorizeFormHandlerTest.php @@ -15,9 +15,9 @@ use FOS\OAuthServerBundle\Form\Handler\AuthorizeFormHandler; use FOS\OAuthServerBundle\Form\Model\Authorize; +use FOS\OAuthServerBundle\Tests\TestCase; use InvalidArgumentException; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; use function random_bytes; use ReflectionException; use ReflectionMethod; @@ -476,7 +476,7 @@ protected function getReflectionMethod(string $methodName): ReflectionMethod */ private function assertAttributesWereSet(?MockObject $request): void { - self::assertSame($this->form, $this->instance->getForm()); - self::assertSame($request, $this->instance->getRequest()); + self::assertObjectPropertySame($this->form, $this->instance, 'form'); + self::assertObjectPropertySame($request, $this->instance, 'requestStack'); } } diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 7ec4c0d9..30089077 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -13,6 +13,37 @@ namespace FOS\OAuthServerBundle\Tests; -class TestCase extends \PHPUnit\Framework\TestCase +use PHPUnit\Framework\TestCase as BaseTestCase; +use ReflectionClass; + +class TestCase extends BaseTestCase { + /** + * Assert sameness to the value of an object's private or protected member. + * + * @param mixed $expected + * @param object $object + * @param string $property + */ + protected static function assertObjectPropertySame($expected, object $object, string $property): void + { + self::assertSame($expected, self::getProtectedMemberValue($object, $property)); + } + + /** + * Get the value of an object's private or protected member. + * + * @param object $object + * @param string $property + * + * @return mixed + */ + protected static function getProtectedMemberValue(object $object, string $property) + { + $reflectionClass = new ReflectionClass($object); + $reflectionProperty = $reflectionClass->getProperty($property); + $reflectionProperty->setAccessible(true); + + return $reflectionProperty->getValue($object); + } }