Skip to content
Permalink
Browse files

Merge pull request #61 from tarlepp/phpunit8

Refactor/PHPUnit 8
  • Loading branch information...
tarlepp committed Jun 6, 2019
2 parents 0a24380 + fdf66e6 commit ba39de1545a7af290e756d7f782d651842d4548a
Showing with 1,855 additions and 1,004 deletions.
  1. +3 −0 .dockerignore
  2. +3 −0 .gitignore
  3. +2 −2 composer.json
  4. +198 −197 composer.lock
  5. +1 −1 phpunit.xml.dist
  6. +1 −0 psalm.xml
  7. +2 −2 src/Utils/Tests/Auth.php
  8. +13 −13 src/Utils/Tests/RestTraitTestCase.php
  9. +10 −6 tests/Functional/Maker/RestApiMakerTest.php
  10. +8 −8 tests/Functional/Security/Provider/ApiKeyUserProviderTest.php
  11. +10 −11 tests/Functional/Security/Provider/SecurityUserFactoryTest.php
  12. +19 −3 tests/Integration/ArgumentResolver/UserValueResolverTest.php
  13. +14 −7 tests/Integration/DTO/GenericDtoTest.php
  14. +4 −4 tests/Integration/Doctrine/DBAL/Types/EnumLogLoginTypeTest.php
  15. +3 −4 tests/Integration/Doctrine/DBAL/Types/UTCDateTimeTypeTest.php
  16. +16 −16 tests/Integration/Entity/EntityTestCase.php
  17. +7 −10 tests/Integration/EventListener/UserEntityEventListenerTest.php
  18. +3 −4 tests/Integration/EventSubscriber/BodySubscriberTest.php
  19. +8 −5 tests/Integration/Form/DataTransformer/RoleTransformerTest.php
  20. +7 −5 tests/Integration/Form/DataTransformer/UserGroupTransformerTest.php
  21. +16 −4 tests/Integration/Repository/GenericRepositoryTest.php
  22. +3 −3 tests/Integration/Request/ParamConverter/RestResourceConverterTest.php
  23. +4 −5 tests/Integration/Resource/CollectionTest.php
  24. +39 −30 tests/Integration/Resource/GenericResourceTest.php
  25. +12 −12 tests/Integration/Rest/ControllerTest.php
  26. +37 −14 tests/Integration/Rest/ResponseHandlerTest.php
  27. +12 −11 tests/Integration/Rest/Traits/Methods/CountMethodTest.php
  28. +13 −14 tests/Integration/Rest/Traits/Methods/CreateMethodTest.php
  29. +12 −11 tests/Integration/Rest/Traits/Methods/DeleteMethodTest.php
  30. +11 −11 tests/Integration/Rest/Traits/Methods/FindMethodTest.php
  31. +13 −11 tests/Integration/Rest/Traits/Methods/FindOneMethodTest.php
  32. +11 −11 tests/Integration/Rest/Traits/Methods/IdsMethodTest.php
  33. +14 −14 tests/Integration/Rest/Traits/Methods/PatchMethodTest.php
  34. +14 −14 tests/Integration/Rest/Traits/Methods/UpdateMethodTest.php
  35. +24 −4 tests/Integration/Security/Authenticator/ApiKeyAuthenticatorTest.php
  36. +13 −8 tests/Integration/Security/Provider/ApiKeyUserProviderTest.php
  37. +20 −14 tests/Integration/Security/Provider/SecurityUserFactoryTest.php
  38. +6 −6 tests/Integration/Utils/LoginLoggerTest.php
  39. +3 −0 tests/Integration/Validator/Constraints/UniqueEmailValidatorTest.php
  40. +3 −0 tests/Integration/Validator/Constraints/UniqueUsernameValidatorTest.php
  41. +13 −14 tests/Unit/Rest/RequestHandlerTest.php
  42. +29 −32 tests/Unit/Utils/JSONTest.php
  43. +10 −13 tests/Unit/Utils/Tests/PHPUnitUtilTest.php
  44. +60 −60 vendor-bin/ecs/composer.lock
  45. +17 −17 vendor-bin/infection/composer.lock
  46. +5 −5 vendor-bin/phan/composer.lock
  47. +17 −17 vendor-bin/php-coveralls/composer.lock
  48. +60 −60 vendor-bin/phpinsights/composer.lock
  49. +6 −6 vendor-bin/phpstan/composer.lock
  50. +5 −5 vendor-bin/phpunit/composer.json
  51. +958 −196 vendor-bin/phpunit/composer.lock
  52. +63 −84 vendor-bin/psalm/composer.lock
@@ -32,3 +32,6 @@ infection.json

### Vendor bin dependencies
/vendor-bin/*/vendor/

### PHPUnit
.phpunit.result.cache
@@ -35,3 +35,6 @@ infection.json
###> lexik/jwt-authentication-bundle ###
/config/jwt/*.pem
###< lexik/jwt-authentication-bundle ###

### PHPUnit
.phpunit.result.cache
@@ -115,11 +115,11 @@
"symfony/debug": "<3.3"
},
"extra": {
"allow-contrib": "true",
"projectTitle": "Symfony Flex Backend",
"symfony": {
"id": "01BFA135DXTPRA5CR250NTJJJP",
"allow-contrib": "true",
"require": "4.3.0"
"require": "4.3.1"
}
}
}

Large diffs are not rendered by default.

@@ -2,7 +2,7 @@

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
@@ -11,6 +11,7 @@

<ignoreFiles>
<directory name="vendor" />
<directory name="src/Utils/Tests" />
<file name="src/Kernel.php" />
</ignoreFiles>
</projectFiles>
@@ -9,7 +9,7 @@
namespace App\Utils\Tests;
use App\Utils\JSON;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Throwable;
@@ -138,7 +138,7 @@ private function getToken(string $username, string $password): string
if (!array_key_exists($hash, $cache)) {
// Get client
/** @noinspection MissingService */
/** @var Client $client */
/** @var KernelBrowser $client */
$client = $this->testContainer->get('test.client');
// Create request to make login using given credentials
@@ -8,9 +8,9 @@
namespace App\Utils\Tests;
use Exception;
use Generator;
use Ramsey\Uuid\Uuid;
use Throwable;
use function array_merge;
/**
@@ -51,7 +51,7 @@ abstract class RestTraitTestCase extends WebTestCase
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatCountRouteDoesNotAllowNotSupportedHttpMethods(
?string $username = null,
@@ -76,7 +76,7 @@ public function testThatCountRouteDoesNotAllowNotSupportedHttpMethods(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatCountRouteWorksWithAllowedHttpMethods(
?string $username = null,
@@ -101,7 +101,7 @@ public function testThatCountRouteWorksWithAllowedHttpMethods(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatCountRouteDoesNotAllowInvalidUser(
?string $username = null,
@@ -126,7 +126,7 @@ public function testThatCountRouteDoesNotAllowInvalidUser(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatRootRouteDoesNotAllowNotSupportedHttpMethods(
?string $username = null,
@@ -151,7 +151,7 @@ public function testThatRootRouteDoesNotAllowNotSupportedHttpMethods(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatRootRouteWorksWithAllowedHttpMethods(
?string $username = null,
@@ -176,7 +176,7 @@ public function testThatRootRouteWorksWithAllowedHttpMethods(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatRootRouteDoesNotAllowInvalidUser(
?string $username = null,
@@ -201,7 +201,7 @@ public function testThatRootRouteDoesNotAllowInvalidUser(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatRootRouteWithIdDoesNotAllowNotSupportedHttpMethods(
?string $username = null,
@@ -228,7 +228,7 @@ public function testThatRootRouteWithIdDoesNotAllowNotSupportedHttpMethods(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatRootRouteWithIdWorksWithAllowedHttpMethods(
?string $username = null,
@@ -255,7 +255,7 @@ public function testThatRootRouteWithIdWorksWithAllowedHttpMethods(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatRootRouteWithIdDoesNotAllowInvalidUser(
?string $username = null,
@@ -282,7 +282,7 @@ public function testThatRootRouteWithIdDoesNotAllowInvalidUser(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatIdsRouteDoesNotAllowNotSupportedHttpMethods(
?string $username = null,
@@ -307,7 +307,7 @@ public function testThatIdsRouteDoesNotAllowNotSupportedHttpMethods(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatIdsRouteWorksWithAllowedHttpMethods(
?string $username = null,
@@ -332,7 +332,7 @@ public function testThatIdsRouteWorksWithAllowedHttpMethods(
* @param string|null $password
* @param string|null $method
*
* @throws Exception
* @throws Throwable
*/
public function testThatIdsRouteDoesNotAllowInvalidUser(
?string $username = null,
@@ -6,6 +6,7 @@
use App\Maker\RestApiMaker;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\MakerBundle\Command\MakerCommand;
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\Util\AutoloaderUtil;
@@ -39,20 +40,23 @@ public function testThatCommandRunsWithSuccess(): void
$tester = new CommandTester($command);
$tester->setInputs($inputs);
$tester->execute(array());
$tester->execute([]);
static::assertContains('Success', $tester->getDisplay());
static::assertStringContainsString('Success', $tester->getDisplay());
// Clean up files
$this->fs->remove($maker->getCreatedFiles());
}
/**
* @expectedException \Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException
* @expectedExceptionMessage "App\Controller\123BookController" is not valid as a PHP class name (it must start with a letter or underscore, followed by any number of letters, numbers, or underscores)
*/
public function testThatCommandReturnsAnErrorWithInvalidInput(): void
{
$this->expectException(RuntimeCommandException::class);
/** @codingStandardsIgnoreStart */
$this->expectExceptionMessage('"App\Controller\123BookController" is not valid as a PHP class name (it must start with a letter or underscore, followed by any number of letters, numbers, or underscores)');
/** @codingStandardsIgnoreEnd */
$maker = new RestApiMaker();
$inputs = [
'123Book',
@@ -15,6 +15,8 @@
use App\Security\RolesService;
use Generator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\User;
use Throwable;
use function array_map;
@@ -65,15 +67,14 @@ public function testThatGetApiKeyReturnsNullForInvalidToken(string $shortRole):
unset($apiKey);
}
/** @noinspection PhpFullyQualifiedNameUsageInspection */
/**
* @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
* @expectedExceptionMessage API key is not valid
*
* @throws Throwable
*/
public function testThatLoadUserByUsernameThrowsAnExceptionWithInvalidGuid(): void
{
$this->expectException(UsernameNotFoundException::class);
$this->expectExceptionMessage('API key is not valid');
$this->apiKeyUserProvider->loadUserByUsername((string)time());
}
@@ -95,15 +96,14 @@ public function testThatLoadUserByUsernameWorksAsExpected(string $token, array $
unset($apiKeyUser);
}
/** @noinspection PhpFullyQualifiedNameUsageInspection */
/**
* @expectedException \Symfony\Component\Security\Core\Exception\UnsupportedUserException
* @expectedExceptionMessage API key cannot refresh user
*
* @throws Throwable
*/
public function testThatRefreshUserThrowsAnException(): void
{
$this->expectException(UnsupportedUserException::class);
$this->expectExceptionMessage('API key cannot refresh user');
$user = new User('username', 'password');
$this->apiKeyUserProvider->refreshUser($user);
@@ -10,10 +10,12 @@
use App\Entity\User;
use App\Repository\UserRepository;
use App\Security\SecurityUser;
use App\Security\Provider\SecurityUserFactory;
use App\Security\SecurityUser;
use Generator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\User as CoreUser;
use Throwable;
@@ -35,14 +37,13 @@ class SecurityUserFactoryTest extends KernelTestCase
*/
private $userRepository;
/** @noinspection PhpFullyQualifiedNameUsageInspection */
/**
* @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
*
* @throws Throwable
*/
public function testThatLoadUserByUsernameThrowsAnExceptionWithInvalidUsername(): void
{
$this->expectException(UsernameNotFoundException::class);
static::assertNull($this->securityUserFactory->loadUserByUsername('foobar'));
}
@@ -62,14 +63,13 @@ public function testThatLoadUserByUsernameReturnsExpectedUserInstance(string $us
static::assertSame($roles, $domainUser->getRoles());
}
/** @noinspection PhpFullyQualifiedNameUsageInspection */
/**
* @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
*
* @throws Throwable
*/
public function testThatRefreshUserThrowsAnExceptionIfUserIsNotFound(): void
{
$this->expectException(UsernameNotFoundException::class);
$this->securityUserFactory->refreshUser(new SecurityUser(new User()));
unset($user);
@@ -113,15 +113,14 @@ public function testThatRefreshUserReturnsANewInstanceOfSecurityUser(): void
unset($user);
}
/** @noinspection PhpFullyQualifiedNameUsageInspection */
/**
* @expectedException \Symfony\Component\Security\Core\Exception\UnsupportedUserException
* @expectedExceptionMessage Invalid user class "Symfony\Component\Security\Core\User\User"
*
* @throws Throwable
*/
public function testThatRefreshUserThrowsAnExceptionIfUserClassIsNotSupported(): void
{
$this->expectException(UnsupportedUserException::class);
$this->expectExceptionMessage('Invalid user class "Symfony\Component\Security\Core\User\User"');
$user = new CoreUser('test', 'password');
$this->securityUserFactory->refreshUser($user);

0 comments on commit ba39de1

Please sign in to comment.
You can’t perform that action at this time.