Skip to content

Commit efbcd33

Browse files
committed
Remove most warnings and deprecations from tests
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.
1 parent 0a877e4 commit efbcd33

12 files changed

+54
-4
lines changed

Diff for: Tests/Command/CleanCommandTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ public function testItShouldRemoveExpiredToken(): void
9292

9393
$display = $tester->getDisplay();
9494

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

100100
/**

Diff for: Tests/CustomAssertions.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace FOS\OAuthServerBundle\Tests;
4+
5+
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
6+
7+
trait CustomAssertions {
8+
use ArraySubsetAsserts;
9+
10+
/**
11+
* Replacement for assert removed in PHPUnit 9.
12+
*
13+
* @param mixed $expected
14+
* @param object $actualObject
15+
*/
16+
public static function assertAttributeSame($expected, string $actualAttributeName, $actualObject, string $message = ''): void
17+
{
18+
$prop = new \ReflectionProperty(\get_class($actualObject), $actualAttributeName);
19+
20+
$prop->setAccessible(true);
21+
self::assertSame($expected, $prop->getValue($actualObject));
22+
}
23+
}

Diff for: Tests/DependencyInjection/ConfigurationTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
namespace FOS\OAuthServerBundle\Tests\DependencyInjection;
1515

1616
use FOS\OAuthServerBundle\DependencyInjection\Configuration;
17+
use FOS\OAuthServerBundle\Tests\CustomAssertions;
1718
use Symfony\Component\Config\Definition\ConfigurationInterface;
1819
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1920
use Symfony\Component\Config\Definition\Processor;
2021

2122
class ConfigurationTest extends \PHPUnit\Framework\TestCase
2223
{
24+
use CustomAssertions;
25+
2326
public function testShouldImplementConfigurationInterface(): void
2427
{
2528
$rc = new \ReflectionClass(Configuration::class);

Diff for: Tests/Document/AuthCodeManagerTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
use Doctrine\MongoDB\Query\Builder;
1717
use Doctrine\ODM\MongoDB\DocumentManager;
18-
use Doctrine\ODM\MongoDB\DocumentRepository;
18+
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
1919
use Doctrine\ORM\AbstractQuery;
2020
use FOS\OAuthServerBundle\Document\AuthCodeManager;
2121
use FOS\OAuthServerBundle\Model\AuthCodeInterface;
22+
use FOS\OAuthServerBundle\Tests\CustomAssertions;
2223

2324
/**
2425
* @group time-sensitive
@@ -29,6 +30,8 @@
2930
*/
3031
class AuthCodeManagerTest extends \PHPUnit\Framework\TestCase
3132
{
33+
use CustomAssertions;
34+
3235
/**
3336
* @var \PHPUnit\Framework\MockObject\MockObject|DocumentManager
3437
*/

Diff for: Tests/Document/ClientManagerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\ODM\MongoDB\DocumentRepository;
1818
use FOS\OAuthServerBundle\Document\ClientManager;
1919
use FOS\OAuthServerBundle\Model\ClientInterface;
20+
use FOS\OAuthServerBundle\Tests\CustomAssertions;
2021

2122
/**
2223
* Class ClientManagerTest.
@@ -25,6 +26,8 @@
2526
*/
2627
class ClientManagerTest extends \PHPUnit\Framework\TestCase
2728
{
29+
use CustomAssertions;
30+
2831
/**
2932
* @var \PHPUnit\Framework\MockObject\MockObject|DocumentManager
3033
*/

Diff for: Tests/Entity/AuthCodeManagerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Doctrine\ORM\QueryBuilder;
2121
use FOS\OAuthServerBundle\Entity\AuthCodeManager;
2222
use FOS\OAuthServerBundle\Model\AuthCodeInterface;
23+
use FOS\OAuthServerBundle\Tests\CustomAssertions;
2324

2425
/**
2526
* @group time-sensitive
@@ -30,6 +31,8 @@
3031
*/
3132
class AuthCodeManagerTest extends \PHPUnit\Framework\TestCase
3233
{
34+
use CustomAssertions;
35+
3336
/**
3437
* @var \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface
3538
*/

Diff for: Tests/Entity/ClientManagerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\ORM\EntityRepository;
1818
use FOS\OAuthServerBundle\Entity\ClientManager;
1919
use FOS\OAuthServerBundle\Model\ClientInterface;
20+
use FOS\OAuthServerBundle\Tests\CustomAssertions;
2021

2122
/**
2223
* Class ClientManagerTest.
@@ -25,6 +26,8 @@
2526
*/
2627
class ClientManagerTest extends \PHPUnit\Framework\TestCase
2728
{
29+
use CustomAssertions;
30+
2831
/**
2932
* @var \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface
3033
*/

Diff for: Tests/Entity/TokenManagerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use FOS\OAuthServerBundle\Entity\AccessToken;
2222
use FOS\OAuthServerBundle\Entity\TokenManager;
2323
use FOS\OAuthServerBundle\Model\TokenInterface;
24+
use FOS\OAuthServerBundle\Tests\CustomAssertions;
2425

2526
/**
2627
* @group time-sensitive
@@ -31,6 +32,8 @@
3132
*/
3233
class TokenManagerTest extends \PHPUnit\Framework\TestCase
3334
{
35+
use CustomAssertions;
36+
3437
/**
3538
* @var \PHPUnit\Framework\MockObject\MockObject|EntityManagerInterface
3639
*/

Diff for: Tests/Form/Handler/AuthorizeFormHandlerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use FOS\OAuthServerBundle\Form\Handler\AuthorizeFormHandler;
1717
use FOS\OAuthServerBundle\Form\Model\Authorize;
18+
use FOS\OAuthServerBundle\Tests\CustomAssertions;
1819
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Serialization\Author;
1920
use Symfony\Component\DependencyInjection\ContainerInterface;
2021
use Symfony\Component\Form\FormInterface;
@@ -29,6 +30,8 @@
2930
*/
3031
class AuthorizeFormHandlerTest extends \PHPUnit\Framework\TestCase
3132
{
33+
use CustomAssertions;
34+
3235
/**
3336
* @var FormInterface&\PHPUnit\Framework\MockObject\MockObject
3437
*/

Diff for: Tests/Functional/config/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ framework:
33
secret: test
44
router:
55
resource: '%kernel.project_dir%/Tests/Functional/config/routing.yml'
6+
utf8: true
67

78
twig:
89
exception_controller: null

Diff for: composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"twig/twig": "<1.40 || >=2.0,<2.9"
3232
},
3333
"require-dev": {
34+
"dms/phpunit-arraysubset-asserts": "^0.1 || ^0.2",
3435
"doctrine/doctrine-bundle": "^2.0",
3536
"doctrine/mongodb-odm": "~1.0",
3637
"doctrine/orm": "~2.2",

Diff for: phpunit.xml.dist

+4
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@
2727
<listeners>
2828
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
2929
</listeners>
30+
31+
<php>
32+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="7" />
33+
</php>
3034
</phpunit>

0 commit comments

Comments
 (0)