Skip to content

Commit

Permalink
Added tests for GedmoExtensionsServiceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Oct 29, 2024
1 parent 3637687 commit d57fa40
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/GedmoExtensionsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace LaravelDoctrine\Extensions;

use Gedmo\DoctrineExtensions;
use Illuminate\Support\ServiceProvider;

class GedmoExtensionsServiceProvider extends ServiceProvider
Expand All @@ -18,6 +19,12 @@ public function register(): void

foreach ($registry->getManagers() as $manager) {
$chain = $manager->getConfiguration()->getMetadataDriverImpl();

if ($this->needsAllMappings()) {
DoctrineExtensions::registerMappingIntoDriverChainORM($chain);
} else {
DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($chain);
}
}
});
}
Expand Down
27 changes: 27 additions & 0 deletions tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace LaravelDoctrineTest\Extensions\Feature;

use Illuminate\Config\Repository;
use LaravelDoctrine\ORM\DoctrineManager;

Check failure on line 8 in tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Type LaravelDoctrine\ORM\DoctrineManager is not used in this file.
use Illuminate\Events\Dispatcher;

Check failure on line 9 in tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Use statements should be sorted alphabetically. The first wrong one is Illuminate\Events\Dispatcher.

Check failure on line 9 in tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Type Illuminate\Events\Dispatcher is not used in this file.

class GedmoExtensionsServiceProviderAllMappingsTest extends TestCase
{
protected function defineEnvironment($app)

Check failure on line 13 in tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Method \LaravelDoctrineTest\Extensions\Feature\GedmoExtensionsServiceProviderAllMappingsTest::defineEnvironment() does not have parameter type hint nor @param annotation for its parameter $app.

Check failure on line 13 in tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Method \LaravelDoctrineTest\Extensions\Feature\GedmoExtensionsServiceProviderAllMappingsTest::defineEnvironment() does not have void return type hint.
{
// Setup default database to use sqlite :memory:
tap($app['config'], function (Repository $config) {

Check failure on line 16 in tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Function tap() should not be referenced via a fallback global name, but via a use statement.

Check failure on line 16 in tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Closure not using "$this" should be declared static.
$config->set('doctrine.gedmo.all_mappings', true);
});
}

public function testCustomExtensionsCanBeRegistered(): void
{
$this->app['events']->dispatch('doctrine.extensions.booting');

$this->assertTrue(true);
}
}
18 changes: 18 additions & 0 deletions tests/Feature/GedmoExtensionsServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace LaravelDoctrineTest\Extensions\Feature;

use LaravelDoctrine\ORM\DoctrineManager;

Check failure on line 7 in tests/Feature/GedmoExtensionsServiceProviderTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Type LaravelDoctrine\ORM\DoctrineManager is not used in this file.
use Illuminate\Events\Dispatcher;

Check failure on line 8 in tests/Feature/GedmoExtensionsServiceProviderTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Use statements should be sorted alphabetically. The first wrong one is Illuminate\Events\Dispatcher.

Check failure on line 8 in tests/Feature/GedmoExtensionsServiceProviderTest.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Type Illuminate\Events\Dispatcher is not used in this file.

class GedmoExtensionsServiceProviderTest extends TestCase
{
public function testCustomExtensionsCanBeRegistered(): void
{
$this->app['events']->dispatch('doctrine.extensions.booting');

$this->assertTrue(true);
}
}
3 changes: 3 additions & 0 deletions tests/Feature/Uploadable/UploadableExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

use Gedmo\Uploadable\UploadableListener;
use LaravelDoctrine\Extensions\Uploadable\UploadableExtension;
use LaravelDoctrine\Extensions\Uploadable\UploadableFacade;
use LaravelDoctrineTest\Extensions\Feature\TestCase;
use Mockery as m;

class UploadableExtensionTest extends TestCase
{
public function testCanRegisterExtension(): void
{
$this->assertFalse(UploadableFacade::isFake());

$listener = m::mock(UploadableListener::class);

$extension = new UploadableExtension(
Expand Down

0 comments on commit d57fa40

Please sign in to comment.