From dd4e77f30a00c4107f2a916ae5ef94cc8e2bd84b Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 30 Oct 2024 16:40:16 -0600 Subject: [PATCH 1/5] Gedmo tests for blameable, iptraceable, timestampable --- .../Assets/IpTraceable/IpTraceableEntity.php | 12 -- tests/Assets/Timestamps/TimestampsEntity.php | 12 -- tests/Assets/User.php | 51 ++++++ tests/Entity/Artist.php | 29 ++++ tests/Entity/Blameable.php | 23 +++ tests/Entity/IpTraceable.php | 23 +++ tests/Entity/Performance.php | 33 ++++ tests/Entity/Recording.php | 24 +++ tests/Entity/Timestamps.php | 23 +++ tests/Entity/User.php | 32 ++++ tests/Extensions.skipper | 157 ++++++++++++++++++ .../Blameable/BlameableExtensionTest.php | 27 --- .../Feature/Gedmo/BlameableExtensionTest.php | 43 +++++ .../IpTraceableExtensionTest.php | 16 +- .../TimestampableExtensionTest.php | 13 +- tests/Feature/IpTraceable/IpTraceableTest.php | 32 ---- tests/Feature/TestCase.php | 39 ++++- tests/Feature/Timestamps/TimestampsTest.php | 37 ----- 18 files changed, 496 insertions(+), 130 deletions(-) delete mode 100644 tests/Assets/IpTraceable/IpTraceableEntity.php delete mode 100644 tests/Assets/Timestamps/TimestampsEntity.php create mode 100644 tests/Assets/User.php create mode 100644 tests/Entity/Artist.php create mode 100644 tests/Entity/Blameable.php create mode 100644 tests/Entity/IpTraceable.php create mode 100644 tests/Entity/Performance.php create mode 100644 tests/Entity/Recording.php create mode 100644 tests/Entity/Timestamps.php create mode 100644 tests/Entity/User.php create mode 100644 tests/Extensions.skipper delete mode 100644 tests/Feature/Blameable/BlameableExtensionTest.php create mode 100644 tests/Feature/Gedmo/BlameableExtensionTest.php rename tests/Feature/{IpTraceable => Gedmo}/IpTraceableExtensionTest.php (52%) rename tests/Feature/{Timestamps => Gedmo}/TimestampableExtensionTest.php (50%) delete mode 100644 tests/Feature/IpTraceable/IpTraceableTest.php delete mode 100644 tests/Feature/Timestamps/TimestampsTest.php 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 @@ -id; + } + + public function getUserIdentifier() + { + return $this->id; + } + + public function getAuthPassword() + { + return 'password'; + } + + public function getRememberToken() + { + return 'token'; + } + + public function setRememberToken($value) + { + return; + } + + public function getRememberTokenName() + { + return 'token'; + } + + public function getAuthPasswordName() + { + // TODO: Implement getAuthPasswordName() method. + } +} diff --git a/tests/Entity/Artist.php b/tests/Entity/Artist.php new file mode 100644 index 0000000..69da4da --- /dev/null +++ b/tests/Entity/Artist.php @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + createdAt + create + createdAt + + + updatedAt + updatedAt + update + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + createdAt + createdAt + create + + + updatedAt + updatedAt + update + + + + + + + + + + + + + + + + createdFromIp + createdFromIp + create + + + updatedFromIp + updatedFromIp + update + + + + + + + + + + + + + + + + updatedBy + updatedBy + update + + + createdBy + createdBy + create + + + + + + + + + default + entity-name-only + + + + + + + + + + + + + + + + + + + diff --git a/tests/Feature/Blameable/BlameableExtensionTest.php b/tests/Feature/Blameable/BlameableExtensionTest.php deleted file mode 100644 index b56d8b8..0000000 --- a/tests/Feature/Blameable/BlameableExtensionTest.php +++ /dev/null @@ -1,27 +0,0 @@ -addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertEmpty($extension->getFilters()); - } -} diff --git a/tests/Feature/Gedmo/BlameableExtensionTest.php b/tests/Feature/Gedmo/BlameableExtensionTest.php new file mode 100644 index 0000000..49ad27a --- /dev/null +++ b/tests/Feature/Gedmo/BlameableExtensionTest.php @@ -0,0 +1,43 @@ +setUser($user); + + $extension = new BlameableExtension(); + + $extension->addSubscribers( + $this->evm, + $this->em, + ); + + $this->assertEmpty($extension->getFilters()); + + $blamable = new Blameable(); + + $this->em->persist($blamable); + $this->em->flush(); + + $this->assertNotNull($blamable->createdBy); + $this->assertNotNull($blamable->updatedBy); + + $this->assertEquals($user->getUserIdentifier(), $blamable->createdBy); + $this->assertEquals($user->getUserIdentifier(), $blamable->updatedBy); + } +} diff --git a/tests/Feature/IpTraceable/IpTraceableExtensionTest.php b/tests/Feature/Gedmo/IpTraceableExtensionTest.php similarity index 52% rename from tests/Feature/IpTraceable/IpTraceableExtensionTest.php rename to tests/Feature/Gedmo/IpTraceableExtensionTest.php index ccdfd0a..473e000 100644 --- a/tests/Feature/IpTraceable/IpTraceableExtensionTest.php +++ b/tests/Feature/Gedmo/IpTraceableExtensionTest.php @@ -2,16 +2,17 @@ declare(strict_types=1); -namespace LaravelDoctrineTest\Extensions\Feature\IpTraceable; +namespace LaravelDoctrineTest\Extensions\Feature\Gedmo; use Illuminate\Http\Request; use LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension; +use LaravelDoctrineTest\Extensions\Entity\IpTraceable; use LaravelDoctrineTest\Extensions\Feature\TestCase; use Mockery as m; class IpTraceableExtensionTest extends TestCase { - public function testCanRegisterExtension(): void + public function testExtensionWorks(): void { $request = m::mock(Request::class); @@ -27,6 +28,15 @@ public function testCanRegisterExtension(): void $this->em, ); - $this->assertEmpty($extension->getFilters()); + $ipTracable = new IpTraceable(); + + $this->em->persist($ipTracable); + $this->em->flush(); + + $this->assertNotNull($ipTracable->createdFromIp); + $this->assertNotNull($ipTracable->updatedFromIp); + + $this->assertEquals('127.0.0.1', $ipTracable->createdFromIp); + $this->assertEquals('127.0.0.1', $ipTracable->updatedFromIp); } } diff --git a/tests/Feature/Timestamps/TimestampableExtensionTest.php b/tests/Feature/Gedmo/TimestampableExtensionTest.php similarity index 50% rename from tests/Feature/Timestamps/TimestampableExtensionTest.php rename to tests/Feature/Gedmo/TimestampableExtensionTest.php index f42e2f4..ebcf8fb 100644 --- a/tests/Feature/Timestamps/TimestampableExtensionTest.php +++ b/tests/Feature/Gedmo/TimestampableExtensionTest.php @@ -2,14 +2,15 @@ declare(strict_types=1); -namespace LaravelDoctrineTest\Extensions\Feature\Timestamps; +namespace LaravelDoctrineTest\Extensions\Feature\Gedmo; use LaravelDoctrine\Extensions\Timestamps\TimestampableExtension; +use LaravelDoctrineTest\Extensions\Entity\Timestamps; use LaravelDoctrineTest\Extensions\Feature\TestCase; class TimestampableExtensionTest extends TestCase { - public function testCanRegisterExtension(): void + public function testExtensionWorks(): void { $extension = new TimestampableExtension(); @@ -18,6 +19,12 @@ public function testCanRegisterExtension(): void $this->em, ); - $this->assertEmpty($extension->getFilters()); + $entity = new Timestamps(); + + $this->em->persist($entity); + $this->em->flush(); + + $this->assertNotNull($entity->createdAt); + $this->assertNotNull($entity->updatedAt); } } 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/TestCase.php b/tests/Feature/TestCase.php index 7d47386..22d9dc8 100644 --- a/tests/Feature/TestCase.php +++ b/tests/Feature/TestCase.php @@ -5,7 +5,11 @@ 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 LaravelDoctrineTest\Extensions\Entity\Artist; use Mockery as m; use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase as OrchestraTestCase; @@ -20,14 +24,39 @@ abstract class TestCase extends OrchestraTestCase protected EventManager $evm; protected EntityManagerInterface $em; - public function setUp(): void + protected function defineEnvironment($app) { - $this->evm = m::mock(EventManager::class); - $this->em = m::mock(EntityManagerInterface::class); + // Setup default database to use sqlite :memory: + tap($app['config'], function (Repository $config) { + $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 +64,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/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()); - } -} From ee09c3f1b42ddbfe3216a5b7c59172c70f1d14bf Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 30 Oct 2024 17:48:34 -0600 Subject: [PATCH 2/5] Change function name --- tests/Feature/Gedmo/BlameableExtensionTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/Feature/Gedmo/BlameableExtensionTest.php b/tests/Feature/Gedmo/BlameableExtensionTest.php index 49ad27a..a3fb29c 100644 --- a/tests/Feature/Gedmo/BlameableExtensionTest.php +++ b/tests/Feature/Gedmo/BlameableExtensionTest.php @@ -4,17 +4,14 @@ namespace LaravelDoctrineTest\Extensions\Feature\Gedmo; -use Illuminate\Contracts\Auth\Authenticatable; -use Illuminate\Contracts\Auth\Guard; use LaravelDoctrine\Extensions\Blameable\BlameableExtension; use LaravelDoctrineTest\Extensions\Assets\User; use LaravelDoctrineTest\Extensions\Entity\Blameable; use LaravelDoctrineTest\Extensions\Feature\TestCase; -use Mockery as m; class BlameableExtensionTest extends TestCase { - public function testCanRegisterExtension(): void + public function testExtensionWorks(): void { $user = new User(); From 3742708d20ca119e1ca12195d18869fe7e4d74f2 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 30 Oct 2024 18:55:07 -0600 Subject: [PATCH 3/5] Removed examples of Gedmo extensions working. This repo just needs to ensure they can be loaded. --- src/IpTraceable/IpTraceable.php | 69 ---------- src/SoftDeletes/SoftDeletes.php | 37 ------ src/Timestamps/Timestamps.php | 50 ------- src/Tree/NestedSet.php | 87 ------------- testbench.yaml | 1 + tests/Entity/Artist.php | 29 ----- tests/Entity/Performance.php | 33 ----- tests/Entity/Recording.php | 24 ---- tests/Entity/User.php | 32 ----- .../Feature/Gedmo/BlameableExtensionTest.php | 40 ------ .../Gedmo/IpTraceableExtensionTest.php | 42 ------ tests/Feature/Gedmo/SubscribeAllTest.php | 122 ++++++++++++++++++ .../Gedmo/TimestampableExtensionTest.php | 30 ----- .../TranslatableExtensionTest.php | 2 +- ...UploadableExtensionServiceProviderTest.php | 2 +- .../Uploadable/UploadableExtensionTest.php | 4 +- ...tensionsServiceProviderAllMappingsTest.php | 2 + .../Loggable/LoggableExtensionTest.php | 29 ----- .../Sluggable/SluggableExtensionTest.php | 23 ---- .../SoftDeleteableExtensionTest.php | 24 ---- tests/Feature/SoftDeletes/SoftDeletesTest.php | 45 ------- .../Sortable/SortableExtensionTest.php | 23 ---- tests/Feature/Tree/NestedSetTest.php | 46 ------- tests/Feature/Tree/TreeExtensionTest.php | 23 ---- 24 files changed, 129 insertions(+), 690 deletions(-) delete mode 100644 src/IpTraceable/IpTraceable.php delete mode 100644 src/SoftDeletes/SoftDeletes.php delete mode 100644 src/Timestamps/Timestamps.php delete mode 100644 src/Tree/NestedSet.php delete mode 100644 tests/Entity/Artist.php delete mode 100644 tests/Entity/Performance.php delete mode 100644 tests/Entity/Recording.php delete mode 100644 tests/Entity/User.php delete mode 100644 tests/Feature/Gedmo/BlameableExtensionTest.php delete mode 100644 tests/Feature/Gedmo/IpTraceableExtensionTest.php create mode 100644 tests/Feature/Gedmo/SubscribeAllTest.php delete mode 100644 tests/Feature/Gedmo/TimestampableExtensionTest.php rename tests/Feature/{ => Gedmo}/Translatable/TranslatableExtensionTest.php (88%) rename tests/Feature/{ => Gedmo}/Uploadable/UploadableExtensionServiceProviderTest.php (93%) rename tests/Feature/{ => Gedmo}/Uploadable/UploadableExtensionTest.php (87%) delete mode 100644 tests/Feature/Loggable/LoggableExtensionTest.php delete mode 100644 tests/Feature/Sluggable/SluggableExtensionTest.php delete mode 100644 tests/Feature/SoftDeletes/SoftDeleteableExtensionTest.php delete mode 100644 tests/Feature/SoftDeletes/SoftDeletesTest.php delete mode 100644 tests/Feature/Sortable/SortableExtensionTest.php delete mode 100644 tests/Feature/Tree/NestedSetTest.php delete mode 100644 tests/Feature/Tree/TreeExtensionTest.php 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/Entity/Artist.php b/tests/Entity/Artist.php deleted file mode 100644 index 69da4da..0000000 --- a/tests/Entity/Artist.php +++ /dev/null @@ -1,29 +0,0 @@ -setUser($user); - - $extension = new BlameableExtension(); - - $extension->addSubscribers( - $this->evm, - $this->em, - ); - - $this->assertEmpty($extension->getFilters()); - - $blamable = new Blameable(); - - $this->em->persist($blamable); - $this->em->flush(); - - $this->assertNotNull($blamable->createdBy); - $this->assertNotNull($blamable->updatedBy); - - $this->assertEquals($user->getUserIdentifier(), $blamable->createdBy); - $this->assertEquals($user->getUserIdentifier(), $blamable->updatedBy); - } -} diff --git a/tests/Feature/Gedmo/IpTraceableExtensionTest.php b/tests/Feature/Gedmo/IpTraceableExtensionTest.php deleted file mode 100644 index 473e000..0000000 --- a/tests/Feature/Gedmo/IpTraceableExtensionTest.php +++ /dev/null @@ -1,42 +0,0 @@ -shouldReceive('getClientIp') - ->once()->andReturn('127.0.0.1'); - - $extension = new IpTraceableExtension( - $request, - ); - - $extension->addSubscribers( - $this->evm, - $this->em, - ); - - $ipTracable = new IpTraceable(); - - $this->em->persist($ipTracable); - $this->em->flush(); - - $this->assertNotNull($ipTracable->createdFromIp); - $this->assertNotNull($ipTracable->updatedFromIp); - - $this->assertEquals('127.0.0.1', $ipTracable->createdFromIp); - $this->assertEquals('127.0.0.1', $ipTracable->updatedFromIp); - } -} diff --git a/tests/Feature/Gedmo/SubscribeAllTest.php b/tests/Feature/Gedmo/SubscribeAllTest.php new file mode 100644 index 0000000..073dfe7 --- /dev/null +++ b/tests/Feature/Gedmo/SubscribeAllTest.php @@ -0,0 +1,122 @@ +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/Gedmo/TimestampableExtensionTest.php b/tests/Feature/Gedmo/TimestampableExtensionTest.php deleted file mode 100644 index ebcf8fb..0000000 --- a/tests/Feature/Gedmo/TimestampableExtensionTest.php +++ /dev/null @@ -1,30 +0,0 @@ -addSubscribers( - $this->evm, - $this->em, - ); - - $entity = new Timestamps(); - - $this->em->persist($entity); - $this->em->flush(); - - $this->assertNotNull($entity->createdAt); - $this->assertNotNull($entity->updatedAt); - } -} 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 87% rename from tests/Feature/Uploadable/UploadableExtensionTest.php rename to tests/Feature/Gedmo/Uploadable/UploadableExtensionTest.php index 40ca936..7de3099 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; @@ -19,7 +19,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/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/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()); - } -} From edc455b4cece9bc1b7a1cf722ac53e8f66e6796a Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 30 Oct 2024 18:56:48 -0600 Subject: [PATCH 4/5] Remove unused test assets --- tests/Assets/User.php | 51 ------------- tests/Extensions.skipper | 157 --------------------------------------- 2 files changed, 208 deletions(-) delete mode 100644 tests/Assets/User.php delete mode 100644 tests/Extensions.skipper diff --git a/tests/Assets/User.php b/tests/Assets/User.php deleted file mode 100644 index 7e61b15..0000000 --- a/tests/Assets/User.php +++ /dev/null @@ -1,51 +0,0 @@ -id; - } - - public function getUserIdentifier() - { - return $this->id; - } - - public function getAuthPassword() - { - return 'password'; - } - - public function getRememberToken() - { - return 'token'; - } - - public function setRememberToken($value) - { - return; - } - - public function getRememberTokenName() - { - return 'token'; - } - - public function getAuthPasswordName() - { - // TODO: Implement getAuthPasswordName() method. - } -} diff --git a/tests/Extensions.skipper b/tests/Extensions.skipper deleted file mode 100644 index fca5b88..0000000 --- a/tests/Extensions.skipper +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - - - - - - - - - createdAt - create - createdAt - - - updatedAt - updatedAt - update - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - createdAt - createdAt - create - - - updatedAt - updatedAt - update - - - - - - - - - - - - - - - - createdFromIp - createdFromIp - create - - - updatedFromIp - updatedFromIp - update - - - - - - - - - - - - - - - - updatedBy - updatedBy - update - - - createdBy - createdBy - create - - - - - - - - - default - entity-name-only - - - - - - - - - - - - - - - - - - - From 35ef2bb6465120102d2c69a4d84774493d8aa500 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 30 Oct 2024 19:07:06 -0600 Subject: [PATCH 5/5] phpcs --- tests/Entity/.gitkeep | 0 tests/Entity/Blameable.php | 23 ------------------ tests/Entity/IpTraceable.php | 23 ------------------ tests/Entity/Timestamps.php | 23 ------------------ tests/Feature/Gedmo/SubscribeAllTest.php | 2 ++ .../Uploadable/UploadableExtensionTest.php | 2 ++ tests/Feature/TestCase.php | 24 +++++++++++-------- 7 files changed, 18 insertions(+), 79 deletions(-) create mode 100644 tests/Entity/.gitkeep delete mode 100644 tests/Entity/Blameable.php delete mode 100644 tests/Entity/IpTraceable.php delete mode 100644 tests/Entity/Timestamps.php diff --git a/tests/Entity/.gitkeep b/tests/Entity/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Entity/Blameable.php b/tests/Entity/Blameable.php deleted file mode 100644 index 9a2a86d..0000000 --- a/tests/Entity/Blameable.php +++ /dev/null @@ -1,23 +0,0 @@ -set('doctrine.managers.default', [ 'meta' => 'attributes', 'connection' => 'testbench', - 'paths' => [ - __DIR__ . '/../Entity' - ], + 'paths' => [__DIR__ . '/../Entity'], 'proxies' => [ 'auto_generate' => true, 'path' => __DIR__ . '/../proxy', 'namespace' => 'Proxy', - ] + ], ]); $config->set('database.connections.testbench', [ - 'driver' => 'sqlite', + 'driver' => 'sqlite', 'database' => ':memory:', - 'prefix' => '', + 'prefix' => '', ]); }); } @@ -53,7 +57,7 @@ public function setUp(): void { parent::setUp(); - $this->em = $this->app->get(EntityManager::class); + $this->em = $this->app->get(EntityManager::class); $this->evm = $this->em->getEventManager(); (new SchemaTool($this->em))->createSchema($this->em->getMetadataFactory()->getAllMetadata());