Skip to content

Commit

Permalink
Merge pull request #69 from TomHAnderson/feature/workbench
Browse files Browse the repository at this point in the history
Feature/workbench
  • Loading branch information
TomHAnderson authored Oct 29, 2024
2 parents 41bc654 + 2bca3c4 commit 638e5da
Show file tree
Hide file tree
Showing 23 changed files with 302 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
/coverage
composer.phar
composer.lock
.DS_Store
Expand All @@ -8,3 +9,4 @@ composer.lock
laravel-doctrine-orm.iml
.phpcs-cache
.phpunit.cache

27 changes: 23 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"mockery/mockery": "^1.6",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^11.4"
"phpunit/phpunit": "^11.4",
"orchestra/testbench": "^9.5"
},
"suggest": {
"gedmo/doctrine-extensions": "Behavioral Doctrine2 extensions",
Expand All @@ -50,7 +51,10 @@
},
"autoload-dev": {
"psr-4": {
"LaravelDoctrineTest\\Extensions\\": "tests/"
"LaravelDoctrineTest\\Extensions\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"scripts": {
Expand All @@ -60,11 +64,26 @@
"vendor/bin/phpunit",
"vendor/bin/phpstan analyze src --level 1"
],
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage"
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage",
"post-autoload-dump": [
"@clear",
"@prepare"
],
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve --ansi"
],
"lint": [
"@php vendor/bin/phpstan analyse --verbose --ansi"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
}
7 changes: 0 additions & 7 deletions src/BeberleiExtensionsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,4 @@ public function boot(DoctrineManager $manager): void
$configuration->setCustomStringFunctions($this->string);
});
}

/**
* Register the service provider.
*/
public function register(): void
{
}
}
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
18 changes: 18 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
providers:
- LaravelDoctrine\ORM\DoctrineServiceProvider
- LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider
- LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider

workbench:
start: '/'
install: true
health: false
discovers:
web: false
api: false
commands: false
components: false
views: false
assets:
- laravel-assets
sync: []
27 changes: 5 additions & 22 deletions tests/Feature/BeberleiExtensionsServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,18 @@

namespace LaravelDoctrineTest\Extensions\Feature;

use Illuminate\Contracts\Foundation\Application;
use LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider;
use LaravelDoctrine\ORM\DoctrineManager;
use Mockery as m;
use PHPUnit\Framework\TestCase;

use function app;

class BeberleiExtensionsServiceProviderTest extends TestCase
{
protected Application $app;
protected BeberleiExtensionsServiceProvider $provider;
protected DoctrineManager $manager;

public function setUp(): void
public function testCustomFunctionsCanBeRegistered(): void
{
$this->app = m::mock(Application::class);
$this->manager = m::mock(DoctrineManager::class);
$doctrineManager = $this->app->get(DoctrineManager::class);

$this->provider = new BeberleiExtensionsServiceProvider($this->app);
$entityManager = app('em');

// silence the 'This test did not perform any assertions' warning
$this->assertTrue(true);

parent::setUp();
}

public function testCustomFunctionsCanBeRegistered(): void
{
$this->manager->shouldReceive('extendAll')->once();

$this->provider->boot($this->manager);
}
}
4 changes: 1 addition & 3 deletions tests/Feature/Blameable/BlameableExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class BlameableExtensionTest extends TestCase
{
public function testCanRegisterExtension(): void
{
$guard = m::mock(Guard::class);

$extension = new BlameableExtension(
$guard,
m::mock(Guard::class),
);

$extension->addSubscribers(
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 function tap;

class GedmoExtensionsServiceProviderAllMappingsTest extends TestCase
{
protected function defineEnvironment(mixed $app): void
{
// Setup default database to use sqlite :memory:
tap($app['config'], static function (Repository $config): void {
$config->set('doctrine.gedmo.all_mappings', true);
});
}

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

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

declare(strict_types=1);

namespace LaravelDoctrineTest\Extensions\Feature;

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

$this->assertTrue(true);
}
}
19 changes: 16 additions & 3 deletions tests/Feature/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
use Doctrine\Common\EventManager;
use Doctrine\ORM\EntityManagerInterface;
use Mockery as m;
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase as OrchestraTestCase;

abstract class TestCase extends PHPUnitTestCase
use function restore_error_handler;
use function restore_exception_handler;

abstract class TestCase extends OrchestraTestCase
{
use WithWorkbench;

protected EventManager $evm;
protected EntityManagerInterface $em;

Expand All @@ -19,11 +25,18 @@ public function setUp(): void
$this->evm = m::mock(EventManager::class);
$this->em = m::mock(EntityManagerInterface::class);

$this->evm->shouldReceive('addEventSubscriber')->once();
$this->evm->shouldReceive('addEventSubscriber');

parent::setUp();
}

public function tearDown(): void
{
restore_error_handler();
restore_exception_handler();

m::close();

parent::tearDown();
}
}
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
Empty file added workbench/app/Models/.gitkeep
Empty file.
45 changes: 45 additions & 0 deletions workbench/app/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Workbench\App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
use HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
24 changes: 24 additions & 0 deletions workbench/app/Providers/WorkbenchServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Workbench\App\Providers;

use Illuminate\Support\ServiceProvider;

class WorkbenchServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}

/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}
19 changes: 19 additions & 0 deletions workbench/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

use function Orchestra\Testbench\default_skeleton_path;

return Application::configure(basePath: $APP_BASE_PATH ?? default_skeleton_path())
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
5 changes: 5 additions & 0 deletions workbench/bootstrap/providers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
//
];
Empty file.
Loading

0 comments on commit 638e5da

Please sign in to comment.