Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -14,7 +14,6 @@ use App\Entity\Project;
use App\Export\Spreadsheet\AnnotatedObjectExporter;
use App\Export\Spreadsheet\Extractor\AnnotationExtractor;
use App\Export\Spreadsheet\SpreadsheetExporter;
use Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -26,11 +25,11 @@ class AnnotatedObjectExporterTest extends TestCase
public function testExport()
{
$spreadsheetExporter = new SpreadsheetExporter($this->createMock(TranslatorInterface::class));
$annotationExtractor = new AnnotationExtractor(new AnnotationReader());
$annotationExtractor = new AnnotationExtractor();
$project = new Project();
$project->setName('test project');
$project->setCustomer((new Customer())->setName('A customer'));
$project->setCustomer(new Customer('A customer'));
$project->setComment('Lorem Ipsum');
$project->setOrderNumber('1234567890');
$project->setBudget(123456.7890);

View File

@@ -11,39 +11,26 @@ namespace App\Tests\Export\Spreadsheet\Entities;
use App\Export\Annotation as Exporter;
/**
* @Exporter\Order({"a-time", "publicProperty", "a-date", "something", "privateProperty"})
* @Exporter\Expose("accessor", label="label.accessor", exp="object.accessorMethod()")
* @Exporter\Expose("a-date", label="label.type-date", exp="object.getDateTime()", type="date")
* @Exporter\Expose("a-time", label="label.type-time", exp="object.getDateTime()", type="time")
*/
#[Exporter\Order(['a-time', 'publicProperty', 'a-date', 'something', 'privateProperty'])]
#[Exporter\Expose(name: 'accessor', label: 'accessor', exp: 'object.accessorMethod()')]
#[Exporter\Expose(name: 'a-date', label: 'type-date', exp: 'object.getDateTime()', type: 'date')]
#[Exporter\Expose(name: 'a-time', label: 'type-time', exp: 'object.getDateTime()', type: 'time')]
class DemoFull
{
/**
* @Exporter\Expose(label="label.Public-Property", type="string")
*/
public $publicProperty = 'public-property';
/**
* @Exporter\Expose("fake-name", label="label.Protected-Property", type="boolean")
*/
protected $protectedProperty = false;
/**
* @Exporter\Expose(label="label.Private-Property", type="integer")
* @phpstan-ignore-next-line
*/
private $privateProperty = 123;
#[Exporter\Expose(label: 'Public-Property', type: 'string')]
public string $publicProperty = 'public-property';
#[Exporter\Expose(name: 'fake-name', label: 'Protected-Property', type: 'boolean')]
protected bool $protectedProperty = false;
#[Exporter\Expose(label: 'Private-Property', type: 'integer')]
private int $privateProperty = 123; // @phpstan-ignore-line
/**
* @Exporter\Expose(label="label.Public-Method")
*/
#[Exporter\Expose(label: 'Public-Method')]
public function publicMethod(): string
{
return 'public-method';
}
/**
* @Exporter\Expose(label="label.Protected-Method", type="datetime")
*/
#[Exporter\Expose(label: 'Protected-Method', type: 'datetime')]
protected function protectedMethod(): \DateTime
{
return new \DateTime();
@@ -54,18 +41,14 @@ class DemoFull
return new \DateTime();
}
/**
* @Exporter\Expose("renamedDuration", label="label.duration", type="duration")
*/
#[Exporter\Expose(name: 'renamedDuration', label: 'duration', type: 'duration')]
protected function duration(): int
{
return 12345;
}
/**
* @Exporter\Expose(name="fake-method", label="label.Private-Method", type="boolean")
* @phpstan-ignore-next-line
*/
// @phpstan-ignore-next-line
#[Exporter\Expose(name: 'fake-method', label: 'Private-Method', type: 'boolean')]
private function privateMethod(): bool
{
return true;

View File

@@ -13,9 +13,7 @@ use App\Export\Annotation as Exporter;
class ExpressionOnMethod
{
/**
* @Exporter\Expose("accessor", label="label.accessor", exp="object.foo")
*/
#[Exporter\Expose(name: 'accessor', label: 'accessor', exp: 'object.foo')]
public function foo()
{
}

View File

@@ -13,9 +13,6 @@ use App\Export\Annotation as Exporter;
class ExpressionOnProperty
{
/**
* @Exporter\Expose("accessor", label="label.accessor", exp="object.foo")
* @phpstan-ignore-next-line
*/
private $foo;
#[Exporter\Expose(name: 'accessor', label: 'accessor', exp: 'object.foo')]
private $foo; // @phpstan-ignore-line
}

View File

@@ -13,9 +13,7 @@ use App\Export\Annotation as Exporter;
class MethodRequiresParams
{
/**
* @Exporter\Expose("accessor", label="label.accessor")
*/
#[Exporter\Expose(name: 'accessor', label: 'accessor')]
public function foo(string $foo)
{
}

View File

@@ -11,9 +11,7 @@ namespace App\Tests\Export\Spreadsheet\Entities;
use App\Export\Annotation as Exporter;
/**
* @Exporter\Expose("accessor", label="label.accessor")
*/
#[Exporter\Expose(name: 'accessor', label: 'accessor')]
class MissingExpressionOnClass
{
}

View File

@@ -11,9 +11,7 @@ namespace App\Tests\Export\Spreadsheet\Entities;
use App\Export\Annotation as Exporter;
/**
* @Exporter\Expose(label="label.accessor", exp="foo")
*/
#[Exporter\Expose(label: 'accessor', exp: 'foo')]
class MissingNameOnClass
{
}

View File

@@ -18,7 +18,6 @@ use App\Export\Spreadsheet\Extractor\AnnotationExtractor;
use App\Export\Spreadsheet\Extractor\MetaFieldExtractor;
use App\Export\Spreadsheet\SpreadsheetExporter;
use App\Repository\Query\ProjectQuery;
use Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -35,15 +34,17 @@ class EntityWithMetaFieldsExporterTest extends TestCase
$event->addField((new ProjectMeta())->setName('foo meta')->setIsVisible(true));
$event->addField((new ProjectMeta())->setName('hidden meta')->setIsVisible(false));
$event->addField((new ProjectMeta())->setName('bar meta')->setIsVisible(true));
return $event;
});
$spreadsheetExporter = new SpreadsheetExporter($this->createMock(TranslatorInterface::class));
$annotationExtractor = new AnnotationExtractor(new AnnotationReader());
$annotationExtractor = new AnnotationExtractor();
$metaFieldExtractor = new MetaFieldExtractor($dispatcher);
$project = new Project();
$project->setName('test project');
$project->setCustomer((new Customer())->setName('A customer'));
$project->setCustomer(new Customer('A customer'));
$project->setComment('Lorem Ipsum');
$project->setOrderNumber('1234567890');
$project->setBudget(123456.7890);

View File

@@ -18,7 +18,6 @@ use App\Tests\Export\Spreadsheet\Entities\ExpressionOnProperty;
use App\Tests\Export\Spreadsheet\Entities\MethodRequiresParams;
use App\Tests\Export\Spreadsheet\Entities\MissingExpressionOnClass;
use App\Tests\Export\Spreadsheet\Entities\MissingNameOnClass;
use Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase;
/**
@@ -31,7 +30,7 @@ class AnnotationExtractorTest extends TestCase
{
public function testExtract()
{
$sut = new AnnotationExtractor(new AnnotationReader());
$sut = new AnnotationExtractor();
$columns = $sut->extract(DemoFull::class);
@@ -43,16 +42,16 @@ class AnnotationExtractorTest extends TestCase
}
$expected = [
['label.type-time', 'time', new \DateTime()],
['label.Public-Property', 'string', 'public-property'],
['label.type-date', 'date', new \DateTime()],
['label.Private-Property', 'integer', 123],
['label.accessor', 'string', 'accessor-method'],
['label.Protected-Property', 'boolean', false],
['label.Public-Method', 'string', 'public-method'],
['label.Protected-Method', 'datetime', new \DateTime()],
['label.duration', 'duration', 12345],
['label.Private-Method', 'boolean', true],
['type-time', 'time', new \DateTime()],
['Public-Property', 'string', 'public-property'],
['type-date', 'date', new \DateTime()],
['Private-Property', 'integer', 123],
['accessor', 'string', 'accessor-method'],
['Protected-Property', 'boolean', false],
['Public-Method', 'string', 'public-method'],
['Protected-Method', 'datetime', new \DateTime()],
['duration', 'duration', 12345],
['Private-Method', 'boolean', true],
];
$i = 0;
@@ -72,7 +71,7 @@ class AnnotationExtractorTest extends TestCase
public function testExceptionOnInvalidType()
{
$sut = new AnnotationExtractor(new AnnotationReader());
$sut = new AnnotationExtractor();
$this->expectException(ExtractorException::class);
$this->expectExceptionMessage('AnnotationExtractor needs a non-empty class name for work');
@@ -83,7 +82,7 @@ class AnnotationExtractorTest extends TestCase
public function testExceptionOnEmptyString()
{
$sut = new AnnotationExtractor(new AnnotationReader());
$sut = new AnnotationExtractor();
$this->expectException(ExtractorException::class);
$this->expectExceptionMessage('AnnotationExtractor needs a non-empty class name for work');
@@ -93,50 +92,50 @@ class AnnotationExtractorTest extends TestCase
public function testExceptionOnMissingExpression()
{
$sut = new AnnotationExtractor(new AnnotationReader());
$sut = new AnnotationExtractor();
$this->expectException(ExtractorException::class);
$this->expectExceptionMessage('@Expose needs an expression attribute on class level hierarchy, check App\Tests\Export\Spreadsheet\Entities\MissingExpressionOnClass::class');
$this->expectExceptionMessage('@Expose needs the "exp" attribute on class level hierarchy, check App\Tests\Export\Spreadsheet\Entities\MissingExpressionOnClass::class');
$sut->extract(MissingExpressionOnClass::class);
}
public function testExceptionOnMissingName()
{
$sut = new AnnotationExtractor(new AnnotationReader());
$sut = new AnnotationExtractor();
$this->expectException(ExtractorException::class);
$this->expectExceptionMessage('@Expose needs a name attribute on class level hierarchy, check App\Tests\Export\Spreadsheet\Entities\MissingNameOnClass::class');
$this->expectExceptionMessage('@Expose needs the "name" attribute on class level hierarchy, check App\Tests\Export\Spreadsheet\Entities\MissingNameOnClass::class');
$sut->extract(MissingNameOnClass::class);
}
public function testExceptionExpressionOnProperty()
{
$sut = new AnnotationExtractor(new AnnotationReader());
$sut = new AnnotationExtractor();
$this->expectException(ExtractorException::class);
$this->expectExceptionMessage('@Expose only supports the expression attribute on class level hierarchy, check App\Tests\Export\Spreadsheet\Entities\ExpressionOnProperty::$foo');
$this->expectExceptionMessage('@Expose only supports the "exp" attribute on class level hierarchy, check App\Tests\Export\Spreadsheet\Entities\ExpressionOnProperty::$foo');
$sut->extract(ExpressionOnProperty::class);
}
public function testExceptionExpressionOnMethod()
{
$sut = new AnnotationExtractor(new AnnotationReader());
$sut = new AnnotationExtractor();
$this->expectException(ExtractorException::class);
$this->expectExceptionMessage('@Expose only supports the expression attribute on class level hierarchy, check App\Tests\Export\Spreadsheet\Entities\ExpressionOnMethod::foo()');
$this->expectExceptionMessage('@Expose only supports the "exp" attribute on method level hierarchy, check App\Tests\Export\Spreadsheet\Entities\ExpressionOnMethod::foo()');
$sut->extract(ExpressionOnMethod::class);
}
public function testExceptionExpressionOnMethodWithRequiredParameters()
{
$sut = new AnnotationExtractor(new AnnotationReader());
$sut = new AnnotationExtractor();
$this->expectException(ExtractorException::class);
$this->expectExceptionMessage('@Expose does not support method App\Tests\Export\Spreadsheet\Entities\MethodRequiresParams::foo(...), it has required parameters.');
$this->expectExceptionMessage('@Expose does not support method App\Tests\Export\Spreadsheet\Entities\MethodRequiresParams::foo(...) as it has required parameters.');
$sut->extract(MethodRequiresParams::class);
}

View File

@@ -32,6 +32,8 @@ class MetaFieldExtractorTest extends TestCase
$event->addField((new ProjectMeta())->setName('foo')->setIsVisible(true));
$event->addField((new ProjectMeta())->setName('no')->setIsVisible(false));
$event->addField((new ProjectMeta())->setName('bar')->setIsVisible(true));
return $event;
});
$sut = new MetaFieldExtractor($dispatcher);

View File

@@ -28,9 +28,11 @@ class UserPreferenceExtractorTest extends TestCase
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects(self::once())->method('dispatch')->willReturnCallback(function (UserPreferenceDisplayEvent $event) {
$event->addPreference((new UserPreference())->setName('foo')->setEnabled(true));
$event->addPreference((new UserPreference())->setName('no')->setEnabled(false));
$event->addPreference((new UserPreference())->setName('bar')->setEnabled(true));
$event->addPreference(new UserPreference('foo'));
$event->addPreference((new UserPreference('no'))->setEnabled(false));
$event->addPreference(new UserPreference('bar'));
return $event;
});
$sut = new UserPreferenceExtractor($dispatcher);
@@ -49,7 +51,7 @@ class UserPreferenceExtractorTest extends TestCase
$definition = $columns[1];
self::assertEquals('bar', $definition->getLabel());
self::assertEquals('string', $definition->getType());
self::assertEquals('tralalalala', \call_user_func($definition->getAccessor(), (new User())->addPreference((new UserPreference())->setName('bar')->setValue('tralalalala'))));
self::assertEquals('tralalalala', \call_user_func($definition->getAccessor(), (new User())->addPreference((new UserPreference('bar', 'tralalalala')))));
}
public function testCheckType()

View File

@@ -15,7 +15,6 @@ use App\Export\Spreadsheet\Extractor\AnnotationExtractor;
use App\Export\Spreadsheet\Extractor\UserPreferenceExtractor;
use App\Export\Spreadsheet\SpreadsheetExporter;
use App\Export\Spreadsheet\UserExporter;
use Doctrine\Common\Annotations\AnnotationReader;
use PHPUnit\Framework\TestCase;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -28,12 +27,12 @@ class UserExporterTest extends TestCase
public function testExport()
{
$spreadsheetExporter = new SpreadsheetExporter($this->createMock(TranslatorInterface::class));
$annotationExtractor = new AnnotationExtractor(new AnnotationReader());
$annotationExtractor = new AnnotationExtractor();
$userPreferenceExtractor = new UserPreferenceExtractor($this->createMock(EventDispatcherInterface::class));
$user = new User();
$user->setAccountNumber('F-747864');
$user->setUsername('test user');
$user->setUserIdentifier('test user');
$user->setAvatar('Lorem Ipsum');
$user->setTimezone('Europe/Berlin');
$user->setColor('#ececec');