Skip to content

Commit

Permalink
got rid of deprecated phpunit calls to assertAttribute but in the pro…
Browse files Browse the repository at this point in the history
…cess had to add public getters on objects which really ought to not be there ... which is not great.
  • Loading branch information
elchris committed Jan 19, 2020
1 parent b497745 commit 1725798
Show file tree
Hide file tree
Showing 30 changed files with 275 additions and 207 deletions.
7 changes: 6 additions & 1 deletion Document/AuthCodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace FOS\OAuthServerBundle\Document;

use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\DocumentRepository;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use FOS\OAuthServerBundle\Model\AuthCodeInterface;
use FOS\OAuthServerBundle\Model\AuthCodeManager as BaseAuthCodeManager;

Expand Down Expand Up @@ -46,6 +46,11 @@ public function __construct(DocumentManager $dm, $class)
$this->class = $class;
}

public function getDocumentManager(): DocumentManager
{
return $this->dm;
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 11 additions & 1 deletion Document/ClientManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace FOS\OAuthServerBundle\Document;

use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\DocumentRepository;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use FOS\OAuthServerBundle\Model\ClientInterface;
use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager;

Expand Down Expand Up @@ -46,6 +46,16 @@ public function __construct(DocumentManager $dm, $class)
$this->class = $class;
}

public function getRepository(): DocumentRepository
{
return $this->repository;
}

public function getDocumentManager(): DocumentManager
{
return $this->dm;
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 5 additions & 0 deletions Entity/AuthCodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public function __construct(EntityManagerInterface $em, $class)
$this->class = $class;
}

public function getEntityManager(): EntityManagerInterface
{
return $this->em;
}

/**
* {@inheritdoc}
*/
Expand Down
10 changes: 10 additions & 0 deletions Entity/ClientManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,14 @@ 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;
}
}
10 changes: 10 additions & 0 deletions Entity/TokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,14 @@ public function deleteExpired()

return $qb->getQuery()->execute();
}

public function getEntityManager(): EntityManagerInterface
{
return $this->em;
}

public function getRepository(): EntityRepository
{
return $this->repository;
}
}
10 changes: 10 additions & 0 deletions Form/Handler/AuthorizeFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,14 @@ private function getCurrentRequest()

return $this->requestStack->getCurrentRequest();
}

public function getForm(): FormInterface
{
return $this->form;
}

public function getRequest()
{
return $this->requestStack;
}
}
2 changes: 1 addition & 1 deletion Tests/Command/CreateClientCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testItShouldCreateClient($client): void
],
]);

$this->assertSame(0, $commandTester->getStatusCode());
self::assertSame(0, $commandTester->getStatusCode());

$output = $commandTester->getDisplay();

Expand Down
8 changes: 4 additions & 4 deletions Tests/Controller/AuthorizeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function testAuthorizeActionWillRenderTemplate(): void
->willReturn($response)
;

$this->assertSame($response, $this->instance->authorizeAction($this->request));
self::assertSame($response, $this->instance->authorizeAction($this->request));
}

public function testAuthorizeActionWillFinishClientAuthorization(): void
Expand Down Expand Up @@ -395,7 +395,7 @@ public function testAuthorizeActionWillFinishClientAuthorization(): void
->willReturn($response)
;

$this->assertSame($response, $this->instance->authorizeAction($this->request));
self::assertSame($response, $this->instance->authorizeAction($this->request));
}

public function testAuthorizeActionWillEnsureLogout(): void
Expand Down Expand Up @@ -484,7 +484,7 @@ public function testAuthorizeActionWillEnsureLogout(): void
->willReturn($response)
;

$this->assertSame($response, $this->instance->authorizeAction($this->request));
self::assertSame($response, $this->instance->authorizeAction($this->request));
}

public function testAuthorizeActionWillProcessAuthorizationForm(): void
Expand Down Expand Up @@ -594,6 +594,6 @@ public function testAuthorizeActionWillProcessAuthorizationForm(): void
->willReturn($response)
;

$this->assertSame($response, $this->instance->authorizeAction($this->request));
self::assertSame($response, $this->instance->authorizeAction($this->request));
}
}
24 changes: 12 additions & 12 deletions Tests/DependencyInjection/FOSOAuthServerExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public function testLoadAuthorizeRouting()

$collection = $loader->load(__DIR__.'/../../Resources/config/routing/authorize.xml');
$authorizeRoute = $collection->get('fos_oauth_server_authorize');
$this->assertSame('/oauth/v2/auth', $authorizeRoute->getPath());
$this->assertSame(['GET', 'POST'], $authorizeRoute->getMethods());
self::assertSame('/oauth/v2/auth', $authorizeRoute->getPath());
self::assertSame(['GET', 'POST'], $authorizeRoute->getMethods());
}

public function testLoadTokenRouting()
Expand All @@ -111,8 +111,8 @@ public function testLoadTokenRouting()

$collection = $loader->load(__DIR__.'/../../Resources/config/routing/token.xml');
$tokenRoute = $collection->get('fos_oauth_server_token');
$this->assertSame('/oauth/v2/token', $tokenRoute->getPath());
$this->assertSame(['GET', 'POST'], $tokenRoute->getMethods());
self::assertSame('/oauth/v2/token', $tokenRoute->getPath());
self::assertSame(['GET', 'POST'], $tokenRoute->getMethods());
}

public function testWithoutService()
Expand All @@ -127,7 +127,7 @@ public function testWithoutService()
$instance = new FOSOAuthServerExtension();
$instance->load([$config], $this->container);

$this->assertSame(
self::assertSame(
$this->container->getParameter('fos_oauth_server.server.options'),
[]
);
Expand All @@ -153,7 +153,7 @@ public function testStringSupportedScopes()
$instance = new FOSOAuthServerExtension();
$instance->load([$config], $this->container);

$this->assertSame(
self::assertSame(
$this->container->getParameter('fos_oauth_server.server.options'),
[
'supported_scopes' => 'scope1 scope2 scope3 scope4',
Expand Down Expand Up @@ -181,7 +181,7 @@ public function testArraySupportedScopes()
$instance = new FOSOAuthServerExtension();
$instance->load([$config], $this->container);

$this->assertSame(
self::assertSame(
$this->container->getParameter('fos_oauth_server.server.options'),
[
'supported_scopes' => 'scope1 scope2 scope3 scope4',
Expand Down Expand Up @@ -235,18 +235,18 @@ public function testShouldAliasServivesWhenCustomDriverIsUsed()
]], $container);

$this->assertTrue($container->hasAlias('fos_oauth_server.storage'));
$this->assertSame('fos_oauth_server.storage.default', (string) $container->getAlias('fos_oauth_server.storage'));
self::assertSame('fos_oauth_server.storage.default', (string) $container->getAlias('fos_oauth_server.storage'));

$this->assertTrue($container->hasAlias('fos_oauth_server.client_manager'));
$this->assertSame('the_client_manager_id', (string) $container->getAlias('fos_oauth_server.client_manager'));
self::assertSame('the_client_manager_id', (string) $container->getAlias('fos_oauth_server.client_manager'));

$this->assertTrue($container->hasAlias('fos_oauth_server.access_token_manager'));
$this->assertSame('the_access_token_manager_id', (string) $container->getAlias('fos_oauth_server.access_token_manager'));
self::assertSame('the_access_token_manager_id', (string) $container->getAlias('fos_oauth_server.access_token_manager'));

$this->assertTrue($container->hasAlias('fos_oauth_server.refresh_token_manager'));
$this->assertSame('the_refresh_token_manager_id', (string) $container->getAlias('fos_oauth_server.refresh_token_manager'));
self::assertSame('the_refresh_token_manager_id', (string) $container->getAlias('fos_oauth_server.refresh_token_manager'));

$this->assertTrue($container->hasAlias('fos_oauth_server.auth_code_manager'));
$this->assertSame('the_auth_code_manager_id', (string) $container->getAlias('fos_oauth_server.auth_code_manager'));
self::assertSame('the_auth_code_manager_id', (string) $container->getAlias('fos_oauth_server.auth_code_manager'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public function setUp() : void

public function testGetPosition()
{
$this->assertSame('pre_auth', $this->instance->getPosition());
self::assertSame('pre_auth', $this->instance->getPosition());
}

public function testGetKey()
{
$this->assertSame('fos_oauth', $this->instance->getKey());
self::assertSame('fos_oauth', $this->instance->getKey());
}

public function testCreate()
Expand Down Expand Up @@ -130,7 +130,7 @@ protected function useDefinitionDecorator()
->willReturn(null)
;

$this->assertSame([
self::assertSame([
'security.authentication.provider.fos_oauth_server.'.$id,
'security.authentication.listener.fos_oauth_server.'.$id,
'fos_oauth_server.security.entry_point',
Expand Down Expand Up @@ -182,7 +182,7 @@ protected function useChildDefinition()
->willReturn(null)
;

$this->assertSame([
self::assertSame([
'security.authentication.provider.fos_oauth_server.'.$id,
'security.authentication.listener.fos_oauth_server.'.$id,
'fos_oauth_server.security.entry_point',
Expand Down
10 changes: 5 additions & 5 deletions Tests/Document/AuthCodeManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public function setUp() : void

public function testConstructWillSetParameters(): void
{
$this->assertAttributeSame($this->documentManager, 'dm', $this->instance);
$this->assertAttributeSame($this->className, 'class', $this->instance);
self::assertSame($this->documentManager, $this->instance->getDocumentManager());
self::assertSame($this->className, $this->instance->getClass());
}

public function testGetClassWillReturnClassName(): void
{
$this->assertSame($this->className, $this->instance->getClass());
self::assertSame($this->className, $this->instance->getClass());
}

public function testFindAuthCodeBy(): void
Expand All @@ -104,7 +104,7 @@ public function testFindAuthCodeBy(): void
->willReturn($randomResult)
;

$this->assertSame($randomResult, $this->instance->findAuthCodeBy($criteria));
self::assertSame($randomResult, $this->instance->findAuthCodeBy($criteria));
}

public function testUpdateAuthCode(): void
Expand Down Expand Up @@ -218,6 +218,6 @@ public function testDeleteExpired(): void
->willReturn($data)
;

$this->assertSame($data['n'], $this->instance->deleteExpired());
self::assertSame($data['n'], $this->instance->deleteExpired());
}
}
21 changes: 11 additions & 10 deletions Tests/Document/ClientManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use FOS\OAuthServerBundle\Document\ClientManager;
use FOS\OAuthServerBundle\Model\ClientInterface;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Class ClientManagerTest.
Expand All @@ -26,7 +27,7 @@
class ClientManagerTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|DocumentManager
* @var MockObject|DocumentManager
*/
protected $documentManager;

Expand All @@ -36,7 +37,7 @@ class ClientManagerTest extends \PHPUnit\Framework\TestCase
protected $className;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|DocumentRepository
* @var MockObject|DocumentRepository
*/
protected $repository;

Expand Down Expand Up @@ -73,19 +74,19 @@ public function setUp() : void
parent::setUp();
}

public function testConstructWillSetParameters()
public function testConstructWillSetParameters(): void
{
$this->assertAttributeSame($this->documentManager, 'dm', $this->instance);
$this->assertAttributeSame($this->repository, 'repository', $this->instance);
$this->assertAttributeSame($this->className, 'class', $this->instance);
self::assertSame($this->documentManager, $this->instance->getDocumentManager());
self::assertSame($this->repository, $this->instance->getRepository());
self::assertSame($this->className, $this->instance->getClass());
}

public function testGetClass()
public function testGetClass(): void
{
$this->assertSame($this->className, $this->instance->getClass());
self::assertSame($this->className, $this->instance->getClass());
}

public function testFindClientBy()
public function testFindClientBy(): void
{
$randomResult = \random_bytes(5);
$criteria = [
Expand All @@ -99,7 +100,7 @@ public function testFindClientBy()
->willReturn($randomResult)
;

$this->assertSame($randomResult, $this->instance->findClientBy($criteria));
self::assertSame($randomResult, $this->instance->findClientBy($criteria));
}

public function testUpdateClient()
Expand Down
6 changes: 3 additions & 3 deletions Tests/Document/TokenManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testFindTokenByToken()
->willReturn($randomResult)
;

$this->assertSame($randomResult, $this->instance->findTokenByToken($randomToken));
self::assertSame($randomResult, $this->instance->findTokenByToken($randomToken));
}

public function testUpdateTokenPersistsAndFlushes()
Expand All @@ -117,7 +117,7 @@ public function testUpdateTokenPersistsAndFlushes()

public function testGetClass()
{
$this->assertSame($this->className, $this->instance->getClass());
self::assertSame($this->className, $this->instance->getClass());
}

public function testDeleteToken()
Expand Down Expand Up @@ -204,6 +204,6 @@ public function testDeleteExpired()
->willReturn($data)
;

$this->assertSame($data['n'], $this->instance->deleteExpired());
self::assertSame($data['n'], $this->instance->deleteExpired());
}
}
Loading

0 comments on commit 1725798

Please sign in to comment.