diff --git a/bin/create-default-fs.php b/bin/create-default-fs.php index f47a1b0..43ef82d 100755 --- a/bin/create-default-fs.php +++ b/bin/create-default-fs.php @@ -22,7 +22,7 @@ $volume = $app->volumes->getVolumeByHandle('local'); if (! $volume) { - $volume = new \craft\models\Volume(); + $volume = new \craft\models\Volume; $volume->name = 'Local'; $volume->handle = 'local'; $volume->fs = $fs; diff --git a/composer.json b/composer.json index aa0e889..2fb9c81 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "src/helpers/Craft.php", "src/helpers/Http.php", "src/helpers/Model.php", + "src/helpers/Queue.php", "src/helpers/Test.php" ] }, diff --git a/src/bin/generate-docs.php b/src/bin/generate-docs.php index 108e01c..0554620 100644 --- a/src/bin/generate-docs.php +++ b/src/bin/generate-docs.php @@ -59,7 +59,7 @@ function parseClass(string $className) function parseComment(string $comment) { preg_match_all('/@see\s+(.+)$/m', $comment, $sees); - foreach (($sees[1] ?? []) as $index => $otherClass) { + foreach ($sees[1] as $index => $otherClass) { $comment = str_replace($sees[0][$index], 'SEE['.$otherClass.']', $comment); } @@ -71,7 +71,7 @@ function parseComment(string $comment) $comment = preg_replace('/(^\s+|\s+$)/', '', $comment); preg_match_all('/^SEE\[(.+)\]$/m', $comment, $sees); - foreach (($sees[1] ?? []) as $index => $otherClass) { + foreach ($sees[1] as $index => $otherClass) { $comment = str_replace($sees[0][$index], "\n\n".implode("\n\n", parseClass($otherClass))."\n\n", $comment); } diff --git a/src/console/TestableResponse.php b/src/console/TestableResponse.php index 4861fef..0b9314e 100644 --- a/src/console/TestableResponse.php +++ b/src/console/TestableResponse.php @@ -10,8 +10,7 @@ public function __construct( protected int $exitCode, protected string $stdout, protected string $stderr, - ) { - } + ) {} public function assertSuccesful() { diff --git a/src/events/RollbackTransactionEvent.php b/src/events/RollbackTransactionEvent.php index add3448..18d2d7b 100644 --- a/src/events/RollbackTransactionEvent.php +++ b/src/events/RollbackTransactionEvent.php @@ -4,6 +4,4 @@ use yii\base\Event; -class RollbackTransactionEvent extends Event -{ -} +class RollbackTransactionEvent extends Event {} diff --git a/src/exceptions/AutoCommittingFieldsException.php b/src/exceptions/AutoCommittingFieldsException.php index 2d9158d..ff89255 100644 --- a/src/exceptions/AutoCommittingFieldsException.php +++ b/src/exceptions/AutoCommittingFieldsException.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\exceptions; -class AutoCommittingFieldsException extends \Exception -{ -} +class AutoCommittingFieldsException extends \Exception {} diff --git a/src/factories/Asset.php b/src/factories/Asset.php index 9190709..d7eff35 100644 --- a/src/factories/Asset.php +++ b/src/factories/Asset.php @@ -78,7 +78,7 @@ public function source(string $source) public function newElement() { - return new \craft\elements\Asset(); + return new \craft\elements\Asset; } public function definition(int $index = 0) diff --git a/src/factories/BlockType.php b/src/factories/BlockType.php index aaa1354..824f6d7 100644 --- a/src/factories/BlockType.php +++ b/src/factories/BlockType.php @@ -33,7 +33,7 @@ public function inferences(array $definition = []) public function newElement() { - return new MatrixBlockType(); + return new MatrixBlockType; } public function store($blockType) diff --git a/src/factories/Category.php b/src/factories/Category.php index c041b08..204dca2 100644 --- a/src/factories/Category.php +++ b/src/factories/Category.php @@ -22,7 +22,7 @@ public function group($handle) public function newElement() { - return new \craft\elements\Category(); + return new \craft\elements\Category; } public function definition(int $index = 0) diff --git a/src/factories/Entry.php b/src/factories/Entry.php index 8fdd473..444dcb3 100644 --- a/src/factories/Entry.php +++ b/src/factories/Entry.php @@ -187,7 +187,7 @@ public function inferTypeId(?int $sectionid): ?int */ public function newElement() { - return new \craft\elements\Entry(); + return new \craft\elements\Entry; } /** diff --git a/src/factories/EntryType.php b/src/factories/EntryType.php index a8431ba..68caf14 100644 --- a/src/factories/EntryType.php +++ b/src/factories/EntryType.php @@ -35,7 +35,7 @@ public function inferences(array $definition = []) public function newElement() { - return new EntryTypeModel(); + return new EntryTypeModel; } public function store($entryType) diff --git a/src/factories/Fieldable.php b/src/factories/Fieldable.php index 41461b4..fa21954 100644 --- a/src/factories/Fieldable.php +++ b/src/factories/Fieldable.php @@ -55,7 +55,7 @@ public function storeFields(FieldLayout $fieldLayout, $context = null) ->toArray(); if (empty($fieldLayout->getTabs()[0])) { - $fieldLayoutTab = new FieldLayoutTab(); + $fieldLayoutTab = new FieldLayoutTab; $fieldLayoutTab->name = 'Content'; $fieldLayoutTab->sortOrder = 1; $fieldLayout->setTabs([$fieldLayoutTab]); diff --git a/src/factories/Section.php b/src/factories/Section.php index 530d414..6d75cdf 100644 --- a/src/factories/Section.php +++ b/src/factories/Section.php @@ -66,7 +66,7 @@ public function template(string $template) */ public function newElement() { - return new \craft\models\Section(); + return new \craft\models\Section; } /** @@ -94,7 +94,7 @@ public function inferences(array $definition = []) $handle = $definition['handle']; $definition['siteSettings'] = collect(Craft::$app->sites->getAllSites()) ->mapWithkeys(function ($site) use ($name, $handle) { - $settings = new Section_SiteSettings(); + $settings = new Section_SiteSettings; $settings->siteId = $site->id; $settings->hasUrls = $this->hasUrls; $settings->uriFormat = $this->uriFormat; diff --git a/src/helpers/Craft.php b/src/helpers/Craft.php index 6484fed..96d5b8e 100644 --- a/src/helpers/Craft.php +++ b/src/helpers/Craft.php @@ -80,7 +80,7 @@ function createVolume() function volumeDefinition(array $definition = []) { if (version_greater_than_or_equal_to(\Craft::$app->version, '4')) { - $fileSystem = new \craft\fs\Local(); // @phpstan-ignore-line + $fileSystem = new \craft\fs\Local; // @phpstan-ignore-line $fileSystem->name = $definition['name'].' FS'; // @phpstan-ignore-line $fileSystem->handle = $definition['handle'].'Fs'; // @phpstan-ignore-line $fileSystem->path = \Craft::getAlias('@storage').'/volumes/'.$definition['handle'].'/'; // @phpstan-ignore-line diff --git a/src/helpers/Queue.php b/src/helpers/Queue.php new file mode 100644 index 0000000..60de9d6 --- /dev/null +++ b/src/helpers/Queue.php @@ -0,0 +1,20 @@ +queue->run(); + + return $result; + } +} diff --git a/src/http/requests/GetRequest.php b/src/http/requests/GetRequest.php index 1675c23..e85b0b2 100644 --- a/src/http/requests/GetRequest.php +++ b/src/http/requests/GetRequest.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\http\requests; -class GetRequest extends WebRequest -{ -} +class GetRequest extends WebRequest {} diff --git a/src/http/requests/PostRequest.php b/src/http/requests/PostRequest.php index 59502fa..8f70355 100644 --- a/src/http/requests/PostRequest.php +++ b/src/http/requests/PostRequest.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\http\requests; -class PostRequest extends WebRequest -{ -} +class PostRequest extends WebRequest {} diff --git a/src/overrides/Config.php b/src/overrides/Config.php index 8ee1675..9664291 100644 --- a/src/overrides/Config.php +++ b/src/overrides/Config.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\overrides; -class Config extends \craft\services\Config -{ -} +class Config extends \craft\services\Config {} diff --git a/src/overrides/ProjectConfig.php b/src/overrides/ProjectConfig.php index 64d524f..ad8495e 100644 --- a/src/overrides/ProjectConfig.php +++ b/src/overrides/ProjectConfig.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\overrides; -class ProjectConfig extends \craft\services\Config -{ -} +class ProjectConfig extends \craft\services\Config {} diff --git a/src/pest/PhpReporter.php b/src/pest/PhpReporter.php index 7c8f963..abcff2a 100644 --- a/src/pest/PhpReporter.php +++ b/src/pest/PhpReporter.php @@ -2,6 +2,4 @@ namespace markhuot\craftpest\pest; -class PhpReporter extends Reporter -{ -} +class PhpReporter extends Reporter {} diff --git a/src/test/CleanupRequestState.php b/src/test/CleanupRequestState.php new file mode 100644 index 0000000..ebfb783 --- /dev/null +++ b/src/test/CleanupRequestState.php @@ -0,0 +1,33 @@ +hasProperty('afterRequestCallbacks')) { + $reflect = $reflect->getParentClass(); + } + + if ($reflect) { + $property = $reflect->getProperty('afterRequestCallbacks'); + $property->setValue($app, []); + } + } + } +} diff --git a/src/test/DatabaseAssertions.php b/src/test/DatabaseAssertions.php index e43a8cc..fa47769 100644 --- a/src/test/DatabaseAssertions.php +++ b/src/test/DatabaseAssertions.php @@ -22,7 +22,7 @@ trait DatabaseAssertions */ public function assertDatabaseCount(string $tableName, int $expectedCount) { - $actualCount = (new Query())->from($tableName)->count(); + $actualCount = (new Query)->from($tableName)->count(); $this->assertEquals($expectedCount, $actualCount); } diff --git a/src/test/RefreshesDatabase.php b/src/test/RefreshesDatabase.php index 2eb16c9..d51c485 100644 --- a/src/test/RefreshesDatabase.php +++ b/src/test/RefreshesDatabase.php @@ -129,7 +129,7 @@ public function rollBackTransaction() $this->transaction->rollBack(); - $event = new RollbackTransactionEvent(); + $event = new RollbackTransactionEvent; $event->sender = $this; Event::trigger(RefreshesDatabase::class, 'EVENT_ROLLBACK_TRANSACTION', $event); diff --git a/src/test/TestCase.php b/src/test/TestCase.php index e06c8b7..5eea605 100644 --- a/src/test/TestCase.php +++ b/src/test/TestCase.php @@ -14,6 +14,7 @@ class TestCase extends \PHPUnit\Framework\TestCase { use ActingAs, Benchmark, + CleanupRequestState, CookieState, DatabaseAssertions, Dd, diff --git a/src/web/BenchmarkResult.php b/src/web/BenchmarkResult.php index 6f7fa20..33056d6 100644 --- a/src/web/BenchmarkResult.php +++ b/src/web/BenchmarkResult.php @@ -29,8 +29,7 @@ class BenchmarkResult public function __construct( public int $startProfileAt, public int $endProfileAt, - ) { - } + ) {} // function summary() // { diff --git a/tests/RequestStateTest.php b/tests/RequestStateTest.php new file mode 100644 index 0000000..e74654c --- /dev/null +++ b/tests/RequestStateTest.php @@ -0,0 +1,17 @@ +onAfterRequest(fn () => throw new Exception('An after request callback was not cleared.')); + + expect(true)->toBeTrue(); +}); + +test('expects request state to be empty', function () { + $app = Craft::$app; + $reflect = new ReflectionClass($app); + while ($reflect && ! $reflect->hasProperty('afterRequestCallbacks')) { + $reflect = $reflect->getParentClass(); + } + + expect($reflect->getProperty('afterRequestCallbacks')->getValue($app))->toBeEmpty(); +})->depends('sets request state');