Skip to content

Commit

Permalink
Remove most warnings and deprecations from tests
Browse files Browse the repository at this point in the history
This commit is dependant on FriendsOfSymfony#663 or FriendsOfSymfony#666 to upgrade the PHPUnit
dependency to ^8. It brings the tests to a passing state by removing all
deprecation warnings that are within this project's control.
  • Loading branch information
GKFX committed Oct 8, 2020
1 parent 0a877e4 commit efbcd33
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Tests/Command/CleanCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public function testItShouldRemoveExpiredToken(): void

$display = $tester->getDisplay();

$this->assertContains(sprintf('Removed %d items from %s storage.', $expiredAccessTokens, get_class($this->accessTokenManager)), $display);
$this->assertContains(sprintf('Removed %d items from %s storage.', $expiredRefreshTokens, get_class($this->refreshTokenManager)), $display);
$this->assertContains(sprintf('Removed %d items from %s storage.', $expiredAuthCodes, get_class($this->authCodeManager)), $display);
$this->assertStringContainsString(sprintf('Removed %d items from %s storage.', $expiredAccessTokens, get_class($this->accessTokenManager)), $display);
$this->assertStringContainsString(sprintf('Removed %d items from %s storage.', $expiredRefreshTokens, get_class($this->refreshTokenManager)), $display);
$this->assertStringContainsString(sprintf('Removed %d items from %s storage.', $expiredAuthCodes, get_class($this->authCodeManager)), $display);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions Tests/CustomAssertions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace FOS\OAuthServerBundle\Tests;

use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;

trait CustomAssertions {
use ArraySubsetAsserts;

/**
* Replacement for assert removed in PHPUnit 9.
*
* @param mixed $expected
* @param object $actualObject
*/
public static function assertAttributeSame($expected, string $actualAttributeName, $actualObject, string $message = ''): void
{
$prop = new \ReflectionProperty(\get_class($actualObject), $actualAttributeName);

$prop->setAccessible(true);
self::assertSame($expected, $prop->getValue($actualObject));
}
}
3 changes: 3 additions & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
namespace FOS\OAuthServerBundle\Tests\DependencyInjection;

use FOS\OAuthServerBundle\DependencyInjection\Configuration;
use FOS\OAuthServerBundle\Tests\CustomAssertions;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;

class ConfigurationTest extends \PHPUnit\Framework\TestCase
{
use CustomAssertions;

public function testShouldImplementConfigurationInterface(): void
{
$rc = new \ReflectionClass(Configuration::class);
Expand Down
5 changes: 4 additions & 1 deletion Tests/Document/AuthCodeManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

use Doctrine\MongoDB\Query\Builder;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\DocumentRepository;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use Doctrine\ORM\AbstractQuery;
use FOS\OAuthServerBundle\Document\AuthCodeManager;
use FOS\OAuthServerBundle\Model\AuthCodeInterface;
use FOS\OAuthServerBundle\Tests\CustomAssertions;

/**
* @group time-sensitive
Expand All @@ -29,6 +30,8 @@
*/
class AuthCodeManagerTest extends \PHPUnit\Framework\TestCase
{
use CustomAssertions;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|DocumentManager
*/
Expand Down
3 changes: 3 additions & 0 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\DocumentRepository;
use FOS\OAuthServerBundle\Document\ClientManager;
use FOS\OAuthServerBundle\Model\ClientInterface;
use FOS\OAuthServerBundle\Tests\CustomAssertions;

/**
* Class ClientManagerTest.
Expand All @@ -25,6 +26,8 @@
*/
class ClientManagerTest extends \PHPUnit\Framework\TestCase
{
use CustomAssertions;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|DocumentManager
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Entity/AuthCodeManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Doctrine\ORM\QueryBuilder;
use FOS\OAuthServerBundle\Entity\AuthCodeManager;
use FOS\OAuthServerBundle\Model\AuthCodeInterface;
use FOS\OAuthServerBundle\Tests\CustomAssertions;

/**
* @group time-sensitive
Expand All @@ -30,6 +31,8 @@
*/
class AuthCodeManagerTest extends \PHPUnit\Framework\TestCase
{
use CustomAssertions;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Entity/ClientManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\ORM\EntityRepository;
use FOS\OAuthServerBundle\Entity\ClientManager;
use FOS\OAuthServerBundle\Model\ClientInterface;
use FOS\OAuthServerBundle\Tests\CustomAssertions;

/**
* Class ClientManagerTest.
Expand All @@ -25,6 +26,8 @@
*/
class ClientManagerTest extends \PHPUnit\Framework\TestCase
{
use CustomAssertions;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Entity/TokenManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use FOS\OAuthServerBundle\Entity\AccessToken;
use FOS\OAuthServerBundle\Entity\TokenManager;
use FOS\OAuthServerBundle\Model\TokenInterface;
use FOS\OAuthServerBundle\Tests\CustomAssertions;

/**
* @group time-sensitive
Expand All @@ -31,6 +32,8 @@
*/
class TokenManagerTest extends \PHPUnit\Framework\TestCase
{
use CustomAssertions;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface
*/
Expand Down
3 changes: 3 additions & 0 deletions Tests/Form/Handler/AuthorizeFormHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use FOS\OAuthServerBundle\Form\Handler\AuthorizeFormHandler;
use FOS\OAuthServerBundle\Form\Model\Authorize;
use FOS\OAuthServerBundle\Tests\CustomAssertions;
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Serialization\Author;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\FormInterface;
Expand All @@ -29,6 +30,8 @@
*/
class AuthorizeFormHandlerTest extends \PHPUnit\Framework\TestCase
{
use CustomAssertions;

/**
* @var FormInterface&\PHPUnit\Framework\MockObject\MockObject
*/
Expand Down
1 change: 1 addition & 0 deletions Tests/Functional/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ framework:
secret: test
router:
resource: '%kernel.project_dir%/Tests/Functional/config/routing.yml'
utf8: true

twig:
exception_controller: null
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"twig/twig": "<1.40 || >=2.0,<2.9"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "^0.1 || ^0.2",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/mongodb-odm": "~1.0",
"doctrine/orm": "~2.2",
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="7" />
</php>
</phpunit>

0 comments on commit efbcd33

Please sign in to comment.