Skip to content

Remove most warnings and deprecations from tests #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 35 additions & 0 deletions Tests/CustomAssertions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

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>