diff --git a/src/IpTraceable/IpTraceable.php b/src/IpTraceable/IpTraceable.php deleted file mode 100644 index 9139066..0000000 --- a/src/IpTraceable/IpTraceable.php +++ /dev/null @@ -1,69 +0,0 @@ -createdFromIp = $createdFromIp; - - return $this; - } - - /** - * Returns createdFromIp. - */ - public function getCreatedFromIp(): string - { - return $this->createdFromIp; - } - - /** - * Sets updatedFromIp. - * - * @return $this - */ - public function setUpdatedFromIp(string $updatedFromIp) - { - $this->updatedFromIp = $updatedFromIp; - - return $this; - } - - /** - * Returns updatedFromIp. - */ - public function getUpdatedFromIp(): string - { - return $this->updatedFromIp; - } -} diff --git a/src/SoftDeletes/SoftDeletes.php b/src/SoftDeletes/SoftDeletes.php deleted file mode 100644 index fa81f2d..0000000 --- a/src/SoftDeletes/SoftDeletes.php +++ /dev/null @@ -1,37 +0,0 @@ -deletedAt; - } - - public function setDeletedAt(DateTime|null $deletedAt = null): void - { - $this->deletedAt = $deletedAt; - } - - /** - * Restore the soft-deleted state - */ - public function restore(): void - { - $this->deletedAt = null; - } - - public function isDeleted(): bool - { - return $this->deletedAt && new DateTime('now') >= $this->deletedAt; - } -} diff --git a/src/Timestamps/Timestamps.php b/src/Timestamps/Timestamps.php deleted file mode 100644 index 4bc912e..0000000 --- a/src/Timestamps/Timestamps.php +++ /dev/null @@ -1,50 +0,0 @@ -createdAt; - } - - public function getUpdatedAt(): DateTime - { - return $this->updatedAt; - } - - public function setCreatedAt(DateTime $createdAt): void - { - $this->createdAt = $createdAt; - } - - public function setUpdatedAt(DateTime $updatedAt): void - { - $this->updatedAt = $updatedAt; - } -} diff --git a/src/Tree/NestedSet.php b/src/Tree/NestedSet.php deleted file mode 100644 index 3467b53..0000000 --- a/src/Tree/NestedSet.php +++ /dev/null @@ -1,87 +0,0 @@ -root; - } - - public function setRoot(int $root): void - { - $this->root = $root; - } - - public function getLevel(): int - { - return $this->level; - } - - public function setLevel(int $level): void - { - $this->level = $level; - } - - public function getLeft(): int - { - return $this->left; - } - - public function setLeft(int $left): void - { - $this->left = $left; - } - - public function getRight(): int - { - return $this->right; - } - - public function setRight(int $right): void - { - $this->right = $right; - } -} diff --git a/testbench.yaml b/testbench.yaml index 18db9dd..83655a9 100644 --- a/testbench.yaml +++ b/testbench.yaml @@ -2,6 +2,7 @@ providers: - LaravelDoctrine\ORM\DoctrineServiceProvider - LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider - LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider + - LaravelDoctrine\Extensions\Uploadable\UploadableExtensionServiceProvider workbench: start: '/' diff --git a/tests/Assets/IpTraceable/IpTraceableEntity.php b/tests/Assets/IpTraceable/IpTraceableEntity.php deleted file mode 100644 index 5091b97..0000000 --- a/tests/Assets/IpTraceable/IpTraceableEntity.php +++ /dev/null @@ -1,12 +0,0 @@ -addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertEmpty($extension->getFilters()); - } -} diff --git a/tests/Feature/Gedmo/SubscribeAllTest.php b/tests/Feature/Gedmo/SubscribeAllTest.php new file mode 100644 index 0000000..e5bf55e --- /dev/null +++ b/tests/Feature/Gedmo/SubscribeAllTest.php @@ -0,0 +1,124 @@ +addSubscribers($this->evm, $this->em); + + $this->assertTrue(true); + $this->assertEmpty($extension->getFilters()); + } + + public function testCanRegisterIpTraceable(): void + { + $request = m::mock(Request::class); + + $request->shouldReceive('getClientIp') + ->once()->andReturn('127.0.0.1'); + + $extension = new IpTraceableExtension($request); + $extension->addSubscribers($this->evm, $this->em); + + $this->assertTrue(true); + $this->assertEmpty($extension->getFilters()); + } + + public function testCanRegisterLoggable(): void + { + $extension = new LoggableExtension(); + $extension->addSubscribers($this->evm, $this->em); + + $this->assertTrue(true); + $this->assertEmpty($extension->getFilters()); + } + + public function testCanRegisterTimestampable(): void + { + $extension = new TimestampableExtension(); + $extension->addSubscribers($this->evm, $this->em); + + $this->assertTrue(true); + $this->assertEmpty($extension->getFilters()); + } + + public function testCanRegisterSluggable(): void + { + $extension = new SluggableExtension(); + $extension->addSubscribers($this->evm, $this->em); + + $this->assertTrue(true); + $this->assertEmpty($extension->getFilters()); + } + + public function testCanRegisterSoftDeletes(): void + { + $extension = new SoftDeleteableExtension(); + $extension->addSubscribers($this->evm, $this->em); + + $this->assertTrue(true); + $this->assertEquals($extension->getFilters(), ['soft-deleteable' => SoftDeleteableFilter::class]); + } + + public function testCanRegisterSortable(): void + { + $extension = new SortableExtension(); + $extension->addSubscribers($this->evm, $this->em); + + $this->assertTrue(true); + $this->assertEmpty($extension->getFilters()); + } + + public function testCanRegisterTranslatable(): void + { + $extension = app(TranslatableExtension::class); + $extension->addSubscribers($this->evm, $this->em); + + $this->assertTrue(true); + $this->assertEmpty($extension->getFilters()); + } + + public function testCanRegisterTree(): void + { + $extension = new TreeExtension(); + $extension->addSubscribers($this->evm, $this->em); + + $this->assertTrue(true); + $this->assertEmpty($extension->getFilters()); + } + + public function testCanRegisterUploadable(): void + { + $extension = new UploadableExtension(app(UploadableListener::class)); + + $this->assertEmpty($extension->getFilters()); + } +} diff --git a/tests/Feature/Translatable/TranslatableExtensionTest.php b/tests/Feature/Gedmo/Translatable/TranslatableExtensionTest.php similarity index 88% rename from tests/Feature/Translatable/TranslatableExtensionTest.php rename to tests/Feature/Gedmo/Translatable/TranslatableExtensionTest.php index 55dfb17..f688eb5 100644 --- a/tests/Feature/Translatable/TranslatableExtensionTest.php +++ b/tests/Feature/Gedmo/Translatable/TranslatableExtensionTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace LaravelDoctrineTest\Extensions\Feature\Translatable; +namespace LaravelDoctrineTest\Extensions\Feature\Gedmo\Translatable; use LaravelDoctrine\Extensions\Translatable\TranslatableExtension; use LaravelDoctrineTest\Extensions\Feature\TestCase; diff --git a/tests/Feature/Uploadable/UploadableExtensionServiceProviderTest.php b/tests/Feature/Gedmo/Uploadable/UploadableExtensionServiceProviderTest.php similarity index 93% rename from tests/Feature/Uploadable/UploadableExtensionServiceProviderTest.php rename to tests/Feature/Gedmo/Uploadable/UploadableExtensionServiceProviderTest.php index e552950..9cb6195 100644 --- a/tests/Feature/Uploadable/UploadableExtensionServiceProviderTest.php +++ b/tests/Feature/Gedmo/Uploadable/UploadableExtensionServiceProviderTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace LaravelDoctrineTest\Extensions\Feature\Uploadable; +namespace LaravelDoctrineTest\Extensions\Feature\Gedmo\Uploadable; use Gedmo\Uploadable\UploadableListener; use Illuminate\Contracts\Foundation\Application; diff --git a/tests/Feature/Uploadable/UploadableExtensionTest.php b/tests/Feature/Gedmo/Uploadable/UploadableExtensionTest.php similarity index 85% rename from tests/Feature/Uploadable/UploadableExtensionTest.php rename to tests/Feature/Gedmo/Uploadable/UploadableExtensionTest.php index 40ca936..e83ddb4 100644 --- a/tests/Feature/Uploadable/UploadableExtensionTest.php +++ b/tests/Feature/Gedmo/Uploadable/UploadableExtensionTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace LaravelDoctrineTest\Extensions\Feature\Uploadable; +namespace LaravelDoctrineTest\Extensions\Feature\Gedmo\Uploadable; use Gedmo\Uploadable\UploadableListener; use LaravelDoctrine\Extensions\Uploadable\UploadableExtension; @@ -10,6 +10,8 @@ use LaravelDoctrineTest\Extensions\Feature\TestCase; use Mockery as m; +use function app; + class UploadableExtensionTest extends TestCase { public function testCanRegisterExtension(): void @@ -19,7 +21,7 @@ public function testCanRegisterExtension(): void $listener = m::mock(UploadableListener::class); $extension = new UploadableExtension( - $listener, + app(UploadableListener::class), ); $extension->addSubscribers( diff --git a/tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php b/tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php index c303028..b9be229 100644 --- a/tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php +++ b/tests/Feature/GedmoExtensionsServiceProviderAllMappingsTest.php @@ -12,6 +12,8 @@ class GedmoExtensionsServiceProviderAllMappingsTest extends TestCase { protected function defineEnvironment(mixed $app): void { + parent::defineEnvironment($app); + // Setup default database to use sqlite :memory: tap($app['config'], static function (Repository $config): void { $config->set('doctrine.gedmo.all_mappings', true); diff --git a/tests/Feature/IpTraceable/IpTraceableExtensionTest.php b/tests/Feature/IpTraceable/IpTraceableExtensionTest.php deleted file mode 100644 index ccdfd0a..0000000 --- a/tests/Feature/IpTraceable/IpTraceableExtensionTest.php +++ /dev/null @@ -1,32 +0,0 @@ -shouldReceive('getClientIp') - ->once()->andReturn('127.0.0.1'); - - $extension = new IpTraceableExtension( - $request, - ); - - $extension->addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertEmpty($extension->getFilters()); - } -} diff --git a/tests/Feature/IpTraceable/IpTraceableTest.php b/tests/Feature/IpTraceable/IpTraceableTest.php deleted file mode 100644 index 697259e..0000000 --- a/tests/Feature/IpTraceable/IpTraceableTest.php +++ /dev/null @@ -1,32 +0,0 @@ -entity = new IpTraceableEntity(); - } - - public function testCanBeSetCreatedFromIp(): void - { - $this->entity->setCreatedFromIp('CREATED_IP'); - - $this->assertEquals('CREATED_IP', $this->entity->getCreatedFromIp()); - } - - public function testCanSetUpdatedFromIp(): void - { - $this->entity->setUpdatedFromIp('UPDATED_IP'); - - $this->assertEquals('UPDATED_IP', $this->entity->getUpdatedFromIp()); - } -} diff --git a/tests/Feature/Loggable/LoggableExtensionTest.php b/tests/Feature/Loggable/LoggableExtensionTest.php deleted file mode 100644 index bfe70cb..0000000 --- a/tests/Feature/Loggable/LoggableExtensionTest.php +++ /dev/null @@ -1,29 +0,0 @@ -addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertEmpty($extension->getFilters()); - } -} diff --git a/tests/Feature/Sluggable/SluggableExtensionTest.php b/tests/Feature/Sluggable/SluggableExtensionTest.php deleted file mode 100644 index 483756c..0000000 --- a/tests/Feature/Sluggable/SluggableExtensionTest.php +++ /dev/null @@ -1,23 +0,0 @@ -addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertEmpty($extension->getFilters()); - } -} diff --git a/tests/Feature/SoftDeletes/SoftDeleteableExtensionTest.php b/tests/Feature/SoftDeletes/SoftDeleteableExtensionTest.php deleted file mode 100644 index b2c74be..0000000 --- a/tests/Feature/SoftDeletes/SoftDeleteableExtensionTest.php +++ /dev/null @@ -1,24 +0,0 @@ -addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertContains(SoftDeleteableFilter::class, $extension->getFilters()); - } -} diff --git a/tests/Feature/SoftDeletes/SoftDeletesTest.php b/tests/Feature/SoftDeletes/SoftDeletesTest.php deleted file mode 100644 index 90d2846..0000000 --- a/tests/Feature/SoftDeletes/SoftDeletesTest.php +++ /dev/null @@ -1,45 +0,0 @@ -entity = new SoftDeletesEntity(); - } - - public function testCanSetDeletedAt(): void - { - $date = new DateTime('now'); - - $this->entity->setDeletedAt($date); - - $this->assertEquals($date, $this->entity->getDeletedAt()); - } - - public function testCanCheckIfDeleted(): void - { - $this->assertFalse($this->entity->isDeleted()); - - $this->entity->setDeletedAt(new DateTime('now')); - $this->assertTrue($this->entity->isDeleted()); - } - - public function testCanRestore(): void - { - $this->entity->setDeletedAt(new DateTime('now')); - $this->assertTrue($this->entity->isDeleted()); - - $this->entity->restore(); - $this->assertFalse($this->entity->isDeleted()); - } -} diff --git a/tests/Feature/Sortable/SortableExtensionTest.php b/tests/Feature/Sortable/SortableExtensionTest.php deleted file mode 100644 index b45ae6a..0000000 --- a/tests/Feature/Sortable/SortableExtensionTest.php +++ /dev/null @@ -1,23 +0,0 @@ -addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertEmpty($extension->getFilters()); - } -} diff --git a/tests/Feature/TestCase.php b/tests/Feature/TestCase.php index 7d47386..f7da531 100644 --- a/tests/Feature/TestCase.php +++ b/tests/Feature/TestCase.php @@ -5,13 +5,18 @@ namespace LaravelDoctrineTest\Extensions\Feature; use Doctrine\Common\EventManager; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Tools\SchemaTool; +use Illuminate\Config\Repository; +use Illuminate\Foundation\Application; use Mockery as m; use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase as OrchestraTestCase; use function restore_error_handler; use function restore_exception_handler; +use function tap; abstract class TestCase extends OrchestraTestCase { @@ -20,14 +25,42 @@ abstract class TestCase extends OrchestraTestCase protected EventManager $evm; protected EntityManagerInterface $em; - public function setUp(): void + /** + * @param Application $app + * + * phpcs:disable + */ + protected function defineEnvironment($app): void { - $this->evm = m::mock(EventManager::class); - $this->em = m::mock(EntityManagerInterface::class); + // Setup default database to use sqlite :memory: + tap($app['config'], static function (Repository $config): void { + $config->set('doctrine.managers.default', [ + 'meta' => 'attributes', + 'connection' => 'testbench', + 'paths' => [__DIR__ . '/../Entity'], + 'proxies' => [ + 'auto_generate' => true, + 'path' => __DIR__ . '/../proxy', + 'namespace' => 'Proxy', + ], + ]); - $this->evm->shouldReceive('addEventSubscriber'); + $config->set('database.connections.testbench', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + }); + } + public function setUp(): void + { parent::setUp(); + + $this->em = $this->app->get(EntityManager::class); + $this->evm = $this->em->getEventManager(); + + (new SchemaTool($this->em))->createSchema($this->em->getMetadataFactory()->getAllMetadata()); } public function tearDown(): void @@ -35,6 +68,8 @@ public function tearDown(): void restore_error_handler(); restore_exception_handler(); + unset($this->em, $this->evm); + m::close(); parent::tearDown(); diff --git a/tests/Feature/Timestamps/TimestampableExtensionTest.php b/tests/Feature/Timestamps/TimestampableExtensionTest.php deleted file mode 100644 index f42e2f4..0000000 --- a/tests/Feature/Timestamps/TimestampableExtensionTest.php +++ /dev/null @@ -1,23 +0,0 @@ -addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertEmpty($extension->getFilters()); - } -} diff --git a/tests/Feature/Timestamps/TimestampsTest.php b/tests/Feature/Timestamps/TimestampsTest.php deleted file mode 100644 index a7505a3..0000000 --- a/tests/Feature/Timestamps/TimestampsTest.php +++ /dev/null @@ -1,37 +0,0 @@ -entity = new TimestampsEntity(); - } - - public function testCanSetCreatedAt(): void - { - $date = new DateTime('now'); - - $this->entity->setCreatedAt($date); - - $this->assertEquals($date, $this->entity->getCreatedAt()); - } - - public function testCanSetUpdatedAt(): void - { - $date = new DateTime('now'); - - $this->entity->setUpdatedAt($date); - - $this->assertEquals($date, $this->entity->getUpdatedAt()); - } -} diff --git a/tests/Feature/Tree/NestedSetTest.php b/tests/Feature/Tree/NestedSetTest.php deleted file mode 100644 index d51dad2..0000000 --- a/tests/Feature/Tree/NestedSetTest.php +++ /dev/null @@ -1,46 +0,0 @@ -entity = new NestedSetEntity(); - } - - public function testCanSetRoot(): void - { - $this->entity->setRoot(10); - - $this->assertEquals(10, $this->entity->getRoot()); - } - - public function testCanSetLevel(): void - { - $this->entity->setLevel(5); - - $this->assertEquals(5, $this->entity->getLevel()); - } - - public function testCanSetLeft(): void - { - $this->entity->setLeft(3); - - $this->assertEquals(3, $this->entity->getLeft()); - } - - public function testCanSetRight(): void - { - $this->entity->setRight(2); - - $this->assertEquals(2, $this->entity->getRight()); - } -} diff --git a/tests/Feature/Tree/TreeExtensionTest.php b/tests/Feature/Tree/TreeExtensionTest.php deleted file mode 100644 index ba6f522..0000000 --- a/tests/Feature/Tree/TreeExtensionTest.php +++ /dev/null @@ -1,23 +0,0 @@ -addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertEmpty($extension->getFilters()); - } -}