From 5229f2fc28c0552903d1c0396824cf38b42306ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 27 Nov 2022 19:43:49 +0100 Subject: [PATCH] Fixed UserCheckerTest --- .../Annotations/ColumnSecurityTest.php | 127 ------------------ tests/Security/UserCheckerTest.php | 9 +- 2 files changed, 6 insertions(+), 130 deletions(-) delete mode 100644 tests/Security/Annotations/ColumnSecurityTest.php diff --git a/tests/Security/Annotations/ColumnSecurityTest.php b/tests/Security/Annotations/ColumnSecurityTest.php deleted file mode 100644 index b6cd7f78..00000000 --- a/tests/Security/Annotations/ColumnSecurityTest.php +++ /dev/null @@ -1,127 +0,0 @@ -. - */ - -declare(strict_types=1); - -/** - * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). - * - * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -namespace App\Tests\Security\Annotations; - -use App\Entity\Attachments\AttachmentType; -use App\Security\Annotations\ColumnSecurity; -use PHPUnit\Framework\TestCase; - -class ColumnSecurityTest extends TestCase -{ - public function testGetReadOperation(): void - { - $annotation = new ColumnSecurity(); - $this->assertSame('read', $annotation->getReadOperationName(), 'A new annotation must return read'); - $annotation->read = 'overwritten'; - $this->assertSame('overwritten', $annotation->getReadOperationName()); - $annotation->prefix = 'prefix'; - $this->assertSame('prefix.overwritten', $annotation->getReadOperationName()); - } - - public function testGetEditOperation(): void - { - $annotation = new ColumnSecurity(); - $this->assertSame('edit', $annotation->getEditOperationName(), 'A new annotation must return read'); - $annotation->edit = 'overwritten'; - $this->assertSame('overwritten', $annotation->getEditOperationName()); - $annotation->prefix = 'prefix'; - $this->assertSame('prefix.overwritten', $annotation->getEditOperationName()); - } - - public function placeholderScalarDataProvider(): array - { - return [ - ['string', '???'], - ['integer', 0], - ['int', 0], - ['float', 0.0], - ['object', null], - ['bool', false], - ['boolean', false], - //['datetime', (new \DateTime())->setTimestamp(0)] - ]; - } - - /** - * @dataProvider placeholderScalarDataProvider - * - * @param $expected_value - */ - public function testGetPlaceholderScalar(string $type, $expected_value): void - { - $annotation = new ColumnSecurity(); - $annotation->type = $type; - $this->assertSame($expected_value, $annotation->getPlaceholder()); - } - - public function testGetPlaceholderSpecifiedValue(): void - { - $annotation = new ColumnSecurity(); - $annotation->placeholder = 3434; - $this->assertSame(3434, $annotation->getPlaceholder()); - - $annotation->placeholder = [323]; - $this->assertCount(1, $annotation->getPlaceholder()); - - //If a placeholder is specified we allow every type - $annotation->type = 'type2'; - $annotation->placeholder = 'invalid'; - $this->assertSame('invalid', $annotation->getPlaceholder()); - } - - public function testGetPlaceholderDBElement(): void - { - $annotation = new ColumnSecurity(); - $annotation->type = AttachmentType::class; - - /** @var AttachmentType $placeholder */ - $placeholder = $annotation->getPlaceholder(); - $this->assertInstanceOf(AttachmentType::class, $placeholder); - $this->assertSame('???', $placeholder->getName()); - - $annotation->placeholder = 'test'; - $placeholder = $annotation->getPlaceholder(); - $this->assertInstanceOf(AttachmentType::class, $placeholder); - $this->assertSame('test', $placeholder->getName()); - } -} diff --git a/tests/Security/UserCheckerTest.php b/tests/Security/UserCheckerTest.php index 4b61699e..608d6443 100644 --- a/tests/Security/UserCheckerTest.php +++ b/tests/Security/UserCheckerTest.php @@ -45,15 +45,18 @@ namespace App\Tests\Security; use App\Entity\UserSystem\User; use App\Security\UserChecker; use PHPUnit\Framework\TestCase; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException; use Symfony\Component\Security\Core\Exception\DisabledException; -class UserCheckerTest extends TestCase +class UserCheckerTest extends WebTestCase { protected $service; protected function setUp(): void { - $this->service = new UserChecker(); + self::bootKernel(); + $this->service = self::getContainer()->get(UserChecker::class); } public function testThrowDisabledException(): void @@ -66,7 +69,7 @@ class UserCheckerTest extends TestCase //An disabled user must throw an exception $user->setDisabled(true); - $this->expectException(DisabledException::class); + $this->expectException(CustomUserMessageAccountStatusException::class); $this->service->checkPostAuth($user); } }